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


Java XMLReaders.NONVALIDATING属性代码示例

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


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

示例1: merge

/**
 * Merges a given XML file with a patch. This API is designed for CobiGen
 * @see com.github.maybeec.lexeme.LeXeMerger#merge(Element, Element, ConflictHandlingType)
 * @param base
 *            File
 * @param patch
 *            String
 * @param charSet
 *            target charset of the file to be read and write
 * @param conflictHandling
 *            {@link ConflictHandlingType} specifying how conflicts will be handled during the merge
 *            process. If null the default for this LeXeMerger will be used
 * @return Document the merged result of base and patch
 * @throws XMLMergeException
 *             when the Documents can't be properly merged
 * @author sholzer (23.04.2015)
 */
public Document merge(File base, String patch, String charSet, ConflictHandlingType conflictHandling)
    throws XMLMergeException {
    if (conflictHandling == null) {
        conflictHandling = conflictHandlingType;
    }
    try {
        SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);
        builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        String baseString = JDom2Util.getInstance().readFile(base.getPath(), charSet);
        Document baseDoc =
            builder.build(new InputSource(new BufferedReader(new StringReader(baseString))));
        Document patchDoc = builder.build(new InputSource(new BufferedReader(new StringReader(patch))));
        return merge(baseDoc, patchDoc, conflictHandling);
    } catch (IOException | JDOMException e) {
        logger.error("Caught unexcpected {}:{}", e.getClass().getName(), e.getMessage());
        throw new XMLMergeException(e.getMessage());
    }

}
 
开发者ID:maybeec,项目名称:lexeme,代码行数:36,代码来源:LeXeMerger.java

示例2: parseXHTMLDocument

public static Document parseXHTMLDocument(String xhtml, JDOMFactory factory) throws IOException, JDOMException
{
    //DTD ersetzen, da die originale nicht erreichbar bzw. nur sehr langsam ist,
    xhtml = xhtml.replace("http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd", "http://localhost:8777/dtd/www.w3.org/TR/xhtml11/DTD/xhtml11.dtd");
    ByteArrayInputStream bais = new ByteArrayInputStream(xhtml.getBytes("UTF-8"));
    SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);
    builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
    builder.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
    builder.setFeature("http://xml.org/sax/features/resolve-dtd-uris", false);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    builder.setExpandEntities(false);
    if (factory != null)
    {
        builder.setJDOMFactory(factory);
    }
    Document document = builder.build(bais);
    return document;
}
 
开发者ID:finanzer,项目名称:epubfx,代码行数:18,代码来源:XHTMLUtils.java

示例3: parseVisualTree

private VisualTreeNode parseVisualTree(ComponentContainer parent, Reader inputStream, Object eventHandlerTarget) throws ParserException {

		SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);

		try {
			Document doc = builder.build(inputStream);
			//FIXME: I think this is not needed with XSD schema. Please use schema validation instead!
			if (!doc.hasRootElement() && (doc.getRootElement().getName().equalsIgnoreCase(Constants.XAADIN_ROOT_ELEMENT_NAME))) {
				throw new ParserException("could not find root rootElement with name xaadin");
			}

			Element rootElement = doc.getRootElement();
			xaadinNamespace = getDefaultXaadinNamespace(rootElement);
			List<Element> childrenList = rootElement.getChildren();
			if (childrenList.isEmpty()) {
				throw new ParserException("xaadin root element is empty");
			}
			return parseVisualTreeInt(childrenList.get(0), null, eventHandlerTarget, parent);
		} catch (Exception e) {
			throw new ParserException(e);
		}
	}
 
开发者ID:xaadin,项目名称:xaadin,代码行数:22,代码来源:Parser.java

示例4: loadFromFile

@MCRCommand(syntax = "load mods document from file {0} for project {1}",
    help = "Load MODS document {0} as MyCoRe Object for project {1}",
    order = 20)
