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


Java InputSource.setPublicId方法代码示例

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


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

示例1: sourceToInputSource

import org.xml.sax.InputSource; //导入方法依赖的package包/类
/**
 * Attempt to obtain a SAX InputSource object from a Source
 * object.
 *
 * @param source Must be a non-null Source reference.
 *
 * @return An InputSource, or null if Source can not be converted.
 */
public static InputSource sourceToInputSource(Source source) {

    if (source instanceof SAXSource) {
        return ((SAXSource) source).getInputSource();
    } else if (source instanceof StreamSource) {
        StreamSource ss      = (StreamSource) source;
        InputSource  isource = new InputSource(ss.getSystemId());

        isource.setByteStream(ss.getInputStream());
        isource.setCharacterStream(ss.getReader());
        isource.setPublicId(ss.getPublicId());

        return isource;
    } else {
        return null;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:SAXSource.java

示例2: resolveEntity

import org.xml.sax.InputSource; //导入方法依赖的package包/类
@Override
public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException {
    if (ConfigurationConstants.CONFIG_SCHEMA.equals(systemId)) {
        InputStream stream = ConfigurationManager.class.getResourceAsStream(ConfigurationConstants.CONFIG_SCHEMA_LOCATION);
        if (stream != null) {
            InputSource source = new InputSource(stream);
            source.setPublicId(publicId);
            source.setSystemId(systemId);

            return source;
        } else {
            throw new SAXException("Cannot find schema " + ConfigurationConstants.CONFIG_SCHEMA);
        }
    }

    return super.resolveEntity(publicId, systemId);
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:18,代码来源:DefaultConfigurationManager.java

示例3: resolveEntity

import org.xml.sax.InputSource; //导入方法依赖的package包/类
/**
 * <p>Resolves an external entity. If the entity cannot be
 * resolved, this method should return <code>null</code>. This
 * method returns an input source if an entry was found in the
 * catalog for the given external identifier. It should be
 * overrided if other behaviour is required.</p>
 *
 * @param publicId the public identifier, or <code>null</code> if none was supplied
 * @param systemId the system identifier
 *
 * @throws SAXException any SAX exception, possibly wrapping another exception
 * @throws IOException thrown if some i/o error occurs
 */
public InputSource resolveEntity(String publicId, String systemId)
     throws SAXException, IOException {

    String resolvedId = null;
    if (publicId != null && systemId != null) {
        resolvedId = resolvePublic(publicId, systemId);
    }
    else if (systemId != null) {
        resolvedId = resolveSystem(systemId);
    }

    if (resolvedId != null) {
        InputSource source = new InputSource(resolvedId);
        source.setPublicId(publicId);
        return source;
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:XMLCatalogResolver.java

示例4: resolvePublicId

import org.xml.sax.InputSource; //导入方法依赖的package包/类
protected InputSource resolvePublicId(String publicId) {

        // public id -> system id
        if (publicId != null) {
            String value = getPublicMapping(publicId);
            if (value != null) {                
                InputSource input = new InputSource(value);
                input.setPublicId(publicId);
                return input;
            }
        }
        
        return null;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:AbstractCatalog.java

示例5: resolveEntity

import org.xml.sax.InputSource; //导入方法依赖的package包/类
/** Tries to find the entity on system file system.
 */
public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException {
    if (publicID == null) {
        return null;
    }


    String id = convertPublicId (publicID);
    
    StringBuffer sb = new StringBuffer (200);
    sb.append (ENTITY_PREFIX);
    sb.append (id);
    
    FileObject fo = FileUtil.getConfigFile (sb.toString ());
    if (fo != null) {
        
        // fill in InputSource instance
        
        InputSource in = new InputSource (fo.getInputStream ());
        try {
            Object myPublicID = fo.getAttribute("hint.originalPublicID");  //NOI18N
            if (myPublicID instanceof String) {
                in.setPublicId((String)myPublicID);
            }                
            URL url = fo.getURL();
            in.setSystemId(url.toString());  // we get nasty nbfs: instead nbres: but it is enough                
        } catch (IOException ex) {
            // do no care just no system id
        }
        return in;
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:FileEntityResolver.java

示例6: resolveEntity

import org.xml.sax.InputSource; //导入方法依赖的package包/类
@Override
public InputSource resolveEntity(String publicId, String systemId) throws IOException {
	if (logger.isTraceEnabled()) {
		logger.trace("Trying to resolve XML entity with public id [" + publicId +
				"] and system id [" + systemId + "]");
	}

	if (systemId != null) {
		String resourceLocation = getSchemaMappings().get(systemId);
		if (resourceLocation != null) {
			Resource resource = new ClassPathResource(resourceLocation, this.classLoader);
			try {
				InputSource source = new InputSource(resource.getInputStream());
				source.setPublicId(publicId);
				source.setSystemId(systemId);
				if (logger.isDebugEnabled()) {
					logger.debug("Found XML schema [" + systemId + "] in classpath: " + resourceLocation);
				}
				return source;
			}
			catch (FileNotFoundException ex) {
				if (logger.isDebugEnabled()) {
					logger.debug("Couldn't find XML schema [" + systemId + "]: " + resource, ex);
				}
			}
		}
	}
	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:PluggableSchemaResolver.java

示例7: resolveEntity

import org.xml.sax.InputSource; //导入方法依赖的package包/类
@Override
public InputSource resolveEntity(String publicId, String systemId) throws IOException {
	if (logger.isTraceEnabled()) {
		logger.trace("Trying to resolve XML entity with public ID [" + publicId +
				"] and system ID [" + systemId + "]");
	}
	if (systemId != null && systemId.endsWith(DTD_EXTENSION)) {
		int lastPathSeparator = systemId.lastIndexOf("/");
		for (String DTD_NAME : DTD_NAMES) {
			int dtdNameStart = systemId.indexOf(DTD_NAME);
			if (dtdNameStart > lastPathSeparator) {
				String dtdFile = systemId.substring(dtdNameStart);
				if (logger.isTraceEnabled()) {
					logger.trace("Trying to locate [" + dtdFile + "] in Spring jar");
				}
				try {
					Resource resource = new ClassPathResource(dtdFile, getClass());
					InputSource source = new InputSource(resource.getInputStream());
					source.setPublicId(publicId);
					source.setSystemId(systemId);
					if (logger.isDebugEnabled()) {
						logger.debug("Found beans DTD [" + systemId + "] in classpath: " + dtdFile);
					}
					return source;
				}
				catch (IOException ex) {
					if (logger.isDebugEnabled()) {
						logger.debug("Could not resolve beans DTD [" + systemId + "]: not found in class path", ex);
					}
				}

			}
		}
	}

	// Use the default behavior -> download from website or wherever.
	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:BeansDtdResolver.java

示例8: buildInputSource

import org.xml.sax.InputSource; //导入方法依赖的package包/类
private InputSource buildInputSource(String publicId, String systemId, InputStream dtdStream, boolean resolved) {
	if ( dtdStream == null ) {
		LOG.tracev( "Unable to locate [{0}] on classpath", systemId );
		return null;
	}
	LOG.tracev( "Located [{0}] in classpath", systemId );
	InputSource source = new InputSource( dtdStream );
	source.setPublicId( publicId );
	source.setSystemId( systemId );
	this.resolved = resolved;
	return source;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:EJB3DTDEntityResolver.java

示例9: resolveEntity

import org.xml.sax.InputSource; //导入方法依赖的package包/类
/**
 * Resolves the given resource and adapts the <code>LSInput</code>
 * returned into an <code>InputSource</code>.
 */
public InputSource resolveEntity(String name, String publicId,
        String baseURI, String systemId) throws SAXException, IOException {
    if (fEntityResolver != null) {
        LSInput lsInput = fEntityResolver.resolveResource(XML_TYPE, null, publicId, systemId, baseURI);
        if (lsInput != null) {
            final String pubId = lsInput.getPublicId();
            final String sysId = lsInput.getSystemId();
            final String baseSystemId = lsInput.getBaseURI();
            final Reader charStream = lsInput.getCharacterStream();
            final InputStream byteStream = lsInput.getByteStream();
            final String data = lsInput.getStringData();
            final String encoding = lsInput.getEncoding();

            /**
             * An LSParser looks at inputs specified in LSInput in
             * the following order: characterStream, byteStream,
             * stringData, systemId, publicId. For consistency
             * with the DOM Level 3 Load and Save Recommendation
             * use the same lookup order here.
             */
            InputSource inputSource = new InputSource();
            inputSource.setPublicId(pubId);
            inputSource.setSystemId((baseSystemId != null) ? resolveSystemId(systemId, baseSystemId) : systemId);

            if (charStream != null) {
                inputSource.setCharacterStream(charStream);
            }
            else if (byteStream != null) {
                inputSource.setByteStream(byteStream);
            }
            else if (data != null && data.length() != 0) {
                inputSource.setCharacterStream(new StringReader(data));
            }
            inputSource.setEncoding(encoding);
            return inputSource;
        }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:44,代码来源:ValidatorHandlerImpl.java

示例10: resolveEntity

import org.xml.sax.InputSource; //导入方法依赖的package包/类
/** SAX resolveEntity API. */
public InputSource resolveEntity (String publicId, String systemId) {
  String resolved = null;

  if (systemId != null && systemMap.containsKey(systemId)) {
    resolved = (String) systemMap.get(systemId);
  } else if (publicId != null && publicMap.containsKey(publicId)) {
    resolved = (String) publicMap.get(publicId);
  }

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      // FIXME: silently fail?
      return null;
    }
  }

  return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:40,代码来源:BootstrapResolver.java

示例11: resolveEntity

import org.xml.sax.InputSource; //导入方法依赖的package包/类
/**
 * Implements the <code>resolveEntity</code> method
 * for the SAX interface, using an underlying CatalogResolver
 * to do the real work.
 */
public InputSource resolveEntity (String publicId, String systemId) {
  allowXMLCatalogPI = false;
  String resolved = catalogResolver.getResolvedEntity(publicId, systemId);

  if (resolved == null && piCatalogResolver != null) {
    resolved = piCatalogResolver.getResolvedEntity(publicId, systemId);
  }

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      catalogManager.debug.message(1, "Failed to create InputSource", resolved);
      return null;
    }
  } else {
    return null;
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:43,代码来源:ResolvingXMLFilter.java

示例12: resolveEntity

import org.xml.sax.InputSource; //导入方法依赖的package包/类
/**
 * Implements the <code>resolveEntity</code> method
 * for the SAX interface.
 *
 * <p>Presented with an optional public identifier and a system
 * identifier, this function attempts to locate a mapping in the
 * catalogs.</p>
 *
 * <p>If such a mapping is found, the resolver attempts to open
 * the mapped value as an InputSource and return it. Exceptions are
 * ignored and null is returned if the mapped value cannot be opened
 * as an input source.</p>
 *
 * <p>If no mapping is found (or an error occurs attempting to open
 * the mapped value as an input source), null is returned and the system
 * will use the specified system identifier as if no entityResolver
 * was specified.</p>
 *
 * @param publicId  The public identifier for the entity in question.
 * This may be null.
 *
 * @param systemId  The system identifier for the entity in question.
 * XML requires a system identifier on all external entities, so this
 * value is always specified.
 *
 * @return An InputSource for the mapped identifier, or null.
 */
public InputSource resolveEntity (String publicId, String systemId) {
  String resolved = getResolvedEntity(publicId, systemId);

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      catalogManager.debug.message(1, "Failed to create InputSource", resolved);
      return null;
    }
  }

  return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:60,代码来源:CatalogResolver.java

示例13: getClassPathInputSource

import org.xml.sax.InputSource; //导入方法依赖的package包/类
/**
 * Get {@link InputSource} for path in class path.
 * 
 * @param path to resource to get {@link InputSource} for.
 * @return InputSource if resource found, otherwise null.
 * @since GemFire 8.1
 */
protected final InputSource getClassPathInputSource(final String publicId, final String systemId,
    final String path) {
  final InputStream stream = ClassPathLoader.getLatest().getResourceAsStream(getClass(), path);
  if (null == stream) {
    return null;
  }

  final InputSource inputSource = new InputSource(stream);
  inputSource.setPublicId(publicId);
  inputSource.setSystemId(systemId);

  return inputSource;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:21,代码来源:DefaultEntityResolver2.java

示例14: resolveEntity

import org.xml.sax.InputSource; //导入方法依赖的package包/类
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
{
    log.debug("resolveEntity(publicId=" + publicId + ", systemId=" + systemId + ") returning null");

    InputSource is = new InputSource(new StringReader(""));
    is.setPublicId(publicId);
    is.setSystemId(systemId);

    return is;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:11,代码来源:EmptyEntityResolver.java

示例15: toInputSource

import org.xml.sax.InputSource; //导入方法依赖的package包/类
private static InputSource toInputSource(StreamSource src) {
    InputSource is = new InputSource();
    is.setByteStream(src.getInputStream());
    is.setCharacterStream(src.getReader());
    is.setPublicId(src.getPublicId());
    is.setSystemId(src.getSystemId());
    return is;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:XmlUtil.java


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