Package org.xml.sax

Examples of org.xml.sax.XMLFilter


    private void writeSVGToOutput(SVGGraphics2D svgGenerator,
                                  Element svgRoot,
                                  TranscoderOutput output)
        throws TranscoderException {
        // XMLFilter
        XMLFilter xmlFilter = output.getXMLFilter();
        if(xmlFilter != null){
            handler.fatalError(new TranscoderException("" + ERROR_INCOMPATIBLE_OUTPUT_TYPE));
        }

        // <!> FIX ME: SHOULD HANDLE DOCUMENT INPUT
View Full Code Here


        Document doc = output.getDocument();

        if (doc != null) return;

        // XMLFilter
        XMLFilter xmlFilter = output.getXMLFilter();
        if (xmlFilter != null) {
            handler.fatalError(new TranscoderException("" + ERROR_INCOMPATIBLE_OUTPUT_TYPE));
        }

        try {
View Full Code Here

            Templates t = createTemplates(getInTemplates(mt), inParamsMap, inProperties);
            if (t == null && supportJaxbOnly) {
                return super.unmarshalFromInputStream(unmarshaller, is, mt);
            }
            XMLFilter filter = factory.newXMLFilter(t);
            SAXSource source = new SAXSource(filter, new InputSource(is));
            if (systemId != null) {
                source.setSystemId(systemId);
            }
            return unmarshaller.unmarshal(source);
View Full Code Here

            throw new IllegalArgumentException("Unsupported programming language: " + languageName);
        }
        // Create a XMLReader
        XMLReader reader = XMLReaderFactory.createXMLReader();
        // Get the needed preprocess filter
        XMLFilter preprocessFilter = this.getPreprocessFilter(filename, programmingLanguage);
        preprocessFilter.setParent(reader);
        // Create code generator
        LogicsheetCodeGenerator codeGenerator = new LogicsheetCodeGenerator();
        codeGenerator.setLogger(getLogger());
        codeGenerator.initialize();
        // set the transformer chain builder filter
View Full Code Here

      // What can we do?
      // TODO: User diagnostics.
    }

    XMLFilter filter
      = ((SAXTransformerFactory) tfactory).newXMLFilter(new StreamSource(xslID));

    filter.setParent(reader);

    // Now, when you call transformer.parse, it will set itself as
    // the content handler for the parser object (it's "parent"), and
    // will then call the parse method on the parser.
    filter.parse(new InputSource(sourceID));
  }
