org.apache.xml.serializer.SerializerFactory Java Examples

The following examples show how to use org.apache.xml.serializer.SerializerFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlDataSetConsumer.java    From morf with Apache License 2.0 5 votes vote down vote up
/**
 * @param outputStream The output
 * @return A content handler
 * @throws IOException When there's an XML error
 */
private ContentHandler createContentHandler(OutputStream outputStream) throws IOException {
  Properties outputProperties = OutputPropertiesFactory.getDefaultMethodProperties(Method.XML);
  outputProperties.setProperty("indent", "yes");
  outputProperties.setProperty(OutputPropertiesFactory.S_KEY_INDENT_AMOUNT, "2");
  outputProperties.setProperty(OutputPropertiesFactory.S_KEY_LINE_SEPARATOR, "\n");
  Serializer serializer = SerializerFactory.getSerializer(outputProperties);
  serializer.setOutputStream(outputStream);
  return serializer.asContentHandler();
}
 
Example #2
Source File: LSSerializerImpl.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor:  Creates a LSSerializerImpl object.  The underlying
 * XML 1.0 or XML 1.1 org.apache.xml.serializer.Serializer object is
 * created and initialized the first time any of the write methods are  
 * invoked to serialize the Node.  Subsequent write methods on the same
 * LSSerializerImpl object will use the previously created Serializer object.
 */
public LSSerializerImpl () {
    // set default parameters
    fFeatures |= CDATA;
    fFeatures |= COMMENTS;
    fFeatures |= ELEM_CONTENT_WHITESPACE;
    fFeatures |= ENTITIES;
    fFeatures |= NAMESPACES;
    fFeatures |= NAMESPACEDECLS;
    fFeatures |= SPLITCDATA;
    fFeatures |= WELLFORMED;
    fFeatures |= DISCARDDEFAULT;
    fFeatures |= XMLDECL;
    
    // New OutputFormat properties
    fDOMConfigProperties = new Properties();
    
    // Initialize properties to be passed on the underlying serializer
    initializeSerializerProps();
    
    // Create the underlying serializer.
    Properties  configProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
    
    // change xml version from 1.0 to 1.1
    //configProps.setProperty("version", "1.1");
    
    // Get a serializer that seriailizes according the the properties,
    // which in this case is to xml
    fXMLSerializer = SerializerFactory.getSerializer(configProps);
    
    // Initialize Serializer
    fXMLSerializer.setOutputFormat(fDOMConfigProperties);
}
 
Example #3
Source File: PipeTest.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Test
public void testPipe()
throws TransformerException, TransformerConfigurationException, 
        SAXException, IOException	   
{
   // Instantiate  a TransformerFactory.
 	TransformerFactory tFactory = TransformerFactory.newInstance();
   // Determine whether the TransformerFactory supports The use uf SAXSource 
   // and SAXResult
   if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE))
   { 
     // Cast the TransformerFactory to SAXTransformerFactory.
     SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);	  
     // Create a TransformerHandler for each stylesheet.
     TransformerHandler tHandler1 = saxTFactory.newTransformerHandler(new StreamSource(PipeTest.class.getResourceAsStream("foo1.xsl")));
     TransformerHandler tHandler2 = saxTFactory.newTransformerHandler(new StreamSource(PipeTest.class.getResourceAsStream("foo2.xsl")));
     TransformerHandler tHandler3 = saxTFactory.newTransformerHandler(new StreamSource(PipeTest.class.getResourceAsStream("foo3.xsl")));
   
     // Create an XMLReader.
    XMLReader reader = XMLReaderFactory.createXMLReader();
     reader.setContentHandler(tHandler1);
     reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHandler1);

     tHandler1.setResult(new SAXResult(tHandler2));
     tHandler2.setResult(new SAXResult(tHandler3));

     // transformer3 outputs SAX events to the serializer.
     java.util.Properties xmlProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
     xmlProps.setProperty("indent", "yes");
     xmlProps.setProperty("standalone", "no");
     Serializer serializer = SerializerFactory.getSerializer(xmlProps);
     serializer.setOutputStream(System.out);
     tHandler3.setResult(new SAXResult(serializer.asContentHandler()));

    // Parse the XML input document. The input ContentHandler and output ContentHandler
     // work in separate threads to optimize performance.   
     reader.parse(new InputSource(PipeTest.class.getResourceAsStream("foo.xml")));
   }
 }
 
