Package org.xml.sax

Examples of org.xml.sax.XMLFilter


  public void setXMLReader(XMLReader reader)
      throws UnsupportedOperationException {
    if (reader instanceof SAXWriter) {
      this.xmlReader = (SAXWriter) reader;
    } else if (reader instanceof XMLFilter) {
      XMLFilter filter = (XMLFilter) reader;

      while (true) {
        XMLReader parent = filter.getParent();

        if (parent instanceof XMLFilter) {
          filter = (XMLFilter) parent;
        } else {
          break;
        }
      }

      // install filter in SAXWriter....
      filter.setParent(xmlReader);
      xmlReader = filter;
    } else {
      throw new UnsupportedOperationException();
    }
  }
View Full Code Here


       
        // In general, a filter may violate the constraints of XML 1.0.
        // However, I specifically trust Norm Walsh not to do that, so
        // if his filters are being used we look at the parent instead.
        if (parserName.equals("org.apache.xml.resolver.tools.ResolvingXMLFilter")) {
            XMLFilter filter = (XMLFilter) parser;
            parserName = filter.getParent().getClass().getName();
        }
       
        // These parsers are known to not make all the checks
        // they're supposed to. :-(
        if (parserName.equals("gnu.xml.aelfred2.XmlReader")) return false;
View Full Code Here

      }

      if (_systemId != null && is != null)
        is.setSystemId(_systemId);

      XMLFilter filter = (XMLFilter) _filter;

      if (xmlReader == null) {
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
       
        // jsp/1m14
        parserFactory.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
        parserFactory.setFeature("http://xml.org/sax/features/namespaces", true);
       
        xmlReader = parserFactory.newSAXParser().getXMLReader();
      }

      // jsp/1g05
      if (_filter != null && _var == null && _varDom == null) {
        filter.setParent(xmlReader);
       
        filter.parse(is);
      } else {
        DocumentBuilderFactory domFactory
          = DocumentBuilderFactory.newInstance();
       
        domFactory.setNamespaceAware(true);
        DocumentBuilder builder = domFactory.newDocumentBuilder();
       
        Document doc = builder.newDocument();
       
        SAXTransformerFactory saxFactory
          = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
       
        //saxFactory.setAttribute("http://xml.org/sax/features/namespace-prefixes", false);
        // saxFactory.setAttribute("http://xml.org/sax/features/namespaces", false);
        //saxFactory.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
        // xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
       
        TransformerHandler handler
          = saxFactory.newTransformerHandler();
       
        handler.setResult(new DOMResult(doc));

        if (filter != null) {
          filter.setParent(xmlReader);
          filter.setContentHandler(handler);

          filter.parse(is);
        } else {
          xmlReader.setContentHandler(handler);

          xmlReader.parse(is);
        }
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

    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

                    && 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) {
                    throw new FOPException("Unable to create SAX parser");
                }

                // xmlFilter1 uses the XMLReader as its reader.
                xmlfilter.setParent(parser);
                return xmlfilter;
            } else {
                throw new FOPException("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

        }

        // 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.enableLogging(getLogger());
        codeGenerator.initialize();
        // set the transformer chain builder filter
View Full Code Here

            // 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(namespaceURIs);
            return xsltProcessor.getTransformerHandler(source, saveNSFilter);

        } catch (ComponentException e) {
            throw new ProcessingException("Could not obtain XSLT processor", e);
        } catch (MalformedURLException e) {
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
                                   (OutputProperties.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

                Source reader = new StaxSource(StaxUtils.createXMLStreamReader(is));
                DOMResult dom = new DOMResult();
                t.newTransformer().transform(reader, dom);
                return unmarshaller.unmarshal(dom.getNode());
            }
            XMLFilter filter = null;
            try {
                filter = factory.newXMLFilter(t);
            } catch (TransformerConfigurationException ex) {
                TemplatesImpl ti = (TemplatesImpl)t;
                filter = factory.newXMLFilter(ti.getTemplates());
                trySettingProperties(filter, ti);
            }
            XMLReader reader = new StaxSource(StaxUtils.createXMLStreamReader(is));
            filter.setParent(reader);
            SAXSource source = new SAXSource();
            source.setXMLReader(filter);
            if (systemId != null) {
                source.setSystemId(systemId);
            }
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.