本文整理了Java中org.xml.sax.EntityResolver.resolveEntity()
方法的一些代码示例,展示了EntityResolver.resolveEntity()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EntityResolver.resolveEntity()
方法的具体详情如下:
包路径:org.xml.sax.EntityResolver
类名称:EntityResolver
方法名:resolveEntity
[英]Allow the application to resolve external entities.
The parser will call this method before opening any external entity except the top-level document entity. Such entities include the external DTD subset and external parameter entities referenced within the DTD (in either case, only if the parser reads external parameter entities), and external general entities referenced within the document element (if the parser reads external general entities). The application may request that the parser locate the entity itself, that it use an alternative URI, or that it use data provided by the application (as a character or byte input stream).
Application writers can use this method to redirect external system identifiers to secure and/or local URIs, to look up public identifiers in a catalogue, or to read an entity from a database or other input source (including, for example, a dialog box). Neither XML nor SAX specifies a preferred policy for using public or system IDs to resolve resources. However, SAX specifies how to interpret any InputSource returned by this method, and that if none is returned, then the system ID will be dereferenced as a URL.
If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to the application.
[中]允许应用程序解析外部实体。
解析器将在打开除顶级文档实体之外的任何外部实体之前调用此方法。这些实体包括DTD中引用的外部DTD子集和外部参数实体(在这两种情况下,仅当解析器读取外部参数实体时),以及文档元素中引用的外部常规实体(如果解析器读取外部常规实体)。应用程序可以请求解析器定位实体本身、使用替代URI或使用应用程序提供的数据(作为字符或字节输入流)。
应用程序编写者可以使用此方法将外部系统标识符重定向到安全和/或本地URI,在目录中查找公共标识符,或从数据库或其他输入源(例如,包括对话框)读取实体。XML和SAX都没有指定使用公共或系统ID解析资源的首选策略。但是,SAX指定如何解释此方法返回的任何InputSource,如果未返回任何InputSource,则系统ID将作为URL取消引用。
如果系统标识符是URL,SAX解析器必须在将其报告给应用程序之前对其进行完全解析。
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public InputSource resolveEntity(String publicId, @Nullable String systemId) throws SAXException, IOException {
if (systemId != null) {
if (systemId.endsWith(DTD_SUFFIX)) {
return this.dtdResolver.resolveEntity(publicId, systemId);
}
else if (systemId.endsWith(XSD_SUFFIX)) {
return this.schemaResolver.resolveEntity(publicId, systemId);
}
}
return null;
}
代码示例来源:origin: geoserver/geoserver
@Override
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
if (delegate != null) {
return delegate.resolveEntity(publicId, systemId);
} else {
return null;
}
}
代码示例来源:origin: robovm/robovm
/**
* Filter an external entity resolution.
*
* @param publicId The entity's public identifier, or null.
* @param systemId The entity's system identifier.
* @return A new InputSource or null for the default.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @exception java.io.IOException The client may throw an
* I/O-related exception while obtaining the
* new InputSource.
*/
public InputSource resolveEntity (String publicId, String systemId)
throws SAXException, IOException
{
if (entityResolver != null) {
return entityResolver.resolveEntity(publicId, systemId);
} else {
return null;
}
}
代码示例来源:origin: org.springframework/spring-beans
@Override
@Nullable
public InputSource resolveEntity(String publicId, @Nullable String systemId) throws SAXException, IOException {
if (systemId != null) {
if (systemId.endsWith(DTD_SUFFIX)) {
return this.dtdResolver.resolveEntity(publicId, systemId);
}
else if (systemId.endsWith(XSD_SUFFIX)) {
return this.schemaResolver.resolveEntity(publicId, systemId);
}
}
return null;
}
代码示例来源:origin: robovm/robovm
/**
* Filter an external entity resolution.
*
* @param publicId The entity's public identifier, or null.
* @param systemId The entity's system identifier.
* @return A new InputSource or null for the default.
*
* @throws IOException
* @throws SAXException The client may throw
* an exception during processing.
* @throws java.io.IOException The client may throw an
* I/O-related exception while obtaining the
* new InputSource.
* @see org.xml.sax.EntityResolver#resolveEntity
*/
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException
{
if (m_entityResolver != null)
{
return m_entityResolver.resolveEntity(publicId, systemId);
}
else
{
return null;
}
}
代码示例来源:origin: xalan/xalan
/**
* Filter an external entity resolution.
*
* @param publicId The entity's public identifier, or null.
* @param systemId The entity's system identifier.
* @return A new InputSource or null for the default.
*
* @throws IOException
* @throws SAXException The client may throw
* an exception during processing.
* @throws java.io.IOException The client may throw an
* I/O-related exception while obtaining the
* new InputSource.
* @see org.xml.sax.EntityResolver#resolveEntity
*/
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException
{
if (m_entityResolver != null)
{
return m_entityResolver.resolveEntity(publicId, systemId);
}
else
{
return null;
}
}
代码示例来源:origin: geoserver/geoserver
@Override
public InputSource resolveEntity(String publicId, String systemId)
throws IOException, SAXException {
if (entityResolver != null) {
return this.entityResolver.resolveEntity(publicId, systemId);
} else {
return super.resolveEntity(publicId, systemId);
}
}
}
代码示例来源:origin: geoserver/geoserver
@Override
public LSInput resolveResource(
String type, String namespaceURI, String publicId, String systemId, String baseURI) {
// give the entity resolver an opportunity (mostly to throw an exception)
try {
InputSource is = entityResolver.resolveEntity(publicId, systemId);
if (is != null) {
return new InputSourceToLSResource(is);
}
} catch (SAXException | IOException e) {
throw new RuntimeException(e);
}
// otherwise fall back on the default resolution path
return delegate.resolveResource(type, namespaceURI, publicId, systemId, baseURI);
}
}
代码示例来源:origin: robovm/robovm
InputSource inputSource = entityResolver.resolveEntity(
publicId, systemId);
if (inputSource == null) {
代码示例来源:origin: apache/geode
/**
* Test {@link PivotalEntityResolver#resolveEntity(String, String)} with <code>null</code>
* <code>systemId</code>. Asserts that returns to <code>null<code>.
*
* @since GemFire 8.1
*/
@Test
public void testResolveEntityNullSystemId() throws SAXException, Exception {
final String systemId = null;
final InputSource inputSource = getEntityResolver().resolveEntity(null, systemId);
assertNull(inputSource);
}
代码示例来源:origin: apache/geode
/**
* Test {@link PivotalEntityResolver#resolveEntity(String, String)} with
* <code>"--not-a-valid-system-id--"</code> <code>systemId</code>, which is not in the Pivotal
* namespace.. Asserts that returns to <code>null<code>.
*
* @since GemFire 8.1
*/
@Test
public void testResolveEntityUnkownSystemId() throws Exception {
final String systemId = "--not-a-valid-system-id--";
final InputSource inputSource = getEntityResolver().resolveEntity(null, systemId);
assertNull(inputSource);
}
代码示例来源:origin: apache/geode
/**
* Test {@link PivotalEntityResolver#resolveEntity(String, String)} with
* <code>"http://schema.pivotal.io/this/should/be/not/found.xsd"</code> <code>systemId</code>,
* which should not be found. Asserts that returns to <code>null<code>.
*
* @since GemFire 8.1
*/
@Test
public void testResolveEntityNotFoundSystemId() throws Exception {
final String systemId = "http://schema.pivotal.io/this/should/be/not/found.xsd";
final InputSource inputSource = getEntityResolver().resolveEntity(null, systemId);
assertNull(inputSource);
}
代码示例来源:origin: apache/geode
/**
* Resolve the cache.xml XSD using the {@link PivotalEntityResolver}. Verifies that the
* META-INF/schemas files are correctly found.
*
* @since GemFire 8.1
*/
@Test
public void testResolveEntity() throws Exception {
final InputSource inputSource = getEntityResolver().resolveEntity(null, getSystemId());
assertNotNull(inputSource);
assertEquals(getSystemId(), inputSource.getSystemId());
}
代码示例来源:origin: camunda/camunda-bpm-platform
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
if (systemId != null) {
if (systemId.endsWith(DTD_SUFFIX)) {
return this.dtdResolver.resolveEntity(publicId, systemId);
}
else if (systemId.endsWith(XSD_SUFFIX)) {
return this.schemaResolver.resolveEntity(publicId, systemId);
}
}
return null;
}
代码示例来源:origin: mulesoft/mule
protected boolean canResolveEntity(String publicId, String systemId) throws SAXException, IOException {
final InputSource resolvedEntity = muleEntityResolver.resolveEntity(publicId, systemId);
try {
return resolvedEntity != null;
} finally {
if (resolvedEntity != null) {
if (resolvedEntity.getByteStream() != null) {
resolvedEntity.getByteStream().close();
}
if (resolvedEntity.getCharacterStream() != null) {
resolvedEntity.getCharacterStream().close();
}
}
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
@Override
public InputSource resolveEntity(String publicId, String systemId)
throws IOException, SAXException {
if (entityResolver!=null) {
return entityResolver.resolveEntity(publicId, systemId);
}
return super.resolveEntity(publicId, systemId);
}
代码示例来源:origin: webx/citrus
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
log.trace("Trying to locate XML entity {} as configuration points schema.", systemId);
Schema schema = schemas.findSchema(systemId);
if (schema == null) {
if (defaultEntityResolver != null) {
return defaultEntityResolver.resolveEntity(publicId, systemId);
} else {
return null;
}
}
log.debug("Found XML schema for systemId {}: {}", systemId, schema);
InputSource inputSource = new InputSource(schema.getInputStream());
inputSource.setPublicId(publicId);
inputSource.setSystemId(systemId);
return inputSource;
}
}
代码示例来源:origin: webx/citrus
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
log.trace("Trying to locate XML entity {} as configuration points schema.", systemId);
Schema schema = schemas.findSchema(systemId);
if (schema == null) {
if (defaultEntityResolver != null) {
return defaultEntityResolver.resolveEntity(publicId, systemId);
} else {
return null;
}
}
log.debug("Found XML schema for systemId {}: {}", systemId, schema);
InputSource inputSource = new InputSource(schema.getInputStream());
inputSource.setPublicId(publicId);
inputSource.setSystemId(systemId);
return inputSource;
}
}
代码示例来源:origin: webx/citrus
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
log.trace("Trying to locate XML entity {} as configuration points schema.", systemId);
Schema schema = schemas.findSchema(systemId);
if (schema == null) {
if (defaultEntityResolver != null) {
return defaultEntityResolver.resolveEntity(publicId, systemId);
} else {
return null;
}
}
log.debug("Found XML schema for systemId {}: {}", systemId, schema);
InputSource inputSource = new InputSource(schema.getInputStream());
inputSource.setPublicId(publicId);
inputSource.setSystemId(systemId);
return inputSource;
}
}
代码示例来源:origin: org.dom4j/dom4j
protected void entityResolver(Document document) throws SAXException {
if (entityResolver != null) {
DocumentType docType = document.getDocType();
if (docType != null) {
String publicID = docType.getPublicID();
String systemID = docType.getSystemID();
if ((publicID != null) || (systemID != null)) {
try {
entityResolver.resolveEntity(publicID, systemID);
} catch (IOException e) {
throw new SAXException("Could not resolve publicID: "
+ publicID + " systemID: " + systemID, e);
}
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!