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


Java XMLResolver类代码示例

本文整理汇总了Java中javax.xml.stream.XMLResolver的典型用法代码示例。如果您正苦于以下问题:Java XMLResolver类的具体用法?Java XMLResolver怎么用?Java XMLResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getStreamReader

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
/**
 * Creates an XMLStreamReader.
 *
 * @param setUseCatalog a flag indicates whether USE_CATALOG shall be set
 * through the factory
 * @param useCatalog the value of USE_CATALOG
 * @param catalog the path to a catalog
 * @param xml the xml to be parsed
 * @param resolver a resolver to be set on the reader
 * @return an instance of the XMLStreamReader
 * @throws FileNotFoundException
 * @throws XMLStreamException
 */
XMLStreamReader getStreamReader(boolean setUseCatalog, boolean useCatalog,
        String catalog, String xml, XMLResolver resolver)
        throws FileNotFoundException, XMLStreamException {
    XMLInputFactory factory = XMLInputFactory.newInstance();
    if (catalog != null) {
        factory.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog);
    }

    factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, true);
    factory.setProperty(XMLInputFactory.IS_COALESCING, true);

    if (resolver != null) {
        factory.setProperty(XMLInputFactory.RESOLVER, resolver);
    }

    if (setUseCatalog) {
        factory.setProperty(XMLConstants.USE_CATALOG, useCatalog);
    }

    InputStream entityxml = new FileInputStream(xml);
    XMLStreamReader streamReader = factory.createXMLStreamReader(xml, entityxml);
    return streamReader;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:CatalogSupportBase.java

