本文整理匯總了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();
}