Example #4
Source File: XSLTProcessor.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Resets the serializer, if resetting is possible. If not, re-creates the
 * serializer.
 */
void resetSerializer() {
	if(!serializer.reset()) {
    	serializer // create new unless re-useable
    		= SerializerFactory.getSerializer(xmlProperties);
    }
}
 
Example #5
Source File: SqlXmlHelperXalan.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Create an instance of Xalan serializer for the sake of serializing an XML
 * value according the SQL/XML specification for serialization.
 */
private void loadSerializer() throws java.io.IOException {
  // Set serialization properties.

  Properties props = OutputPropertiesFactory
      .getDefaultMethodProperties("xml");
  /* (original code)
  Properties props = OutputProperties.getDefaultMethodProperties("xml");
  */

  // SQL/XML[2006] 10.15:General Rules:6 says method is "xml".
  props.setProperty(OutputKeys.METHOD, "xml");

  /* Since the XMLSERIALIZE operator doesn't currently support
   * the DOCUMENT nor CONTENT keywords, SQL/XML spec says that
   * the default is CONTENT (6.7:Syntax Rules:2.a).  Further,
   * since the XMLSERIALIZE operator doesn't currently support the
   * <XML declaration option> syntax, the SQL/XML spec says
   * that the default for that option is "Unknown" (6.7:General
   * Rules:2.f).  Put those together and that in turn means that
   * the value of "OMIT XML DECLARATION" must be "Yes", as
   * stated in section 10.15:General Rules:8.c.  SO, that's what
   * we set here.
   *
   * NOTE: currently the only way to view the contents of an
   * XML column is by using an explicit XMLSERIALIZE operator.
   * This means that if an XML document is stored and it
   * begins with an XML declaration, the user will never be
   * able to _see_ that declaration after inserting the doc
   * because, as explained above, our current support for
   * XMLSERIALIZE dictates that the declaration must be
   * omitted.  Similarly, other transformations that may
   * occur from serialization (ex. entity replacement,
   * attribute order, single-to-double quotes, etc)) will
   * always be in effect for the string returned to the user;
   * the original form of the XML document, if different
   * from the serialized version, is not currently retrievable.
   */
  props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

  // We serialize everything as UTF-8 to match what we
  // store on disk.
  props.setProperty(OutputKeys.ENCODING, "UTF-8");

  // Load the serializer with the correct properties.
  serializer = SerializerFactory.getSerializer(props);
}
 
Example #6
Source File: SqlXmlHelperXalan.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Create an instance of Xalan serializer for the sake of serializing an XML
 * value according the SQL/XML specification for serialization.
 */
