类javax.xml.stream.XMLResolver源码实例Demo

下面列出了怎么用javax.xml.stream.XMLResolver的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: openjdk-jdk9   文件: CatalogSupportBase.java
/**
 * 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 项目: openjdk-jdk9   文件: CatalogSupportBase.java
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);
}
 
源代码3 项目: openjdk-jdk9   文件: CatalogSupportBase.java
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);
}
 
源代码4 项目: lucene-solr   文件: SystemIdResolver.java
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);
      }
    }
  };
}
 
源代码5 项目: woodstox   文件: StreamScanner.java
/**
 * 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;

    mAllowXml11EscapedCharsInXml10 = mConfig.willAllowXml11EscapedCharsInXml10();

    mNormalizeLFs = mConfig.willNormalizeLFs();
    mInputBuffer = null;
    mInputPtr = mInputEnd = 0;
    mEntityResolver = res;
    
    mCfgTreatCharRefsAsEntities = mConfig.willTreatCharRefsAsEnts();
    if (mCfgTreatCharRefsAsEntities) {
        mCachedEntities = new HashMap<String,IntEntity>();
    } else {
        mCachedEntities = Collections.emptyMap();
    }
}
 
源代码6 项目: woodstox   文件: IntEntity.java
@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);
}
 
源代码7 项目: woodstox   文件: ParsedExtEntity.java
@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);
}
 
源代码8 项目: woodstox   文件: UnparsedExtEntity.java
@Override
public WstxInputSource expand(WstxInputSource parent,
        XMLResolver res, ReaderConfig cfg, int xmlVersion)
{
    // Should never get called, actually...
    throw new IllegalStateException("Internal error: createInputSource() called for unparsed (external) entity.");
}
 
源代码9 项目: woodstox   文件: DefaultInputResolver.java
/**
 * Basic external resource resolver implementation; usable both with
 * DTD and entity resolution.
 *
 * @param parent Input source that contains reference to be expanded.
 * @param pathCtxt Reference context to use for resolving path, if
 *   known. If null, reference context of the parent will
 *   be used; and if that is null (which is possible), the
 *   current working directory will be assumed.
 * @param entityName Name/id of the entity being expanded, if this is an
 *   entity expansion; null otherwise (for example, when resolving external
 *   subset).
 * @param publicId Public identifier of the resource, if known; null/empty
 *   otherwise. Default implementation just ignores the identifier.
 * @param systemId System identifier of the resource. Although interface
 *   allows null/empty, default implementation considers this an error.
 * @param xmlVersion Xml version as declared by the main parsed
 *   document. Currently only relevant for checking that XML 1.0 document
 *   does not include XML 1.1 external parsed entities.
 *   If XML_V_UNKNOWN, no checks will be done.
 * @param customResolver Custom resolver to use first for resolution,
 *   if any (may be null).
 * @param cfg Reader configuration object used by the parser that is
 *   resolving the entity
 *
 * @return Input source, if entity could be resolved; null if it could
 *   not be resolved. In latter case processor may use its own default
 *   resolution mechanism.
 */
public static WstxInputSource resolveEntity
    (WstxInputSource parent, URL pathCtxt, String entityName,
     String publicId, String systemId,
     XMLResolver customResolver, ReaderConfig cfg, int xmlVersion)
    throws IOException, XMLStreamException
{
    if (pathCtxt == null) {
        pathCtxt = parent.getSource();
        if (pathCtxt == null) {
            pathCtxt = URLUtil.urlFromCurrentDir();
        }
    }

    // Do we have a custom resolver that may be able to resolve it?
    if (customResolver != null) {
        Object source = customResolver.resolveEntity(publicId, systemId, pathCtxt.toExternalForm(), entityName);
        if (source != null) {
            return sourceFrom(parent, cfg, entityName, xmlVersion, source);
        }
    }
        
    // Have to have a system id, then...
    if (systemId == null) {
        throw new XMLStreamException("Can not resolve "
                                     +((entityName == null) ? "[External DTD subset]" : ("entity '"+entityName+"'"))+" without a system id (public id '"
                                     +publicId+"')");
    }
    URL url = URLUtil.urlFromSystemId(systemId, pathCtxt);
    return sourceFromURL(parent, cfg, entityName, xmlVersion, url, publicId);
}
 
源代码10 项目: woodstox   文件: DefaultInputResolver.java
/**
 * A very simple utility expansion method used generally when the
 * only way to resolve an entity is via passed resolver; and where
 * failing to resolve it is not fatal.
 */
