Java 类org.xml.sax.helpers.ParserAdapter 实例源码

项目:Java-OpenMobility    文件:ContextFilterImpl.java   
/** Create a new SAX parser for processing the Context document.<p>
 * Note that in order for WHERE Geometries to be created a valid SAX
 * parser for GML must be implemented on the {@link ContextDocumentReader}
 * 
 * @param reader
 * @param inStream
 * @throws SAXException 
 * @throws ParserConfigurationException 
 */
public ContextFilterImpl(ContextDocumentReader reader) throws SAXException, ParserConfigurationException {
    parent = reader;
    entry = new EntryFilter(this);
    contentBuffer = new ContentBuffer( reader.getInputStream() );

    // Set-up the SAX parser and source
       SAXParser contextParser = SAXParserFactory.newInstance().newSAXParser();
       contextAdapter = new ParserAdapter(contextParser.getParser());
       contextAdapter.setContentHandler( this );
       inputSource = new InputSource( new BufferedReader(new InputStreamReader(contentBuffer)) );
       charEncoding = inputSource.getEncoding();

       // Geometry parser
       SAXParser gmlParser = SAXParserFactory.newInstance().newSAXParser();
       gmAdapter = new ParserAdapter(gmlParser.getParser());
       gmAdapter.setContentHandler( parent.getGeometryFilter() );
}
项目:orbeon-forms    文件:ScopeGenerator.java   
protected static void readBean(Object bean, Mapping mapping, ContentHandler contentHandler) {
    try {
        contentHandler.startDocument();

        // Initialize Castor
        ParserAdapter adapter = new ParserAdapter(XMLUtils.newSAXParser(XMLUtils.ParserConfiguration.PLAIN).getParser());
        adapter.setContentHandler(contentHandler);
        Marshaller marshaller = new Marshaller(adapter);
        marshaller.setMarshalAsDocument(false);
        marshaller.setMapping(mapping);

        // Serialize with Castor
        marshaller.marshal(bean);

        contentHandler.endDocument();

    } catch (Exception e) {
        throw new OXFException(e);
    }
}
项目:openjdk-jdk10    文件:ParserAdapterTest.java   
/**
 * Initiate ParserAdapter.
 * @throws Exception If any errors occur.
 */
ParserAdapterTest() throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    XMLReader xmlReader = spf.newSAXParser().getXMLReader();
    XMLReaderAdapter xmlReaderAdapter = new XMLReaderAdapter(xmlReader);
    parserAdapter = new ParserAdapter(xmlReaderAdapter);
}
项目:openjdk9    文件:ParserAdapterTest.java   
/**
 * Initiate ParserAdapter.
 * @throws Exception If any errors occur.
 */
ParserAdapterTest() throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    XMLReader xmlReader = spf.newSAXParser().getXMLReader();
    XMLReaderAdapter xmlReaderAdapter = new XMLReaderAdapter(xmlReader);
    parserAdapter = new ParserAdapter(xmlReaderAdapter);
}
项目:In-the-Box-Fork    文件:ParserAdapterTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    method = "ParserAdapter",
    args = { }
)
public void testParserAdapter() {
    System.setProperty("org.xml.sax.parser",
            "tests.api.org.xml.sax.support.DoNothingParser");

    try {
        new ParserAdapter();
    } catch (SAXException e) {
        throw new RuntimeException("Unexpected exception", e);
    }
}
项目:Java-OpenMobility    文件:CapabilitiesReader.java   
/** Construct a new instance of the reader and immediately parse the supplied inputStream.
 * 
 * Use {@link #getTypeNames()} to retrieve the output.
 * 
 * @param inputStream
 * @throws SAXException
 * @throws IOException
 * @throws ParserConfigurationException
 */
