當前位置: 首頁>>代碼示例>>Java>>正文


Java SAXBuilder.setEntityResolver方法代碼示例

本文整理匯總了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);
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:27,代碼來源:MyCoReWebPageProvider.java

示例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);
    }
}
 
開發者ID:nikos,項目名稱:informa,代碼行數:29,代碼來源:FeedParser.java

示例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()));
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:10,代碼來源:MCRXMLParserImpl.java

示例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);
    }
}
 
開發者ID:nikos,項目名稱:informa,代碼行數:14,代碼來源:OPMLParser.java

示例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();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:14,代碼來源:MCRURIResolver.java


注:本文中的org.jdom2.input.SAXBuilder.setEntityResolver方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。