當前位置: 首頁>>代碼示例>>Java>>正文


Java SAXReader.setEntityResolver方法代碼示例

本文整理匯總了Java中org.dom4j.io.SAXReader.setEntityResolver方法的典型用法代碼示例。如果您正苦於以下問題:Java SAXReader.setEntityResolver方法的具體用法?Java SAXReader.setEntityResolver怎麽用?Java SAXReader.setEntityResolver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.dom4j.io.SAXReader的用法示例。


在下文中一共展示了SAXReader.setEntityResolver方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadXmlFile

import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
private XmlNode loadXmlFile( String agent, String filePath ) {

        // load the file as a String
        String fileContent = loadFileContent(agent, filePath);

        try {
            SAXReader reader = new SAXReader();

            // following code prevents dom4j from running DTD XML validation
            reader.setEntityResolver(new EntityResolver() {

                @Override
                public InputSource resolveEntity( String publicId, String systemId ) throws SAXException,
                                                                                     IOException {

                    return new InputSource(new StringReader(""));
                }
            });

            // load XML document
            Document xmlDocument = reader.read(new StringReader(fileContent));
            return new XmlNode(null, xmlDocument.getRootElement());
        } catch (XMLException | DocumentException e) {
            throw new XMLException("Error parsing XML file: " + filePath, e);
        }
    }
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:27,代碼來源:XmlFileSnapshot.java

示例2: legacyReadMappingDocument

import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
private XmlDocument legacyReadMappingDocument(EntityResolver entityResolver, InputSource source, Origin origin) {
	// IMPL NOTE : this is the legacy logic as pulled from the old AnnotationConfiguration code

	Exception failure;

	ErrorLogger errorHandler = new ErrorLogger();

	SAXReader saxReader = new SAXReader();
	saxReader.setEntityResolver( entityResolver );
	saxReader.setErrorHandler( errorHandler );
	saxReader.setMergeAdjacentText( true );
	saxReader.setValidation( true );

	Document document = null;
	try {
		// first try with orm 2.1 xsd validation
		setValidationFor( saxReader, "orm_2_1.xsd" );
		document = saxReader.read( source );
		if ( errorHandler.hasErrors() ) {
			throw errorHandler.getErrors().get( 0 );
		}
		return new XmlDocumentImpl( document, origin.getType(), origin.getName() );
	}
	catch ( Exception e ) {
		if ( LOG.isDebugEnabled() ) {
			LOG.debugf( "Problem parsing XML using orm 2.1 xsd, trying 2.0 xsd : %s", e.getMessage() );
		}
		failure = e;
		errorHandler.reset();

		if ( document != null ) {
			// next try with orm 2.0 xsd validation
			try {
				setValidationFor( saxReader, "orm_2_0.xsd" );
				document = saxReader.read( new StringReader( document.asXML() ) );
				if ( errorHandler.hasErrors() ) {
					errorHandler.logErrors();
					throw errorHandler.getErrors().get( 0 );
				}
				return new XmlDocumentImpl( document, origin.getType(), origin.getName() );
			}
			catch ( Exception e2 ) {
				if ( LOG.isDebugEnabled() ) {
					LOG.debugf( "Problem parsing XML using orm 2.0 xsd, trying 1.0 xsd : %s", e2.getMessage() );
				}
				errorHandler.reset();

				if ( document != null ) {
					// next try with orm 1.0 xsd validation
					try {
						setValidationFor( saxReader, "orm_1_0.xsd" );
						document = saxReader.read( new StringReader( document.asXML() ) );
						if ( errorHandler.hasErrors() ) {
							errorHandler.logErrors();
							throw errorHandler.getErrors().get( 0 );
						}
						return new XmlDocumentImpl( document, origin.getType(), origin.getName() );
					}
					catch ( Exception e3 ) {
						if ( LOG.isDebugEnabled() ) {
							LOG.debugf( "Problem parsing XML using orm 1.0 xsd : %s", e3.getMessage() );
						}
					}
				}
			}
		}
	}
	throw new InvalidMappingException( "Unable to read XML", origin.getType(), origin.getName(), failure );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:70,代碼來源:MappingReader.java

示例3: CreateBaseModelFromXml

import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
public CreateBaseModelFromXml() throws DocumentException {
	iSAXReader = new SAXReader();
	iSAXReader.setEntityResolver(iEntityResolver);
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:5,代碼來源:CreateBaseModelFromXml.java

示例4: LowercaseTableNames

import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
public LowercaseTableNames() throws DocumentException, SAXException {
	iSAXReader = new SAXReader();
	iSAXReader.setEntityResolver(iEntityResolver);
	iSAXReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:6,代碼來源:LowercaseTableNames.java

示例5: afterPropertiesSet

import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
@Override
public void afterPropertiesSet() throws Exception {
	try {
		String menu = ApplicationProperty.MenuFile.value();
		Document document = null;
        URL menuUrl = ApplicationProperties.class.getClassLoader().getResource(menu);
        SAXReader sax = new SAXReader();
        sax.setEntityResolver(new EntityResolver() {
        	public InputSource resolveEntity(String publicId, String systemId) {
        		if (publicId.equals("-//UniTime//UniTime Menu DTD/EN")) {
        			return new InputSource(ApplicationProperties.class.getClassLoader().getResourceAsStream("menu.dtd"));
        		}
        		return null;
        	}
        });
        if (menuUrl!=null) {
            sLog.info("Reading menu from " + URLDecoder.decode(menuUrl.getPath(), "UTF-8") + " ...");
            document = sax.read(menuUrl.openStream());
        } else if (new File(menu).exists()) {
            sLog.info("Reading menu from " + menu + " ...");
            document = sax.read(new File(menu));
        }
        if (document==null)
            throw new ServletException("Unable to create menu, reason: resource " + menu + " not found.");

        if (!"unitime-menu".equals(document.getRootElement().getName())) throw new ServletException("Menu has an unknown format.");
        iRoot = document.getRootElement();
        
        String customMenu = ApplicationProperty.CustomMenuFile.value();
		Document customDocument = null;
        URL customMenuUrl = ApplicationProperties.class.getClassLoader().getResource(customMenu);
        if (customMenuUrl!=null) {
        	sLog.info("Reading custom menu from " + URLDecoder.decode(customMenuUrl.getPath(), "UTF-8") + " ...");
            customDocument = sax.read(customMenuUrl.openStream());
        } else if (new File(customMenu).exists()) {
        	sLog.info("Reading custom menu from " + customMenu + " ...");
            customDocument = sax.read(new File(customMenu));
        }
        if (customDocument != null) {
        	merge(iRoot, customDocument.getRootElement());
        }
        
	} catch (Exception e) {
		if (e instanceof RuntimeException) throw (RuntimeException)e;
		throw new RuntimeException("Unable to initialize, reason: "+e.getMessage(), e);
	}
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:48,代碼來源:MenuBackend.java

示例6: createSAXReader

import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
/**
 * @param errorHandler the sax error handler
 * @param entityResolver an xml entity resolver
 *
 * @return Create and return a dom4j {@code SAXReader} which will append all validation errors
 *         to the passed error list
 */
public SAXReader createSAXReader(ErrorHandler errorHandler, EntityResolver entityResolver) {
	SAXReader saxReader = resolveSAXReader();
	saxReader.setEntityResolver( entityResolver );
	saxReader.setErrorHandler( errorHandler );
	return saxReader;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:XMLHelper.java


注:本文中的org.dom4j.io.SAXReader.setEntityResolver方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。