public static void loadFromFile(String modsFileName, String projectID) throws JDOMException, IOException,
    MCRActiveLinkException, SAXException, MCRPersistenceException, MCRAccessException {
    File modsFile = new File(modsFileName);
    if (!modsFile.isFile()) {
        throw new MCRException(MessageFormat.format("File {0} is not a file.", modsFile.getAbsolutePath()));
    }
    SAXBuilder s = new SAXBuilder(XMLReaders.NONVALIDATING, null, null);
    Document modsDoc = s.build(modsFile);
    //force validation against MODS XSD
    MCRXMLHelper.validate(modsDoc, MODS_V3_XSD_URI);
    Element modsRoot = modsDoc.getRootElement();
    if (!modsRoot.getNamespace().equals(MCRConstants.MODS_NAMESPACE)) {
        throw new MCRException(
            MessageFormat.format("File {0} is not a MODS document.", modsFile.getAbsolutePath()));
    }
    if (modsRoot.getName().equals("modsCollection")) {
        List<Element> modsElements = modsRoot.getChildren("mods", MCRConstants.MODS_NAMESPACE);
        for (Element mods : modsElements) {
            saveAsMyCoReObject(projectID, mods);
        }
    } else {
        saveAsMyCoReObject(projectID, modsRoot);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:27,代码来源:MCRMODSCommands.java

示例5: loadFromFileWithFiles

@MCRCommand(syntax = "load mods document from file {0} with files from directory {1} for project {2}",
    help = "Load MODS document {0} as MyCoRe Object with files from direcory {1} for project {2}",
    order = 10)
public static void loadFromFileWithFiles(String modsFileName, String fileDirName, String projectID)
    throws JDOMException, IOException,
    MCRActiveLinkException, SAXException, MCRPersistenceException, MCRAccessException {
    File modsFile = new File(modsFileName);
    if (!modsFile.isFile()) {
        throw new MCRException(MessageFormat.format("File {0} is not a file.", modsFile.getAbsolutePath()));
    }

    File fileDir = new File(fileDirName);
    if (!fileDir.isDirectory()) {
        throw new MCRException(
            MessageFormat.format("Directory {0} is not a directory.", fileDir.getAbsolutePath()));
    }

    SAXBuilder s = new SAXBuilder(XMLReaders.NONVALIDATING, null, null);
    Document modsDoc = s.build(modsFile);
    //force validation against MODS XSD
    MCRXMLHelper.validate(modsDoc, MODS_V3_XSD_URI);
    Element modsRoot = modsDoc.getRootElement();
    if (!modsRoot.getNamespace().equals(MCRConstants.MODS_NAMESPACE)) {
        throw new MCRException(
            MessageFormat.format("File {0} is not a MODS document.", modsFile.getAbsolutePath()));
    }
    if (modsRoot.getName().equals("modsCollection")) {
        throw new MCRException(
            MessageFormat.format("File {0} contains a mods collection witch not supported by this command.",
                modsFile.getAbsolutePath()));
    } else {
        createDerivate(saveAsMyCoReObject(projectID, modsRoot), fileDir);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:34,代码来源:MCRMODSCommands.java

示例6: createSAXBuilder

/**
 * Creates and sets up a org.jdom2.input.SAXBuilder for parsing.
 *
 * @return a new org.jdom2.input.SAXBuilder object
 */
protected SAXBuilder createSAXBuilder() {
    SAXBuilder saxBuilder;
    if (validate) {
        saxBuilder = new SAXBuilder(XMLReaders.DTDVALIDATING);
    } else {
        saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING);
    }
    saxBuilder.setEntityResolver(RESOLVER);

    //
    // This code is needed to fix the security problem outlined in
    // http://www.securityfocus.com/archive/1/297714
    //
    // Unfortunately there isn't an easy way to check if an XML parser
    // supports a particular feature, so
    // we need to set it and catch the exception if it fails. We also need
    // to subclass the JDom SAXBuilder
    // class in order to get access to the underlying SAX parser - otherwise
    // the features don't get set until
    // we are already building the document, by which time it's too late to
    // fix the problem.
    //
    // Crimson is one parser which is known not to support these features.
    try {
        
        final XMLReader parser = saxBuilder.createParser();
        
        setFeature(saxBuilder, parser, "http://xml.org/sax/features/external-general-entities", false);
        setFeature(saxBuilder, parser, "http://xml.org/sax/features/external-parameter-entities", false);
        setFeature(saxBuilder, parser, "http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

        if(!allowDoctypes) {
            setFeature(saxBuilder, parser, "http://apache.org/xml/features/disallow-doctype-decl", true);
        }

    } catch (final JDOMException e) {
        throw new IllegalStateException("JDOM could not create a SAX parser", e);
    }
    
    saxBuilder.setExpandEntities(false);

    return saxBuilder;

}
 
开发者ID:rometools,项目名称:rome,代码行数:49,代码来源:WireFeedInput.java

示例7: getJDomDoc

protected Document getJDomDoc() throws Exception {
    final SAXBuilder saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING);
    return saxBuilder.build(getFeedReader());
}
 
开发者ID:rometools,项目名称:rome,代码行数:4,代码来源:FeedTest.java

示例8: createBuilder

private static SAXBuilder createBuilder() {
	SAXBuilder sax = new SAXBuilder(XMLReaders.NONVALIDATING);
	sax.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
	return sax;
}
 
开发者ID:pescuma,项目名称:buildhealth,代码行数:5,代码来源:JDomUtil.java

示例9: parseStream

/**
 * Reads xml from an InputStream and returns the parsed root element.
 *
 * @param in
 *            the InputStream that contains the XML document
 * @return the root element of the parsed input stream
 */
protected Element parseStream(InputStream in) throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);
    builder.setEntityResolver(MCREntityResolver.instance());

    return builder.build(in).getRootElement();
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:13,代码来源:MCRURIResolver.java

示例10: SAXBuilder

/**
 *
 * @deprecated use SAXBuilder(XMLReaderJDOMFactory) with either XMLReaders.DTDVALIDATING or
 *             XMLReaders.NONVALIDATING
 */
@Deprecated
public SAXBuilder(final boolean validate) {
    super(validate ? XMLReaders.DTDVALIDATING : XMLReaders.NONVALIDATING);
}
 
开发者ID:rometools,项目名称:rome,代码行数:9,代码来源:SAXBuilder.java


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