本文整理汇总了Java中org.xml.sax.helpers.ParserAdapter.setContentHandler方法的典型用法代码示例。如果您正苦于以下问题:Java ParserAdapter.setContentHandler方法的具体用法?Java ParserAdapter.setContentHandler怎么用?Java ParserAdapter.setContentHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xml.sax.helpers.ParserAdapter
的用法示例。
在下文中一共展示了ParserAdapter.setContentHandler方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ContextFilterImpl
import org.xml.sax.helpers.ParserAdapter; //导入方法依赖的package包/类
/** 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() );
}
示例2: readBean
import org.xml.sax.helpers.ParserAdapter; //导入方法依赖的package包/类
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);
}
}
示例3: CapabilitiesReader
import org.xml.sax.helpers.ParserAdapter; //导入方法依赖的package包/类
/** 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 ) );
}
示例4: parseXgmmlFile
import org.xml.sax.helpers.ParserAdapter; //导入方法依赖的package包/类
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;
}
示例5: parse
import org.xml.sax.helpers.ParserAdapter; //导入方法依赖的package包/类
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));
}
示例6: readBean
import org.xml.sax.helpers.ParserAdapter; //导入方法依赖的package包/类
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);
}
}