public static WstxInputSource resolveEntityUsing
    (WstxInputSource refCtxt, String entityName,
     String publicId, String systemId,
     XMLResolver resolver, ReaderConfig cfg, int xmlVersion)
    throws IOException, XMLStreamException
{
    URL ctxt = (refCtxt == null) ? null : refCtxt.getSource();
    if (ctxt == null) {
        ctxt = URLUtil.urlFromCurrentDir();
    }
    Object source = resolver.resolveEntity(publicId, systemId, ctxt.toExternalForm(), entityName);
    return (source == null) ? null : sourceFrom(refCtxt, cfg, entityName, xmlVersion, source);
}
 
源代码11 项目: TencentKona-8   文件: StaxEntityResolverWrapper.java
/** Creates a new instance of StaxEntityResolverWrapper */
public StaxEntityResolverWrapper(XMLResolver resolver) {
    fStaxResolver = resolver ;
}
 
源代码12 项目: TencentKona-8   文件: StaxEntityResolverWrapper.java
public void setStaxEntityResolver(XMLResolver resolver ){
    fStaxResolver = resolver ;
}
 
源代码13 项目: TencentKona-8   文件: StaxEntityResolverWrapper.java
public XMLResolver getStaxEntityResolver(){
    return fStaxResolver ;
}
 
源代码14 项目: jdk8u60   文件: StaxEntityResolverWrapper.java
/** Creates a new instance of StaxEntityResolverWrapper */
public StaxEntityResolverWrapper(XMLResolver resolver) {
    fStaxResolver = resolver ;
}
 
源代码15 项目: jdk8u60   文件: StaxEntityResolverWrapper.java
public void setStaxEntityResolver(XMLResolver resolver ){
    fStaxResolver = resolver ;
}
 
源代码16 项目: jdk8u60   文件: StaxEntityResolverWrapper.java
public XMLResolver getStaxEntityResolver(){
    return fStaxResolver ;
}
 
源代码17 项目: openjdk-jdk8u   文件: StaxEntityResolverWrapper.java
/** Creates a new instance of StaxEntityResolverWrapper */
public StaxEntityResolverWrapper(XMLResolver resolver) {
    fStaxResolver = resolver ;
}
 
源代码18 项目: openjdk-jdk8u   文件: StaxEntityResolverWrapper.java
public void setStaxEntityResolver(XMLResolver resolver ){
    fStaxResolver = resolver ;
}
 
源代码19 项目: openjdk-jdk8u   文件: StaxEntityResolverWrapper.java
public XMLResolver getStaxEntityResolver(){
    return fStaxResolver ;
}
 
/** Creates a new instance of StaxEntityResolverWrapper */
public StaxEntityResolverWrapper(XMLResolver resolver) {
    fStaxResolver = resolver ;
}
 
public void setStaxEntityResolver(XMLResolver resolver ){
    fStaxResolver = resolver ;
}
 
public XMLResolver getStaxEntityResolver(){
    return fStaxResolver ;
}
 
源代码23 项目: Bytecoder   文件: StaxEntityResolverWrapper.java
/** Creates a new instance of StaxEntityResolverWrapper */
public StaxEntityResolverWrapper(XMLResolver resolver) {
    fStaxResolver = resolver ;
}
 
源代码24 项目: Bytecoder   文件: StaxEntityResolverWrapper.java
public void setStaxEntityResolver(XMLResolver resolver ){
    fStaxResolver = resolver ;
}
 
源代码25 项目: Bytecoder   文件: StaxEntityResolverWrapper.java
public XMLResolver getStaxEntityResolver(){
    return fStaxResolver ;
}
 
源代码26 项目: openjdk-jdk9   文件: StaxEntityResolverWrapper.java
/** Creates a new instance of StaxEntityResolverWrapper */
public StaxEntityResolverWrapper(XMLResolver resolver) {
    fStaxResolver = resolver ;
}
 
源代码27 项目: openjdk-jdk9   文件: StaxEntityResolverWrapper.java
public void setStaxEntityResolver(XMLResolver resolver ){
    fStaxResolver = resolver ;
}
 
源代码28 项目: openjdk-jdk9   文件: StaxEntityResolverWrapper.java
public XMLResolver getStaxEntityResolver(){
    return fStaxResolver ;
}
 
源代码29 项目: openjdk-jdk9   文件: MyInputFactory.java
@Override
public XMLResolver getXMLResolver() {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
源代码30 项目: openjdk-jdk9   文件: MyInputFactory.java
@Override
public void setXMLResolver(XMLResolver resolver) {
    throw new UnsupportedOperationException("Not supported yet.");
}