private void loadSerializer() throws java.io.IOException {
  // Set serialization properties.

  Properties props = OutputPropertiesFactory
      .getDefaultMethodProperties("xml");
  /* (original code)
  Properties props = OutputProperties.getDefaultMethodProperties("xml");
  */

  // SQL/XML[2006] 10.15:General Rules:6 says method is "xml".
  props.setProperty(OutputKeys.METHOD, "xml");

  /* Since the XMLSERIALIZE operator doesn't currently support
   * the DOCUMENT nor CONTENT keywords, SQL/XML spec says that
   * the default is CONTENT (6.7:Syntax Rules:2.a).  Further,
   * since the XMLSERIALIZE operator doesn't currently support the
   * <XML declaration option> syntax, the SQL/XML spec says
   * that the default for that option is "Unknown" (6.7:General
   * Rules:2.f).  Put those together and that in turn means that
   * the value of "OMIT XML DECLARATION" must be "Yes", as
   * stated in section 10.15:General Rules:8.c.  SO, that's what
   * we set here.
   *
   * NOTE: currently the only way to view the contents of an
   * XML column is by using an explicit XMLSERIALIZE operator.
   * This means that if an XML document is stored and it
   * begins with an XML declaration, the user will never be
   * able to _see_ that declaration after inserting the doc
   * because, as explained above, our current support for
   * XMLSERIALIZE dictates that the declaration must be
   * omitted.  Similarly, other transformations that may
   * occur from serialization (ex. entity replacement,
   * attribute order, single-to-double quotes, etc)) will
   * always be in effect for the string returned to the user;
   * the original form of the XML document, if different
   * from the serialized version, is not currently retrievable.
   */
  props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

  // We serialize everything as UTF-8 to match what we
  // store on disk.
  props.setProperty(OutputKeys.ENCODING, "UTF-8");

  // Load the serializer with the correct properties.
  serializer = SerializerFactory.getSerializer(props);
}
 
Example #7
Source File: XSLTEntityHandler.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public ContentHandler getOutputHandler(OutputStream out) throws IOException
{
	if (!isAvailable()) return null;

	try
	{
		XSLTTransform xsltTransform = (XSLTTransform) transformerHolder.get();
		if (xsltTransform == null)
		{
			xsltTransform = new XSLTTransform();
			xsltTransform.setXslt(new InputSource(this.getClass()
					.getResourceAsStream(xslt)));
			transformerHolder.set(xsltTransform);
		}
		SAXResult sr = new SAXResult();
		
		TransformerHandler th = xsltTransform.getContentHandler();
		
		Transformer transformer = th.getTransformer();
		if (transformParameters != null) {
			for (Map.Entry<String, String> entry: transformParameters.entrySet()) {
				transformer.setParameter(entry.getKey(), entry.getValue());
			}
		}

		Properties p = OutputPropertiesFactory.getDefaultMethodProperties("xml");
		p.putAll(outputProperties);
		
		/*
		S_KEY_CONTENT_HANDLER:{http://xml.apache.org/xalan}content-handler
			S_KEY_ENTITIES:{http://xml.apache.org/xalan}entities
			S_KEY_INDENT_AMOUNT:{http://xml.apache.org/xalan}indent-amount
			S_OMIT_META_TAG:{http://xml.apache.org/xalan}omit-meta-tag
			S_USE_URL_ESCAPING:{http://xml.apache.org/xalan}use-url-escaping
		*/
		
		Serializer s = SerializerFactory.getSerializer(p);
		s.setOutputStream(out);
		sr.setHandler(s.asContentHandler());
		th.setResult(sr);
		return th;
	}
	catch (Exception ex)
	{
		throw new RuntimeException("Failed to create Content Handler", ex); //$NON-NLS-1$
		/*
		 * String stackTrace = null; try { StringWriter exw = new
		 * StringWriter(); PrintWriter pw = new PrintWriter(exw);
		 * log.error(ex.getMessage(), ex); stackTrace = exw.toString(); } catch
		 * (Exception ex2) { stackTrace =
		 * MessageFormat.format(defaultStackTrace, new Object[] {
		 * ex.getMessage() }); } out.write(MessageFormat.format(errorFormat,
		 * new Object[] { ex.getMessage(), stackTrace }));
		 */
	}
}
 
