Package org.exist.memtree

Examples of org.exist.memtree.SAXAdapter


*
*/
public class Utils {

    public static NodeImpl nodeFromString(XQueryContext context, String source) throws IOException {
        SAXAdapter adapter = new SAXAdapter(context);

        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
       
        XMLReader xr;
    try {
      SAXParser parser = factory.newSAXParser();

      xr = parser.getXMLReader();
      xr.setContentHandler(adapter);
      xr.setProperty(Namespaces.SAX_LEXICAL_HANDLER, adapter);

    } catch (Exception e) {
      throw new IOException(e);
    }
       
        try {
            InputSource src = new InputSource(new StringReader(source));
            xr.parse(src);
           
            return (NodeImpl) adapter.getDocument();
    } catch (SAXException e) {
      throw new IOException(e);
        }
    }
View Full Code Here


                    LOG.error(errorMsg, e);

                    throw new IOException(errorMsg, e);
            }

            final SAXAdapter adapter = new SAXAdapter();

            // allow multiple attributes of the same name attached to the same element
            // to enhance resilience against bad HTML. The last attribute value wins.
            adapter.setReplaceAttributeFlag(true);

            reader.setContentHandler(adapter);
            reader.parse(srcHtml);
            final Document doc = adapter.getDocument();
            memtreeDoc = (DocumentImpl) doc;
            memtreeDoc.setContext(context);
           
            return memtreeDoc;
  }
View Full Code Here

        factory.setNamespaceAware(true);
        InputSource src = new InputSource(file.toURI().toASCIIString());
        SAXParser parser = factory.newSAXParser();
        XMLReader xr = parser.getXMLReader();

        SAXAdapter adapter = new SAXAdapter();
        xr.setContentHandler(adapter);
        xr.setProperty(Namespaces.SAX_LEXICAL_HANDLER, adapter);
        xr.parse(src);

        return adapter.getDocument();
    }
View Full Code Here

      factory.setNamespaceAware(true)

      InputSource src = new InputSource(source);
      SAXParser parser = factory.newSAXParser();
      XMLReader reader = parser.getXMLReader();
      SAXAdapter adapter = new SAXAdapter();
      reader.setContentHandler(adapter);
      reader.parse(src);
   
      DocumentAtExist document = (DocumentAtExist) adapter.getDocument();
//      document.setContext(new XSLContext(broker));
      //return receiver.getDocument();
      return compile((ElementAtExist) document.getDocumentElement(), broker);
    } catch (ParserConfigurationException e) {
          LOG.debug(e);
View Full Code Here

              InputSource src = new InputSource(reader);

                SAXParser parser = factory.newSAXParser();
                XMLReader xr = parser.getXMLReader();

              SAXAdapter adapter = new SAXAdapter(context);
              xr.setContentHandler(adapter);
              xr.setProperty(Namespaces.SAX_LEXICAL_HANDLER, adapter);
              xr.parse(src);

            Sequence listenerParams[] = new Sequence[3];
           
            listenerParams[0] = new IntegerValue(chatHandle);
              listenerParams[1] = (DocumentImpl) adapter.getDocument();        
              listenerParams[2] = listenerParam;
             
        chatListenerFunction.evalFunction(contextSequence, null, listenerParams);

          } catch (ParserConfigurationException e) {
View Full Code Here

                                        factory.setNamespaceAware(true);
                                        InputSource src = new InputSource(sqlXml.getCharacterStream());
                                        SAXParser parser = factory.newSAXParser();
                                        XMLReader xr = parser.getXMLReader();

                                        SAXAdapter adapter = new AppendingSAXAdapter(builder);
                                        xr.setContentHandler(adapter);
                                        xr.setProperty(Namespaces.SAX_LEXICAL_HANDLER, adapter);
                                        xr.parse(src);
                                    }
                                } catch(Exception e) {
View Full Code Here

          Grammar grammar = grammarFactory.createGrammar(xsdInputStream);
          exiFactory.setGrammar(grammar);
        }
      }
      SAXDecoder decoder = new SAXDecoder(exiFactory);
      SAXAdapter adapter = new AppendingSAXAdapter(builder);
            decoder.setContentHandler(adapter);
            decoder.parse(new InputSource(exiBinary.getInputStream()));
       
        NodeValue node  = (NodeValue)builder.getDocument().getDocumentElement();
        return node;
View Full Code Here

        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        InputSource src = new InputSource(is);
        SAXParser parser = factory.newSAXParser();
        XMLReader reader = parser.getXMLReader();
        SAXAdapter adapter = new SAXAdapter();
        reader.setContentHandler(adapter);
        reader.parse(src);
       
        ConfigurationImpl config = new ConfigurationImpl((ElementAtExist) adapter.getDocument().getDocumentElement());
       
        ConfigurableObject object = new ConfigurableObject(config);
       
        assertEquals("a", object.some);
       
View Full Code Here

    }
    return res;
  }
 
    public NodeImpl loadVarFromURI(XQueryContext context, String uri) throws IOException {
        SAXAdapter adapter = new SAXAdapter(context);

        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
       
        XMLReader xr;
    try {
      SAXParser parser = factory.newSAXParser();

      xr = parser.getXMLReader();
      xr.setContentHandler(adapter);
      xr.setProperty(Namespaces.SAX_LEXICAL_HANDLER, adapter);

    } catch (Exception e) {
      throw new IOException(e);
    }
       
        try {
//      URL url = new URL(uri);
//      InputStreamReader isr = new InputStreamReader(url.openStream(), "UTF-8");
      InputStreamReader isr = new InputStreamReader(new FileInputStream(uri), "UTF-8");
            InputSource src = new InputSource(isr);
            xr.parse(src);
            isr.close();
           
            adapter.getDocument().setDocumentURI(new File(uri).getAbsoluteFile().toString());
           
            return (NodeImpl) adapter.getDocument();
    } catch (SAXException e) {
     
      //workaround BOM
      if (e.getMessage().equals("Content is not allowed in prolog.")) {
              try {
                String xml = readFileAsString(new File(uri));
                xml = xml.trim().replaceFirst("^([\\W]+)<","<");
                InputSource src = new InputSource(new StringReader(xml));
          xr.parse(src);
               
          adapter.getDocument().setDocumentURI(new File(uri).getAbsoluteFile().toString());

                return (NodeImpl) adapter.getDocument();
        } catch (SAXException e1) {
          throw new IOException(e);
        }
      }
      throw new IOException(e);
View Full Code Here

      throw new IOException(e);
        }
    }

    public NodeImpl loadVarFromString(XQueryContext context, String source) throws IOException {
        SAXAdapter adapter = new SAXAdapter(context);

        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
       
        XMLReader xr;
    try {
      SAXParser parser = factory.newSAXParser();

      xr = parser.getXMLReader();
      xr.setContentHandler(adapter);
      xr.setProperty(Namespaces.SAX_LEXICAL_HANDLER, adapter);

    } catch (Exception e) {
      throw new IOException(e);
    }
       
        try {
            InputSource src = new InputSource(new StringReader(source));
            xr.parse(src);
           
            return (NodeImpl) adapter.getDocument();
    } catch (SAXException e) {
      throw new IOException(e);
        }
    }
View Full Code Here

TOP

Related Classes of org.exist.memtree.SAXAdapter

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.