本文整理汇总了Java中org.jdom2.input.SAXBuilder.setEntityResolver方法的典型用法代码示例。如果您正苦于以下问题:Java SAXBuilder.setEntityResolver方法的具体用法?Java SAXBuilder.setEntityResolver怎么用?Java SAXBuilder.setEntityResolver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom2.input.SAXBuilder
的用法示例。
在下文中一共展示了SAXBuilder.setEntityResolver方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSection
import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
/**
* Adds a section to the MyCoRe webpage.
*
* @param title the title of the section
* @param xmlAsString xml string which is added to the section
* @param lang the language of the section specified by a language key.
* @return added section
*/
public Element addSection(String title, String xmlAsString, String lang) throws IOException, SAXParseException,
JDOMException {
String sb = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<!DOCTYPE MyCoReWebPage PUBLIC \"-//MYCORE//DTD MYCOREWEBPAGE 1.0//DE\" "
+ "\"http://www.mycore.org/mycorewebpage.dtd\">" + "<MyCoReWebPage>" + xmlAsString + "</MyCoReWebPage>";
SAXBuilder saxBuilder = new SAXBuilder();
saxBuilder.setEntityResolver((publicId, systemId) -> {
String resource = systemId.substring(systemId.lastIndexOf("/"));
InputStream is = getClass().getResourceAsStream(resource);
if (is == null) {
throw new IOException(new FileNotFoundException("Unable to locate resource " + resource));
}
return new InputSource(is);
});
StringReader reader = new StringReader(sb);
Document doc = saxBuilder.build(reader);
return this.addSection(title, doc.getRootElement().cloneContent(), lang);
}
示例2: parse
import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
/**
* Parse feed from input source with base location set and create channel.
*
* @param cBuilder specific channel builder to use.
* @param inpSource input source of data.
* @param baseLocation base location of feed.
* @return parsed channel.
* @throws IOException if IO errors occur.
* @throws ParseException if parsing is not possible.
*/
public static ChannelIF parse(ChannelBuilderIF cBuilder, InputSource inpSource,
URL baseLocation)
throws IOException, ParseException {
// document reading without validation
SAXBuilder saxBuilder = new SAXBuilder();
// turn off DTD loading
saxBuilder.setEntityResolver(new NoOpEntityResolver());
try {
Document doc = saxBuilder.build(inpSource);
ChannelIF channel = parse(cBuilder, doc);
channel.setLocation(baseLocation);
return channel;
} catch (JDOMException e) {
throw new ParseException("Problem parsing " + inpSource + ": " + e);
}
}
示例3: MCRXMLParserImpl
import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
public MCRXMLParserImpl(XMLReaderJDOMFactory factory, boolean silent) {
this.validate = factory.isValidating();
builder = new SAXBuilder(factory);
builder.setFeature(FEATURE_NAMESPACES, true);
builder.setFeature(FEATURE_SCHEMA_SUPPORT, validate);
builder.setFeature(FEATURE_FULL_SCHEMA_SUPPORT, false);
builder.setErrorHandler(new MCRXMLParserErrorHandler(silent));
builder.setEntityResolver(new XercesBugFixResolver(MCREntityResolver.instance()));
}
示例4: parse
import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
public static Collection<FeedIF> parse(InputSource inpSource,
URL baseLocation) throws IOException, ParseException {
// document reading without validation
SAXBuilder saxBuilder = new SAXBuilder(false);
// turn off DTD loading
saxBuilder.setEntityResolver(new NoOpEntityResolver());
try {
Document doc = saxBuilder.build(inpSource);
return parse(doc);
} catch (JDOMException e) {
throw new ParseException(e);
}
}
示例5: parseStream
import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
/**
* Reads xml from an InputStream and returns the parsed root element.
*
* @param in
* the InputStream that contains the XML document
* @return the root element of the parsed input stream
*/
protected Element parseStream(InputStream in) throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);
builder.setEntityResolver(MCREntityResolver.instance());
return builder.build(in).getRootElement();
}