Example #8
Source File: SerializerSwitcher.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
   * Switch to HTML serializer if element is HTML
   *
   *
   * @param transformer Non-null transformer instance
   * @param ns Namespace URI of the element
   * @param localName Local part of name of element
   *
   * @throws TransformerException
   */
  public static void switchSerializerIfHTML(
          TransformerImpl transformer, String ns, String localName)
            throws TransformerException
  {

    if (null == transformer)
      return;

    if (((null == ns) || (ns.length() == 0))
            && localName.equalsIgnoreCase("html"))
    {
      // System.out.println("transformer.getOutputPropertyNoDefault(OutputKeys.METHOD): "+
      //              transformer.getOutputPropertyNoDefault(OutputKeys.METHOD));     
      // Access at level of hashtable to see if the method has been set.
      if (null != transformer.getOutputPropertyNoDefault(OutputKeys.METHOD))
        return;

      // Getting the output properties this way won't cause a clone of 
      // the properties.
      Properties prevProperties = transformer.getOutputFormat().getProperties();
      
      // We have to make sure we get an output properties with the proper 
      // defaults for the HTML method.  The easiest way to do this is to 
      // have the OutputProperties class do it.
      OutputProperties htmlOutputProperties = new OutputProperties(Method.HTML);

      htmlOutputProperties.copyFrom(prevProperties, true);
      Properties htmlProperties = htmlOutputProperties.getProperties();

      try
      {
//        Serializer oldSerializer = transformer.getSerializer();
        Serializer oldSerializer = null;

        if (null != oldSerializer)
        {
          Serializer serializer =
            SerializerFactory.getSerializer(htmlProperties);

          Writer writer = oldSerializer.getWriter();

          if (null != writer)
            serializer.setWriter(writer);
          else
          {
            OutputStream os = oldSerializer.getOutputStream();

            if (null != os)
              serializer.setOutputStream(os);
          }

//          transformer.setSerializer(serializer);

          ContentHandler ch = serializer.asContentHandler();

          transformer.setContentHandler(ch);
        }
      }
      catch (java.io.IOException e)
      {
        throw new TransformerException(e);
      }
    }
  }
 
Example #9
Source File: SerializerSwitcher.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
   * Switch to HTML serializer if element is HTML
   *
   *
   * @param ns Namespace URI of the element
   * @param localName Local part of name of element
   *
   * @throws TransformerException
   * @return new contentHandler.
   */
  public static Serializer switchSerializerIfHTML(
          String ns, String localName, Properties props, Serializer oldSerializer)
            throws TransformerException
  {
    Serializer newSerializer = oldSerializer;

    if (((null == ns) || (ns.length() == 0))
            && localName.equalsIgnoreCase("html"))
    {
      // System.out.println("transformer.getOutputPropertyNoDefault(OutputKeys.METHOD): "+
      //              transformer.getOutputPropertyNoDefault(OutputKeys.METHOD));     
      // Access at level of hashtable to see if the method has been set.
      if (null != getOutputPropertyNoDefault(OutputKeys.METHOD, props))
        return newSerializer;

      // Getting the output properties this way won't cause a clone of 
      // the properties.
      Properties prevProperties = props;
      
      // We have to make sure we get an output properties with the proper 
      // defaults for the HTML method.  The easiest way to do this is to 
      // have the OutputProperties class do it.
      OutputProperties htmlOutputProperties = new OutputProperties(Method.HTML);

      htmlOutputProperties.copyFrom(prevProperties, true);
      Properties htmlProperties = htmlOutputProperties.getProperties();

//      try
      {
        if (null != oldSerializer)
        {
          Serializer serializer =
            SerializerFactory.getSerializer(htmlProperties);

          Writer writer = oldSerializer.getWriter();

          if (null != writer)
            serializer.setWriter(writer);
          else
          {
            OutputStream os = serializer.getOutputStream();

            if (null != os)
              serializer.setOutputStream(os);
          }
          newSerializer = serializer;
        }
      }
//      catch (java.io.IOException e)
//      {
//        throw new TransformerException(e);
//      }
    }
    return newSerializer;
  }
 
