Package org.xml.sax

Examples of org.xml.sax.XMLReader


                "http://xml.org/sax/features/namespace-prefixes", true);
        parser.setFeature(
                "http://xml.org/sax/features/namespaces", true);
       
        // Parser specific configuration
        XMLReader baseParser = parser;
        while (baseParser instanceof XMLFilter) {
             XMLReader parent = ((XMLFilter) baseParser).getParent();
             if (parent == null) break;
             baseParser = parent;
        }
       
        String parserName = baseParser.getClass().getName();
View Full Code Here


  }

  private static Definition saxParsing(URL url) throws SAXException, ParserConfigurationException, IOException {
    DocumentParser parser = new DocumentParser();

    XMLReader xmlReader = getXMLReader();
    xmlReader.setContentHandler(parser);
    xmlReader.setErrorHandler(parser);

    try {
      xmlReader.setFeature("http://xml.org/sax/features/validation", false);
    } catch (SAXException e) {
      // fine, the parser don't do validation
    }
    try {
      xmlReader.setFeature("http://xml.org/sax/features/external-general-entities", false);
    } catch (SAXException e) {
      // fine, the parser don't do validation
    }
    try {
      xmlReader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
    } catch (SAXException e) {
      // fine, the parser don't do validation
    }

    xmlReader.setEntityResolver(parser);
    InputStream in = url.openStream();
    xmlReader.parse(new InputSource(in));
    return parser.m_definition;
  }
View Full Code Here

    xmlReader.parse(new InputSource(in));
    return parser.m_definition;
  }

  private static XMLReader getXMLReader() throws SAXException, ParserConfigurationException {
    XMLReader xmlReader = null;
    /* Try this first for Java 5 */
    try {
      xmlReader = XMLReaderFactory.createXMLReader();
    }

View Full Code Here

    protected void parseXml(String xmlText) throws ParserConfigurationException, SAXException, IOException {
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
        parserFactory.setNamespaceAware(true);
        SAXParser parser = parserFactory.newSAXParser();
        XMLReader xmlReader = parser.getXMLReader();
        xmlReader.setContentHandler(filter);
        xmlReader.setDTDHandler(filter);
        xmlReader.parse(new InputSource(new StringReader(xmlText)));
    }
View Full Code Here

        return new QDocument();
    }
    else if (source instanceof SAXSource) {
      SAXSource saxSource = (SAXSource) source;
     
      XMLReader reader = saxSource.getXMLReader();

      if (reader == null)
        return new QDocument();
     
      InputSource inputSource = saxSource.getInputSource();

      Document doc = new QDocument();
      DOMBuilder builder = new DOMBuilder();
      builder.init(doc);
      reader.setContentHandler(builder);

      reader.parse(inputSource);
     
      return doc;
    }

    else
View Full Code Here

  {
    try {
      PageContextImpl pageContext = (PageContextImpl) this.pageContext;
      BodyContentImpl body = (BodyContentImpl) getBodyContent();

      XMLReader xmlReader = null;
      Reader reader = null;
      InputSource is;

      if (_xml != null) {
        Object obj = _xml;

        if (obj instanceof Reader) {
          reader = (Reader) obj;

          is = new InputSource(reader);
        }
        else if (obj instanceof String) {
          reader = Vfs.openString((String) obj).getReader();

          is = new InputSource(reader);
        } else if (obj instanceof XMLReader) {
          xmlReader = (XMLReader) obj;

          is = new InputSource();
        }
        else
          throw new JspException(L.l("xml must be java.io.Reader, String or org.xml.sax.XMLReader at `{0}'",
                                     obj));
      }
      else if (body != null) {
        TempCharReader tempReader = (TempCharReader) body.getReader();
        int ch;

        while (Character.isWhitespace((ch = tempReader.read()))) {
        }

        if (ch >= 0)
          tempReader.unread();
       
        reader = tempReader;

        is = new InputSource(reader);
      }
      /*
      else if (_filter != null) {
        is = null;
      }
      */
      else {
        throw new JspException(L.l("No XML document supplied via a doc attribute or inside the body of <x:parse> tag."));
      }

      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);
        }

        if (_var == null && _varDom == null)
          throw new JspException(L.l("x:parse needs either var or varDom"));

View Full Code Here

   */
  public void usePipe(Vector vTHandler, String source, String target)
          throws TransformerException, TransformerConfigurationException,
                 FileNotFoundException, IOException, SAXException, SAXNotRecognizedException
  {
    XMLReader reader = XMLReaderFactory.createXMLReader();
    TransformerHandler tHFirst = (TransformerHandler)vTHandler.firstElement();
    reader.setContentHandler(tHFirst);
    reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHFirst);
    for (int i = 1; i < vTHandler.size(); i++)
    {
      TransformerHandler tHFrom = (TransformerHandler)vTHandler.elementAt(i-1);
      TransformerHandler tHTo = (TransformerHandler)vTHandler.elementAt(i);
      tHFrom.setResult(new SAXResult(tHTo));     
    }
    TransformerHandler tHLast = (TransformerHandler)vTHandler.lastElement();
    Transformer trans = tHLast.getTransformer();
    Properties outputProps = trans.getOutputProperties();
    Serializer serializer = SerializerFactory.getSerializer(outputProps);
    serializer.setOutputStream(new FileOutputStream(target));
    tHLast.setResult(new SAXResult(serializer.asContentHandler()));
   
    reader.parse(source);
  }