View Full Code Here

    throw new org.xml.sax.SAXException( ex1.toString() );
      } catch( NoSuchMethodError ex2 ) {
      }
      if( reader==null ) reader = XMLReaderFactory.createXMLReader();

      XMLFilter filter1 = stf.newXMLFilter(new StreamSource(xslID_1));
      XMLFilter filter2 = stf.newXMLFilter(new StreamSource(xslID_2));
      XMLFilter filter3 = stf.newXMLFilter(new StreamSource(xslID_3));

      if (null != filter1) // If one success, assume all were success.
      {
        // transformer1 will use a SAX parser as it's reader.   
        filter1.setParent(reader);

        // transformer2 will use transformer1 as it's reader.
        filter2.setParent(filter1);

        // transform3 will use transform2 as it's reader.
        filter3.setParent(filter2);

        filter3.setContentHandler(new ExampleContentHandler());
        // filter3.setContentHandler(new org.xml.sax.helpers.DefaultHandler());

        // Now, when you call transformer3 to parse, it will set 
        // itself as the ContentHandler for transform2, and
        // call transform2.parse, which will set itself as the
        // content handler for transform1, and call transform1.parse,
        // which will set itself as the content listener for the
        // SAX parser, and call parser.parse(new InputSource("xml/foo.xml")).
        filter3.parse(new InputSource(sourceID));
      }
      else
      {
        System.out.println(
                           "Can't do exampleXMLFilter because "+
View Full Code Here

    if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE))
    {
      // Cast the TransformerFactory to SAXTransformerFactory.
      SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
      // Create an XMLFilter for each stylesheet.
      XMLFilter xmlFilter1 = saxTFactory.newXMLFilter(new StreamSource("foo1.xsl"));
      XMLFilter xmlFilter2 = saxTFactory.newXMLFilter(new StreamSource("foo2.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);
   
      // xmlFilter2 uses xmlFilter1 as its reader.
      xmlFilter2.setParent(xmlFilter1);
   
      // xmlFilter3 uses xmlFilter2 as its reader.
      xmlFilter3.setParent(xmlFilter2);
   
      // xmlFilter3 outputs SAX events to the serializer.
      Serializer serializer = SerializerFactory.getSerializer
                      (OutputPropertiesFactory.getDefaultMethodProperties("xml"));       
      serializer.setOutputStream(System.out);
      xmlFilter3.setContentHandler(serializer.asContentHandler());

      // Perform the series of transformations as follows:
      //   - transformer3 gets its parent (transformer2) as the XMLReader/XMLFilter
      //     and calls transformer2.parse(new InputSource("foo.xml")).
      //   - transformer2 gets its parent (transformer1) as the XMLReader/XMLFilter
      //     and calls transformer1.parse(new InputSource("foo.xml")).
      //   - transformer1 gets its parent (reader, a SAXParser) as the XMLReader
      //     and calls reader.parse(new InputSource("foo.xml")).
      //   - reader parses the XML document and sends the SAX parse events to transformer1,
      //     which performs transformation 1 and sends the output to transformer2.
      //   - transformer2 parses the transformation 1 output, performs transformation 2, and
      //     sends the output to transformer3.
      //   - transformer3 parses the transformation 2 output, performs transformation 3,
      //     and sends the output to the serializer.
      xmlFilter3.parse(new InputSource("foo.xml"));
    }
  }
View Full Code Here

        try {
            // If the Source object is not changed, the
            // getTransformerHandler() of XSLTProcessor will simply return
            // the old template object. If the Source is unchanged, the
            // namespaces are not modified either.
            XMLFilter saveNSFilter = new SaveNamespaceFilter(namespaces);
            return xsltProcessor.getTransformerHandler(source, saveNSFilter);
        } finally {
            // Release used resources
            source.recycle();
        }
View Full Code Here

    if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE))
    {
      // Cast the TransformerFactory to SAXTransformerFactory.
      SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
      // Create an XMLFilter for each stylesheet.
      XMLFilter xmlFilter1 = saxTFactory.newXMLFilter(new StreamSource("foo1.xsl"));
      XMLFilter xmlFilter2 = saxTFactory.newXMLFilter(new StreamSource("foo2.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);
   
      // xmlFilter2 uses xmlFilter1 as its reader.
      xmlFilter2.setParent(xmlFilter1);
   
      // xmlFilter3 uses xmlFilter2 as its reader.
      xmlFilter3.setParent(xmlFilter2);
   
      // xmlFilter3 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);
      xmlFilter3.setContentHandler(serializer.asContentHandler());

      // Perform the series of transformations as follows:
      //   - transformer3 gets its parent (transformer2) as the XMLReader/XMLFilter
      //     and calls transformer2.parse(new InputSource("foo.xml")).
      //   - transformer2 gets its parent (transformer1) as the XMLReader/XMLFilter
      //     and calls transformer1.parse(new InputSource("foo.xml")).
      //   - transformer1 gets its parent (reader, a SAXParser) as the XMLReader
      //     and calls reader.parse(new InputSource("foo.xml")).
      //   - reader parses the XML document and sends the SAX parse events to transformer1,
      //     which performs transformation 1 and sends the output to transformer2.
      //   - transformer2 parses the transformation 1 output, performs transformation 2, and
      //     sends the output to transformer3.
      //   - transformer3 parses the transformation 2 output, performs transformation 3,
      //     and sends the output to the serializer.
      xmlFilter3.parse(new InputSource("foo.xml"));
    }
  }
View Full Code Here

                    tFactory.getFeature(SAXResult.FEATURE)) {
                // Cast the TransformerFactory to SAXTransformerFactory.
                SAXTransformerFactory saxTFactory =
                  ((SAXTransformerFactory) tFactory);
                // Create an XMLFilter for each stylesheet.
                XMLFilter xmlfilter = saxTFactory.newXMLFilter(
                                        new StreamSource(xsltfile));

                // Create an XMLReader.
                XMLReader parser = createParser();
                if (parser == null) {
                    MessageHandler.errorln("ERROR: Unable to create SAX parser");
                    System.exit(1);
                }

                // xmlFilter1 uses the XMLReader as its reader.
                xmlfilter.setParent(parser);
                return xmlfilter;
            } else {
                MessageHandler.errorln(
                  "Your parser doesn't support the features SAXSource and SAXResult." +
                  "\nMake sure you are using a xsl parser which supports TrAX");
View Full Code Here

TOP

Related Classes of org.xml.sax.XMLFilter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.