Example #10
Source File: XSLTEntityHandler.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public ContentHandler getOutputHandler(OutputStream out) throws IOException
{
	if (!isAvailable()) return null;

	try
	{
		XSLTTransform xsltTransform = (XSLTTransform) transformerHolder.get();
		if (xsltTransform == null)
		{
			xsltTransform = new XSLTTransform();
			xsltTransform.setXslt(new InputSource(this.getClass()
					.getResourceAsStream(xslt)));
			transformerHolder.set(xsltTransform);
		}
		SAXResult sr = new SAXResult();
		
		TransformerHandler th = xsltTransform.getContentHandler();
		
		Transformer transformer = th.getTransformer();
		if (transformParameters != null) {
			for (Map.Entry<String, String> entry: transformParameters.entrySet()) {
				transformer.setParameter(entry.getKey(), entry.getValue());
			}
		}

		Properties p = OutputPropertiesFactory.getDefaultMethodProperties("xml");
		p.putAll(outputProperties);
		
		/*
		S_KEY_CONTENT_HANDLER:{http://xml.apache.org/xalan}content-handler
			S_KEY_ENTITIES:{http://xml.apache.org/xalan}entities
			S_KEY_INDENT_AMOUNT:{http://xml.apache.org/xalan}indent-amount
			S_OMIT_META_TAG:{http://xml.apache.org/xalan}omit-meta-tag
			S_USE_URL_ESCAPING:{http://xml.apache.org/xalan}use-url-escaping
		*/
		
		Serializer s = SerializerFactory.getSerializer(p);
		s.setOutputStream(out);
		sr.setHandler(s.asContentHandler());
		th.setResult(sr);
		return th;
	}
	catch (Exception ex)
	{
		throw new RuntimeException("Failed to create Content Handler", ex); //$NON-NLS-1$
		/*
		 * String stackTrace = null; try { StringWriter exw = new
		 * StringWriter(); PrintWriter pw = new PrintWriter(exw);
		 * log.error(ex.getMessage(), ex); stackTrace = exw.toString(); } catch
		 * (Exception ex2) { stackTrace =
		 * MessageFormat.format(defaultStackTrace, new Object[] {
		 * ex.getMessage() }); } out.write(MessageFormat.format(errorFormat,
		 * new Object[] { ex.getMessage(), stackTrace }));
		 */
	}
}
 
Example #11
Source File: PipeTransformationTest.java    From rice with Educational Community License v2.0 4 votes vote down vote up
@Test public void testPipeUsingTemplate(){
	try{
		// Instantiate a TransformerFactory.
	  	TransformerFactory tFactory = TransformerFactory.newInstance();
	    // Determine whether the TransformerFactory supports The use uf SAXSource 
	    // and SAXResult
	    if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE)){
	    	// Cast the TransformerFactory to SAXTransformerFactory.
	        SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);	  
	        // Get Relevant StyleSheets
	        URIResolver resolver = new WidgetURITestResolver();
	        saxTFactory.setURIResolver(resolver);
	        
	        /*
	        Document edlStyle,templateStyle;
	        edlStyle=XMLUtil.parseInputStream(PipeTransformationTest.class.getResourceAsStream("StudentInitiatedDrop_Style_pipeTest.xml"));
	        // Get Template Name
	        XPathFactory xPathFactory=XPathFactory.newInstance();
            XPath xPath=xPathFactory.newXPath();
            Node node=(Node)xPath.evaluate("//use[0]",edlStyle,XPathConstants.NODE);
            //Node node=nodes.item(0);
            if(node!=null){
            	if(node.hasAttributes()){
            		Node testAttri=node.getAttributes().getNamedItem("name");
            		if(testAttri!=null){
            			templateName=testAttri.getNodeValue();
            		}else{
            			//set default template as widgets
            			templateName="widgets";
            		}
            	}
            }
           
            System.out.println(templateName);
             */
            //templateStyle=XMLUtil.parseInputStream(PipeTransformationTest.class.getResourceAsStream("widgets_pipeTest.xml"));
	        // Create a TransformerHandler for each stylesheet.
	        TransformerHandler tHandler1 = saxTFactory.newTransformerHandler(new StreamSource(PipeTransformationTest.class.getResourceAsStream("StudentInitiatedDrop_Style_pipeTest.xml")));
	       // TransformerHandler tHandler2 = saxTFactory.newTransformerHandler(new StreamSource(PipeTransformationTest.class.getResourceAsStream("trans.xml")));
	        	//TransformerHandler tHandler3 = saxTFactory.newTransformerHandler(new StreamSource("foo3.xsl"));
	      
	        // Create an XMLReader.
	  	    XMLReader reader = XMLReaderFactory.createXMLReader();
	        reader.setContentHandler(tHandler1);
	        reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHandler1);

	        //tHandler1.setResult(new SAXResult(tHandler2));
	        	//tHandler2.setResult(new SAXResult(tHandler3));

	        // transformer3 outputs SAX events to the serializer.
	        java.util.Properties xmlProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
	        xmlProps.setProperty("indent", "yes");
	        xmlProps.setProperty("standalone", "no");
	        Serializer serializer = SerializerFactory.getSerializer(xmlProps);
	        FileOutputStream transformedXML=new FileOutputStream("c://file.xml");
	        serializer.setOutputStream(transformedXML);
	        tHandler1.setResult(new SAXResult(serializer.asContentHandler()));

	  	    // Parse the XML input document. The input ContentHandler and output ContentHandler
	        // work in separate threads to optimize performance.   
	        reader.parse(new InputSource(PipeTransformationTest.class.getResourceAsStream("StudentInitiatedDrop.xml")));
	    }
		
	}catch(Exception ex){
		ex.printStackTrace();
	}
}
 
