/** 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() ); }
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); } }
/** * 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); }
@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); } }
/** 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 ) ); }
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; }
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)); }
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); } }
/** * 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); }