// Path: sonar-flow-plugin/src/main/java/be/i8c/codequality/sonar/plugins/sag/webmethods/flow/ws/sources/xslt/LocationFilter.java
// public class LocationFilter extends XMLFilterImpl {
// 
//   public LocationFilter(XMLReader xmlReader) {
//     super(xmlReader);
//   }
// 
//   private Locator locator = null;
// 
//   @Override
//   public void setDocumentLocator(Locator locator) {
//     super.setDocumentLocator(locator);
//     this.locator = locator;
//   }
// 
//   @Override
//   public void startElement(String uri, String localName,
//       String qualifiedName, Attributes attributes)
//       throws SAXException {
// 
//     // Add extra attribute to elements to hold location
//     String location = String.valueOf(locator.getLineNumber());
//     Attributes2Impl attrs = new Attributes2Impl(attributes);
//     attrs.addAttribute("", "location", "location", "String", location);
//     super.startElement(uri, localName, qualifiedName, attrs);
//   }
// 
// }


import be.i8c.codequality.sonar.plugins.sag.webmethods.flow.ws.sources.xslt.LocationFilter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService.Action;
import org.sonar.api.server.ws.WebService.Context;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

    response.stream().setMediaType("application/json");
    response.setHeader("Content-Type", "application/json");
  }

  private void convertRawToFlow(byte[] in, OutputStream out, String type, 
      boolean full, String flowname)
      throws Exception {
    XMLReader xmlReader = XMLReaderFactory.createXMLReader();
    LocationFilter locationFilter = new LocationFilter(xmlReader);
    Transformer transformer = type.equals("html") 
        ? htmlTransformer : (full ? jsonFullTransformer : jsonTransformer);
    transformer.setParameter("full", String.valueOf(full));
    transformer.setParameter("flowname", flowname);
    SAXSource saxSource = new SAXSource(
        locationFilter, new InputSource(new ByteArrayInputStream(in)));
    transformer.transform(saxSource, new StreamResult(out));

  }

  private static Transformer getTransFormer(String type, boolean full) {
    Transformer t;
    try {
      if (type.equals("html")) {
        t = factory.newTransformer(xslt_html);
      } else if (full) {
        t = factory.newTransformer(xslt_json_full);
      } else {
        t = factory.newTransformer(xslt_json);
      }
      return t;

// Path: sonar-flow-plugin/src/main/java/be/i8c/codequality/sonar/plugins/sag/webmethods/flow/ws/sources/xslt/LocationFilter.java
// public class LocationFilter extends XMLFilterImpl {
// 
//   public LocationFilter(XMLReader xmlReader) {
//     super(xmlReader);
//   }
// 
//   private Locator locator = null;
// 
//   @Override
//   public void setDocumentLocator(Locator locator) {
//     super.setDocumentLocator(locator);
//     this.locator = locator;
//   }
// 
//   @Override
//   public void startElement(String uri, String localName,
//       String qualifiedName, Attributes attributes)
//       throws SAXException {
// 
//     // Add extra attribute to elements to hold location
//     String location = String.valueOf(locator.getLineNumber());
//     Attributes2Impl attrs = new Attributes2Impl(attributes);
//     attrs.addAttribute("", "location", "location", "String", location);
//     super.startElement(uri, localName, qualifiedName, attrs);
//   }
// 
// }


// Path: sonar-flow-plugin/src/main/java/be/i8c/codequality/sonar/plugins/sag/webmethods/flow/ws/sources/FlowActionHandler.java
import be.i8c.codequality.sonar.plugins.sag.webmethods.flow.ws.sources.xslt.LocationFilter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService.Action;
import org.sonar.api.server.ws.WebService.Context;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

    response.stream().setMediaType("application/json");
    response.setHeader("Content-Type", "application/json");
  }

  private void convertRawToFlow(byte[] in, OutputStream out, String type, 
      boolean full, String flowname)
      throws Exception {
    XMLReader xmlReader = XMLReaderFactory.createXMLReader();
    LocationFilter locationFilter = new LocationFilter(xmlReader);
    Transformer transformer = type.equals("html") 
        ? htmlTransformer : (full ? jsonFullTransformer : jsonTransformer);
    transformer.setParameter("full", String.valueOf(full));
    transformer.setParameter("flowname", flowname);
    SAXSource saxSource = new SAXSource(
        locationFilter, new InputSource(new ByteArrayInputStream(in)));
    transformer.transform(saxSource, new StreamResult(out));

  }

  private static Transformer getTransFormer(String type, boolean full) {
    Transformer t;
    try {
      if (type.equals("html")) {
        t = factory.newTransformer(xslt_html);
      } else if (full) {
        t = factory.newTransformer(xslt_json_full);
      } else {
        t = factory.newTransformer(xslt_json);
      }
      return t;

    } catch (TransformerConfigurationException e) {