示例2: createXMLInputFactory

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
public static XMLInputFactory createXMLInputFactory(boolean nsAware) {
    XMLInputFactory factory = XMLInputFactory.newInstance();
    setProperty(factory, XMLInputFactory.IS_NAMESPACE_AWARE, nsAware);
    setProperty(factory, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
    setProperty(factory, XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
    setProperty(factory, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
    factory.setXMLResolver(new XMLResolver() {
        public Object resolveEntity(String publicID, String systemID,
                                    String baseURI, String namespace)
            throws XMLStreamException {
            throw new XMLStreamException("Reading external entities is disabled");
        }
    });

    if (isWoodstox(factory)) {
        // just log a debug as we are good then
        LOG.debug("Created Woodstox XMLInputFactory: {}", factory);
    } else {
        // log a hint that woodstock may be a better factory to use
        LOG.info("Created XMLInputFactory: {}. DOMSource/DOMResult may have issues with {}. We suggest using Woodstox.", factory, factory);
    }
    return factory;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:StaxConverter.java

示例3: createXMLInputFactory

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
/**
 * Return a new factory so that the caller can set sticky parameters.
 * @param nsAware
 */
public static XMLInputFactory createXMLInputFactory(boolean nsAware) {
    XMLInputFactory factory = XMLInputFactory.newInstance();
    setProperty(factory, XMLInputFactory.IS_NAMESPACE_AWARE, nsAware);
    setProperty(factory, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
    setProperty(factory, XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
    setProperty(factory, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
    factory.setXMLResolver(new XMLResolver() {
        public Object resolveEntity(String publicID, String systemID,
                                    String baseURI, String namespace)
            throws XMLStreamException {
            throw new XMLStreamException("Reading external entities is disabled");
        }
    });
    return factory;
}
 
开发者ID:beemsoft,项目名称:techytax-zk,代码行数:20,代码来源:StaxUtils.java

示例4: createXMLInputFactory

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
private static XMLInputFactory createXMLInputFactory()
		throws FactoryConfigurationError {
	XMLInputFactory factory = XMLInputFactory.newInstance();
	if (!SUPPORT_DTD) {
		factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
		//these next ones are somewhat redundant, we set them just in case the DTD support property is not respected
		factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
		factory.setXMLResolver(new XMLResolver() {
			
			@Override
			public Object resolveEntity(String arg0, String arg1, String arg2,
					String arg3) throws XMLStreamException {
				throw new XMLStreamException("Reading external entities is disabled"); //$NON-NLS-1$
			}
		});
	}
	return factory;
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:19,代码来源:XMLType.java

示例5: AbstractXMLIterator

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
AbstractXMLIterator(final InputStream in,final String jaxbPath,final Boolean namespaceaware) throws JAXBException,XMLStreamException  {
this.in = in;
this.jc = JAXBContext.newInstance(jaxbPath);
this.unmarshaller =jc.createUnmarshaller();
final XMLInputFactory xmlInputFactory=XMLInputFactory.newFactory();
xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE,namespaceaware);
xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
xmlInputFactory.setXMLResolver(new XMLResolver()
	{
	@Override
	public Object resolveEntity(String publicID,
			String systemID, String baseURI, String namespace)
			throws XMLStreamException {
			LOG.warn("ignoring resolveEntity "+systemID+" "+baseURI+" "+namespace);
				return new ByteArrayInputStream(new byte[0]);
			}
	});
final StreamSource streamSource = new StreamSource(in);
r=xmlInputFactory.createXMLEventReader(streamSource);
}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:23,代码来源:BioAlcidae.java

示例6: testStAX

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
public void testStAX(boolean setUseCatalog, boolean useCatalog, String catalog,
        String xml, XMLResolver resolver, String expected) throws Exception {

        XMLStreamReader streamReader = getStreamReader(
                setUseCatalog, useCatalog, catalog, xml, resolver);
        String text = getText(streamReader, XMLStreamConstants.CHARACTERS);
        Assert.assertEquals(text.trim(), expected);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:CatalogSupportBase.java

示例7: testStAXNegative

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
public void testStAXNegative(boolean setUseCatalog, boolean useCatalog, String catalog,
        String xml, XMLResolver resolver, String expected) throws Exception {

        XMLStreamReader streamReader = getStreamReader(
                setUseCatalog, useCatalog, catalog, xml, resolver);
        String text = getText(streamReader, XMLStreamConstants.ENTITY_REFERENCE);
        Assert.assertEquals(text.trim(), expected);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:CatalogSupportBase.java

示例8: Canonicalizer20010315Test

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
public Canonicalizer20010315Test() throws Exception {
    this.xmlInputFactory = XMLInputFactory.newInstance();
    this.xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
    XMLResolver xmlResolver = new XMLResolver() {
        @Override
        public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) throws XMLStreamException {
            return this.getClass().getClassLoader().getResourceAsStream(
                "org/apache/xml/security/c14n/in/" + systemID);
        }
    };
    this.xmlInputFactory.setXMLResolver(xmlResolver);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:13,代码来源:Canonicalizer20010315Test.java

示例9: Canonicalizer11Test

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
public Canonicalizer11Test() throws Exception {
    this.xmlInputFactory = XMLInputFactory.newInstance();
    this.xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
    XMLResolver xmlResolver = new XMLResolver() {
        @Override
        public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) throws XMLStreamException {
            return this.getClass().getClassLoader().getResourceAsStream(
                "org/apache/xml/security/c14n/in/" + systemID);
        }
    };
    this.xmlInputFactory.setXMLResolver(xmlResolver);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:13,代码来源:Canonicalizer11Test.java

示例10: setProperty

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
public void setProperty(String name, Object value)
  throws IllegalArgumentException
{
  if (name.equals(IS_NAMESPACE_AWARE))
    namespaceAware = ((Boolean) value).booleanValue();
  else if (name.equals(IS_VALIDATING))
    validating = ((Boolean) value).booleanValue();
  else if (name.equals(IS_COALESCING))
    coalescing = ((Boolean) value).booleanValue();
  else if (name.equals(IS_REPLACING_ENTITY_REFERENCES))
    replacingEntityReferences = ((Boolean) value).booleanValue();
  else if (name.equals(IS_SUPPORTING_EXTERNAL_ENTITIES))
    externalEntities = ((Boolean) value).booleanValue();
  else if (name.equals(SUPPORT_DTD))
    supportDTD = ((Boolean) value).booleanValue();
  else if (name.equals(REPORTER))
    reporter = (XMLReporter) value;
  else if (name.equals(RESOLVER))
    resolver = (XMLResolver) value;
  else if (name.equals(ALLOCATOR))
    allocator = (XMLEventAllocator) value;
  else if (name.equals("gnu.xml.stream.stringInterning"))
    stringInterning = ((Boolean) value).booleanValue();
  else if (name.equals("gnu.xml.stream.baseAware"))
    baseAware = ((Boolean) value).booleanValue();
  else if (name.equals("gnu.xml.stream.xIncludeAware"))
    xIncludeAware = ((Boolean) value).booleanValue();
  else
    throw new IllegalArgumentException(name);
}
 
开发者ID:vilie,项目名称:javify,代码行数:31,代码来源:XMLInputFactoryImpl.java

示例11: newXMLInputFactory2

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
@Override
public XMLInputFactory2 newXMLInputFactory2() {
  XMLInputFactory factory = XMLInputFactory.newInstance();
  factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
  factory.setXMLResolver(new XMLResolver() {
    @Override
    public Object resolveEntity(String arg0, String arg1, String arg2,
      String arg3) throws XMLStreamException {
      throw new XMLStreamException("Reading external entities is disabled");
    }
  });
  return new StaxXMLInputFactory2(factory);
}
 
开发者ID:teiid,项目名称:oreva,代码行数:14,代码来源:StaxXMLFactoryProvider2.java

示例12: asXMLResolver

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
public XMLResolver asXMLResolver() {
  return new XMLResolver() {
    @Override
    public Object resolveEntity(String publicId, String systemId, String baseURI, String namespace) throws XMLStreamException {
      try {
        final InputSource src = SystemIdResolver.this.resolveEntity(null, publicId, baseURI, systemId);
        return (src == null) ? null : src.getByteStream();
      } catch (IOException ioe) {
        throw new XMLStreamException("Cannot resolve entity", ioe);
      }
    }
  };
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:SystemIdResolver.java

示例13: StreamScanner

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
/**
 * Constructor used when creating a complete new (main-level) reader that
 * does not share its input buffers or state with another reader.
 */
protected StreamScanner(WstxInputSource input, ReaderConfig cfg,
                        XMLResolver res)
{
    super();
    mInput = input;
    // 17-Jun-2004, TSa: Need to know root-level input source
    mRootInput = input;

    mConfig = cfg;
    mSymbols = cfg.getSymbols();
    int cf = cfg.getConfigFlags();
    mCfgNsEnabled = (cf & CFG_NAMESPACE_AWARE) != 0;
    mCfgReplaceEntities = (cf & CFG_REPLACE_ENTITY_REFS) != 0;

    mNormalizeLFs = mConfig.willNormalizeLFs();
    mInputBuffer = null;
    mInputPtr = mInputEnd = 0;
    mEntityResolver = res;
    
    mCfgTreatCharRefsAsEntities = mConfig.willTreatCharRefsAsEnts();
    if (mCfgTreatCharRefsAsEntities) {
        mCachedEntities = new HashMap<String,IntEntity>();
    } else {
        mCachedEntities = Collections.emptyMap();
    }
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:31,代码来源:StreamScanner.java

示例14: expand

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
@Override
public WstxInputSource expand(WstxInputSource parent,
                              XMLResolver res, ReaderConfig cfg,
                              int xmlVersion)
{
    /* 26-Dec-2006, TSa: Better leave source as null, since internal
     *   entity declaration context should never be used: when expanding,
     *   reference context is to be used.
     */
    return InputSourceFactory.constructCharArraySource
        //(parent, mName, mRepl, 0, mRepl.length, mContentLocation, getSource());
        (parent, mName, mRepl, 0, mRepl.length, mContentLocation, null);
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:14,代码来源:IntEntity.java

示例15: expand

import javax.xml.stream.XMLResolver; //导入依赖的package包/类
@Override
public WstxInputSource expand(WstxInputSource parent,
                              XMLResolver res, ReaderConfig cfg,
                              int xmlVersion)
    throws IOException, XMLStreamException
{
    /* 05-Feb-2006, TSa: If xmlVersion not explicitly known, it defaults
     *    to 1.0
     */
    if (xmlVersion == XmlConsts.XML_V_UNKNOWN) {
        xmlVersion = XmlConsts.XML_V_10;
    }
    return DefaultInputResolver.resolveEntity
        (parent, mContext, mName, getPublicId(), getSystemId(), res, cfg, xmlVersion);
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:16,代码来源:ParsedExtEntity.java


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