当前位置: 首页>>代码示例>>Java>>正文


Java SAXBuilder.setEntityResolver方法代码示例

本文整理汇总了Java中org.jdom.input.SAXBuilder.setEntityResolver方法的典型用法代码示例。如果您正苦于以下问题:Java SAXBuilder.setEntityResolver方法的具体用法?Java SAXBuilder.setEntityResolver怎么用?Java SAXBuilder.setEntityResolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jdom.input.SAXBuilder的用法示例。


在下文中一共展示了SAXBuilder.setEntityResolver方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadXml

import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
public static Element loadXml(File configXml) throws Exception {
    SAXBuilder saxBuilder = new SAXBuilder();
    saxBuilder.setEntityResolver(new EntityResolver() {

        public InputSource resolveEntity(
            String publicId,
            String systemId
        )
        throws SAXException, IOException {
            return new InputSource(new CharArrayReader(new char[0]));
        }
    });
    final Document document = saxBuilder.build(configXml);
    return document.getRootElement();
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:16,代码来源:ModelGen.java

示例2: processResource

import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
public void processResource( String resource, InputStream is, List<Relocator> relocators )
    throws IOException
{
    Document r;
    try
    {
        SAXBuilder builder = new SAXBuilder( false );
        builder.setExpandEntities( false );
        if ( ignoreDtd )
        {
            builder.setEntityResolver( new EntityResolver()
            {
                public InputSource resolveEntity( String publicId, String systemId )
                    throws SAXException, IOException
                {
                    return new InputSource( new StringReader( "" ) );
                }
            } );
        }
        r = builder.build( is );
    }
    catch ( JDOMException e )
    {
        throw new RuntimeException( "Error processing resource " + resource + ": " + e.getMessage(), e );
    }

    if ( doc == null )
    {
        doc = r;
    }
    else
    {
        Element root = r.getRootElement();

        for ( @SuppressWarnings( "unchecked" )
        Iterator<Attribute> itr = root.getAttributes().iterator(); itr.hasNext(); )
        {
            Attribute a = itr.next();
            itr.remove();

            Element mergedEl = doc.getRootElement();
            Attribute mergedAtt = mergedEl.getAttribute( a.getName(), a.getNamespace() );
            if ( mergedAtt == null )
            {
                mergedEl.setAttribute( a );
            }
        }

        for ( @SuppressWarnings( "unchecked" )
        Iterator<Content> itr = root.getChildren().iterator(); itr.hasNext(); )
        {
            Content n = itr.next();
            itr.remove();

            doc.getRootElement().addContent( n );
        }
    }
}
 
开发者ID:javiersigler,项目名称:apache-maven-shade-plugin,代码行数:59,代码来源:XmlAppendingTransformer.java

示例3: XML2JDOM

import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
/**
 * Generates a Document from a XML input stream
 * 
 * @param is the input xml stream
 * @throws JDOMException if something goes wrong during the parsing process
 * @throws IOException if something goes wrong reading stream
 */
public static void XML2JDOM(Reader is, Document doc) throws IOException, JDOMException {
    Document tdoc = new Document();
    SAXBuilder builder = new SAXBuilder();
    builder.setExpandEntities(false);
    builder.setEntityResolver(new MyResolver());
    tdoc = builder.build(is);
    Element root = tdoc.getRootElement();
    Element new_root = (Element) root.clone();
    doc.setRootElement(new_root);
}
 
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:18,代码来源:JDOMUtils.java

示例4: XML2JDOM

import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
/**
 * Generates a Document from a XML input stream
 * 
 * @param is the input xml stream
 * @throws Exception if something goes wrong during the parsing process
 */
public static void XML2JDOM(Reader is, Document doc) throws Exception {
    Document tdoc = new Document();
    SAXBuilder builder = new SAXBuilder();
    builder.setExpandEntities(false);
    builder.setEntityResolver(new MyResolver());
    tdoc = builder.build(is);
    Element root = tdoc.getRootElement();
    Element new_root = (Element) root.clone();
    doc.setRootElement(new_root);
}
 
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:17,代码来源:JDOMUtils.java

示例5: loadXml

import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
public static Element loadXml(File configXml) throws Exception {
  SAXBuilder saxBuilder = new SAXBuilder();
  saxBuilder.setEntityResolver(new EntityResolver() {
    public InputSource resolveEntity(String publicId,
                                     String systemId)
            throws SAXException, IOException {
      return new InputSource(new CharArrayReader(new char[0]));
    }
  });
  final Document document = saxBuilder.build(configXml);
  return document.getRootElement();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:ModelGen.java

示例6: parseXMLFileAsJDOMDocument

import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
/**
 * Parses an XML file into a DOM document.
 * @param filename the path of the file.
 * @param useDTD true if the XML DTD should be used.
 * @return DOM document
 * @throws IOException 
 * @throws JDOMException 
 * @throws Exception if XML could not be parsed or file could not be found.
 */
public static Document parseXMLFileAsJDOMDocument(String filename, boolean useDTD) throws IOException, JDOMException {
	InputStream stream = getInputStream(filename);
	/* bug 2909888: read the inputstream with a specific encoding instead of the system default. */
	InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
	SAXBuilder saxBuilder = new SAXBuilder(useDTD);
	/* [landrus, 26.11.09]: Use an entity resolver to load dtds from the classpath */
	saxBuilder.setEntityResolver(new ClasspathEntityResolver());
	Document result = saxBuilder.build(reader);
	stream.close();
       
	return result;
}
 
开发者ID:mars-sim,项目名称:mars-sim,代码行数:22,代码来源:SimulationConfig.java


注:本文中的org.jdom.input.SAXBuilder.setEntityResolver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。