public CapabilitiesReader(InputStream inputStream)  throws SAXException, IOException, ParserConfigurationException {
    InputStream dStream = decompressStream( inputStream );
    //InputSource source = new InputSource( dStream );

    // Set-up the SAX parser and source
       SAXParser contextParser = SAXParserFactory.newInstance().newSAXParser();
       contextAdapter = new ParserAdapter(contextParser.getParser());
       contextAdapter.setContentHandler( this );
       contextAdapter.parse( new InputSource( dStream ) );
}
项目:cytargetlinker    文件:XgmmlParser.java   
public Result parseXgmmlFile(File file, List<String> ids, Direction dir, DataSource ds) {
    Result res = new Result();
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        ParserAdapter pa = new ParserAdapter(sp.getParser());
        CyTargetLinkerParser parser = new CyTargetLinkerParser(ids, dir, ds);
        pa.setContentHandler(parser);
        pa.parse(new InputSource(new FileInputStream(file)));

        res.setReginName(parser.getNetworkName());
        res.setDir(dir);
        if(parser.getNetworkAttr().containsKey("url")) {
            res.setReginUrl(parser.getNetworkAttr().get("url"));
        }
        if(parser.getNetworkAttr().containsKey("type")) {
            res.setReginType(parser.getNetworkAttr().get("type"));
        }

        res.getEdges().addAll(parser.getEdgeList());

        parser.clean();
    } catch(Exception e) {
        e.printStackTrace();
    }
    return res;
}
项目:gdata-java-client    文件:SaxEventSource.java   
public void parse(DefaultHandler handler) throws IOException, SAXException {
  SAXParser sp = createSaxParser();
  ParserAdapter pa = new ParserAdapter(sp.getParser());
  pa.setContentHandler(handler);
  pa.parse(new InputSource(reader));
}
项目:orbeon-forms    文件:BeanGenerator.java   
protected void readBean(PipelineContext context, Config config, Mapping mapping, XMLReceiver xmlReceiver) {
    ExternalContext externalContext = (ExternalContext) context.getAttribute(PipelineContext.EXTERNAL_CONTEXT);
    if (externalContext == null)
        throw new OXFException("Missing external context in BeanGenerator");
    try {
        xmlReceiver.startDocument();
        String rootElementName = "beans";
        xmlReceiver.startElement("", rootElementName, rootElementName, XMLUtils.EMPTY_ATTRIBUTES);

        // Initialize Castor
        ParserAdapter adapter = new ParserAdapter(XMLUtils.newSAXParser(XMLUtils.ParserConfiguration.PLAIN).getParser());
        adapter.setContentHandler(xmlReceiver);
        Marshaller marshaller = new Marshaller(adapter);
        marshaller.setMarshalAsDocument(false);
        marshaller.setMapping(mapping);

        for (Iterator atts = config.getAttributesIterator(); atts.hasNext();) {
            String attName = (String) atts.next();
            Object bean = getBean(attName, config.getSourcesIterator(), externalContext);
            if (bean == null) {
                // Create empty element
                if (logger.isInfoEnabled())
                    logger.info("Bean " + attName + " is null");
                xmlReceiver.startElement("", attName, attName, XMLUtils.EMPTY_ATTRIBUTES);
                xmlReceiver.endElement("", attName, attName);
            } else if (bean instanceof org.w3c.dom.Document) {
                // W3C Document: send as-is
                TransformerUtils.sourceToSAX(new DOMSource((org.w3c.dom.Document) bean), new EmbeddedDocumentXMLReceiver(xmlReceiver));
            } else {
                // Serialize with Castor
                if (logger.isDebugEnabled())
                    logger.debug("Serializing bean" + attName + " value=" + bean);
                marshaller.setRootElement(attName);
                marshaller.marshal(bean);
            }
        }
        xmlReceiver.endElement("", rootElementName, rootElementName);
        xmlReceiver.endDocument();

    } catch (Exception e) {
        throw new OXFException(e);
    }
}
项目:ant    文件:XMLValidateTask.java   
/**
 * test that returns true if we are using a SAX1 parser.
 * @return true when a SAX1 parser is in use
 */
protected boolean isSax1Parser() {
    return (xmlReader instanceof ParserAdapter);
}