Example #12
Source File: MorphExtract.java    From openccg with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void extractMorph(ExtractionProperties extractProps)
		throws TransformerException, TransformerConfigurationException,
		SAXException, IOException, JDOMException {

	System.out.println("Extracting morph:");
	System.out.println("Generating morph.xml");

	TransformerFactory tFactory = TransformerFactory.newInstance();

	File morphFile = new File(new File(extractProps.destDir), "morph.xml");
	File tempFile = new File(new File(extractProps.tempDir), "temp.xml");

	if (tFactory.getFeature(SAXSource.FEATURE)
			&& tFactory.getFeature(SAXResult.FEATURE)) {

		SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);

		ArrayList<XMLFilter> filterChain = new ArrayList<XMLFilter>();
		ArrayList<String> xslChain = new ArrayList<String>();

		if (extractProps.macroSpecs.length() > 0) {

		}

		addTransforms(xslChain, extractProps.macroSpecs);

		for (String xslFile : xslChain)
			filterChain.add(saxTFactory.newXMLFilter(ExtractGrammar
					.getSource(xslFile)));
		// Create an XMLReader and set first xsl transform to that.
		XMLReader reader = XMLReaderFactory.createXMLReader();
		XMLFilter xmlFilter0 = filterChain.get(0);
		xmlFilter0.setParent(reader);

		//Create chain of xsl transforms
		// Create an XMLFilter for each stylesheet.
		for (int i = 1; i < filterChain.size(); i++) {
			XMLFilter xmlFilterPrev = filterChain.get(i - 1);
			XMLFilter xmlFilterCurr = filterChain.get(i);
			xmlFilterCurr.setParent(xmlFilterPrev);
		}

		XMLFilter xmlFilter = filterChain.get(filterChain.size() - 1);

		java.util.Properties xmlProps = OutputPropertiesFactory
				.getDefaultMethodProperties("xml");
		xmlProps.setProperty("indent", "yes");
		xmlProps.setProperty("standalone", "no");
		xmlProps.setProperty("{http://xml.apache.org/xalan}indent-amount",
				"2");
		Serializer serializer = SerializerFactory.getSerializer(xmlProps);
		serializer.setOutputStream(new FileOutputStream(morphFile));
		//XMLFilter xmlFilter = xmlFilter2;
		//XMLFilter xmlFilter = xmlFilter3;

		xmlFilter.setContentHandler(serializer.asContentHandler());
		xmlFilter.parse(new InputSource(tempFile.getPath()));
	}

	//Deleting the temporary lex file
	//tempFile.delete();
}
 
