本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
};
}
示例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();
}
}
示例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);
}
示例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);
}