View Full Code Here

  {

    String baseID;
    InputSource isource = null;
    Node node = null;
    XMLReader reader = null;

    if (source instanceof DOMSource)
    {
      DOMSource dsource = (DOMSource) source;

      node = dsource.getNode();
      baseID = dsource.getSystemId();
    }
    else
    {
      isource = SAXSource.sourceToInputSource(source);
      baseID = isource.getSystemId();
    }

    // What I try to do here is parse until the first startElement
    // is found, then throw a special exception in order to terminate
    // the parse.
    StylesheetPIHandler handler = new StylesheetPIHandler(baseID, media,
                                    title, charset);
   
    // Use URIResolver. Patch from Dmitri Ilyin
    if (m_uriResolver != null)
    {
      handler.setURIResolver(m_uriResolver);
    }

    try
    {
      if (null != node)
      {
        TreeWalker walker = new TreeWalker(handler, new org.apache.xpath.DOM2Helper(), baseID);

        walker.traverse(node);
      }
      else
      {

        // Use JAXP1.1 ( if possible )
        try
        {
          javax.xml.parsers.SAXParserFactory factory =
            javax.xml.parsers.SAXParserFactory.newInstance();

          factory.setNamespaceAware(true);

          javax.xml.parsers.SAXParser jaxpParser = factory.newSAXParser();

          reader = jaxpParser.getXMLReader();
        }
        catch (javax.xml.parsers.ParserConfigurationException ex)
        {
          throw new org.xml.sax.SAXException(ex);
        }
        catch (javax.xml.parsers.FactoryConfigurationError ex1)
        {
          throw new org.xml.sax.SAXException(ex1.toString());
        }
        catch (NoSuchMethodError ex2){}
        catch (AbstractMethodError ame){}

        if (null == reader)
        {
          reader = XMLReaderFactory.createXMLReader();
        }

        // Need to set options!
        reader.setContentHandler(handler);
        reader.parse(isource);
      }
    }
    catch (StopParseException spe)
    {
View Full Code Here

    }

    try
    {
      InputSource isource = SAXSource.sourceToInputSource(source);
      XMLReader reader = null;

      if (source instanceof SAXSource)
        reader = ((SAXSource) source).getXMLReader();
       
      boolean isUserReader = (reader != null);

      if (null == reader)
      {

        // Use JAXP1.1 ( if possible )
        try
        {
          javax.xml.parsers.SAXParserFactory factory =
            javax.xml.parsers.SAXParserFactory.newInstance();

          factory.setNamespaceAware(true);

          javax.xml.parsers.SAXParser jaxpParser = factory.newSAXParser();

          reader = jaxpParser.getXMLReader();
        }
        catch (javax.xml.parsers.ParserConfigurationException ex)
        {
          throw new org.xml.sax.SAXException(ex);
        }
        catch (javax.xml.parsers.FactoryConfigurationError ex1)
        {
          throw new org.xml.sax.SAXException(ex1.toString());
        }
        catch (NoSuchMethodError ex2){}
        catch (AbstractMethodError ame){}
      }

      if (null == reader)
        reader = XMLReaderFactory.createXMLReader();

      // If you set the namespaces to true, we'll end up getting double
      // xmlns attributes.  Needs to be fixed.  -sb
      // reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
      try
      {
        if(!isUserReader)
          reader.setFeature("http://apache.org/xml/features/validation/dynamic",
                            true);
      }
      catch (org.xml.sax.SAXException ex)
      {

        // feature not recognized
      }

      reader.setContentHandler(builder);
      reader.parse(isource);
    }
    catch (org.xml.sax.SAXException se)
    {
      if (m_errorListener != null)
      {
View Full Code Here

     *            name of the XML to load users parameter data
     * @return all users name value pairs obtained from XML file
     */
    public List<Map<String, String>> getXMLParameters(String xmlURI) throws SAXException, IOException {
        // create instances needed for parsing
        XMLReader reader = JMeterUtils.getXMLParser();
        // XMLReaderFactory.createXMLReader(vendorParseClass);
        UserParameterXMLContentHandler threadParametersContentHandler = new UserParameterXMLContentHandler();
        UserParameterXMLErrorHandler parameterErrorHandler = new UserParameterXMLErrorHandler();

        // register content handler
        reader.setContentHandler(threadParametersContentHandler);

        // register error handler
        reader.setErrorHandler(parameterErrorHandler);

        // Request validation
        reader.setFeature("http://xml.org/sax/features/validation", true); // $NON-NLS-1$

        // parse
        InputSource inputSource = new InputSource(xmlURI);
        reader.parse(inputSource);

        return threadParametersContentHandler.getParsedParameters();
    }
View Full Code Here

TOP

Related Classes of org.xml.sax.XMLReader

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.