Example #13
Source File: RulesExtract.java    From openccg with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void extractRules(ExtractionProperties extractProps) throws TransformerException, TransformerConfigurationException,SAXException, IOException,JDOMException{
	
	System.out.println("Extracting rule info:");
	
	File rulesFile = new File(new File(extractProps.destDir), "rules.xml");
	File tempFile = new File(new File(extractProps.tempDir), "temp-rules.xml");
	PrintWriter tempOut=new PrintWriter(new FileOutputStream(tempFile),true);
	
	File ccgbankDir = new File(extractProps.srcDir);
	File[] ccgbankSections=ccgbankDir.listFiles();
	Arrays.sort(ccgbankSections);
	
	RulesTally.RULE_FREQ_CUTOFF = extractProps.ruleFreqCutoff;
       RulesTally.KEEP_UNMATCHED = !extractProps.skipUnmatched;
	
	// add root
	tempOut.println("<rules>");
	
	TransformerFactory tFactory = TransformerFactory.newInstance();
	Transformer transformer = tFactory.newTransformer(ExtractGrammar.getSource("opennlp.ccgbank/transform/rulesExtr.xsl"));
	
	for (int i=extractProps.startSection; i<=extractProps.endSection; i++){
		
		File[] files=ccgbankSections[i].listFiles();
		Arrays.sort(files);
		
		int fileStart = 0; int fileLimit = files.length;
		if (extractProps.fileNum >= 0) {
			fileStart = extractProps.fileNum;
			fileLimit = extractProps.fileNum + 1;
		}
		
		for (int j=fileStart; j<fileLimit; j++){
			String inputFile=files[j].getAbsolutePath();
			if (j == fileStart) System.out.print(files[j].getName() + " ");
			else if (j == (fileLimit-1)) System.out.println(" " + files[j].getName());
			else System.out.print(".");
			if (fileStart == fileLimit-1) System.out.println();
			try {
				transformer.transform(new StreamSource(inputFile),new StreamResult(tempOut));
			}
			catch (Exception exc) {
                   System.out.println("Skipping: " + inputFile);
                   System.out.println(exc.toString());
			}
			tempOut.flush();
		}
	}
	
	tempOut.flush();
	tempOut.println("</rules>");
	tempOut.close();
	
	RulesTally.printTally(extractProps);
	
	System.out.println("Generating rules.xml");
	
	if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE)){
		
		SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
		
		// Create an XMLFilter for each stylesheet.
		XMLFilter xmlFilter1 = saxTFactory.newXMLFilter(ExtractGrammar.getSource("opennlp.ccgbank/transform/ccgRules.xsl"));
		

		//XMLFilter xmlFilter3 = saxTFactory.newXMLFilter(new StreamSource("foo3.xsl"));
		
		// Create an XMLReader.
		XMLReader reader = XMLReaderFactory.createXMLReader();
		
		// xmlFilter1 uses the XMLReader as its reader.
		xmlFilter1.setParent(reader);
		
		java.util.Properties xmlProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
		xmlProps.setProperty("indent", "yes");
		xmlProps.setProperty("standalone", "no"); 
		xmlProps.setProperty("{http://xml.apache.org/xalan}indent-amount", "2");
		Serializer serializer = SerializerFactory.getSerializer(xmlProps);
		serializer.setOutputStream(new FileOutputStream(rulesFile));


		XMLFilter xmlFilter = xmlFilter1;
		xmlFilter.setContentHandler(serializer.asContentHandler());
		xmlFilter.parse(new InputSource(tempFile.getPath()));
	}
	
	//Deleting the temporory lex file
	//lexiconTempFile.delete();
}