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


Java SAXBuilder.setFeature方法代码示例

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


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

示例1: merge

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
/**
 * 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,代码行数:37,代码来源:LeXeMerger.java

示例2: parseXHTMLDocument

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
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,代码行数:19,代码来源:XHTMLUtils.java

示例3: importXml

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
protected void importXml(String text) {
    if (isNotBlank(text)) {
        SAXBuilder builder = new SAXBuilder();
        builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
        builder.setFeature("http://xml.org/sax/features/validation", false);
        try {
            Document document = builder.build(new StringReader(text));
            String rootName = document.getRootElement().getName();
            if (rootName.equals("definitions")) {
                importFromWsdl(text);
            } else if (rootName.equals("schema")) {
                importFromXsd(text);
            } else {
                Notification note = new Notification("Unrecognized Content", "The XML file has a root element of " + rootName
                        + ", but expected \"definitions\" for WSDL or \"schema\" for XSD.");
                note.show(Page.getCurrent());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:JumpMind,项目名称:metl,代码行数:23,代码来源:ImportXmlTemplateWindow.java

示例4: buildXpathChoices

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
protected void buildXpathChoices() {
    SAXBuilder builder = new SAXBuilder();
    builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    Setting setting = component.findSetting(XmlFormatter.XML_FORMATTER_TEMPLATE);
    xpathChoices = new TreeSet<String>();
    if (StringUtils.isNotBlank(setting.getValue())) {
        try {
            Document document = builder.build(new StringReader(setting.getValue()));
            
            buildXpathChoicesFromElement("/" + document.getRootElement().getName(),
                    document.getRootElement());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    ComboBox combo = (ComboBox) grid.getColumn("xpath").getEditorField();
    combo.removeAllItems();
    combo.addItems(xpathChoices);
}
 
开发者ID:JumpMind,项目名称:metl,代码行数:22,代码来源:EditXmlFormatPanel.java

示例5: parseXmlStream

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
/**
 * Parses a stream of XML into a tree of XML elements.
 *
 * @param xmlStream The XML.
 * @return The root element of the XML tree.
 * @throws XmlException When a failure to parse the XML.
 */
public static Element parseXmlStream(InputStream xmlStream) throws XmlException {
	try {
		SAXBuilder saxBuilder = new SAXBuilder();
		saxBuilder.setFeature(DISALLOW_DTD,true);
		saxBuilder.setFeature(EXT_GENERAL_ENTITIES , false);
		saxBuilder.setFeature(EXT_PARAM_ENTITIES, false);

		return saxBuilder.build(xmlStream).getRootElement();
	} catch (JDOMException | IOException e) {
		throw new XmlException("Failed to process XML String into DOM Element", e);
	}
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:20,代码来源:XmlUtils.java

示例6: setupBuilder

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
public static void setupBuilder() {
	URL schema = MonomerFactory.class.getResource(MONOMER_DB_SCHEMA_RESOURCE);
	builder = new SAXBuilder(false); // checks both well-formedness and
	// validity
	builder.setFeature(XML_SCHEMA_VALIDATION_FEATURE, true);
	builder.setProperty(EXTERNAL_SCHEMA_LOCATION_KEY, DEFAULT_NAME_SPACE + " " + schema.toString());
}
 
开发者ID:PistoiaHELM,项目名称:HELM2NotationToolkit,代码行数:8,代码来源:MonomerFactory.java

示例7: setupBuilder

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
private static void setupBuilder() {
  URL schema = MonomerFactory.class.getResource(NUCLEOTIDE_TEMPLATE_SCHEMA_RESOURCE);
  builder = new SAXBuilder(true); // checks both well-formedness and
  // validity
  builder.setFeature(XML_SCHEMA_VALIDATION_FEATURE, true);
  builder.setProperty(EXTERNAL_SCHEMA_LOCATION_KEY, DEFAULT_NAME_SPACE
      + " " + schema.toString());
}
 
开发者ID:PistoiaHELM,项目名称:HELM2NotationToolkit,代码行数:9,代码来源:NucleotideFactory.java

示例8: MCRXMLParserImpl

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
public MCRXMLParserImpl(XMLReaderJDOMFactory factory, boolean silent) {
    this.validate = factory.isValidating();
    builder = new SAXBuilder(factory);
    builder.setFeature(FEATURE_NAMESPACES, true);
    builder.setFeature(FEATURE_SCHEMA_SUPPORT, validate);
    builder.setFeature(FEATURE_FULL_SCHEMA_SUPPORT, false);
    builder.setErrorHandler(new MCRXMLParserErrorHandler(silent));
    builder.setEntityResolver(new XercesBugFixResolver(MCREntityResolver.instance()));
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:10,代码来源:MCRXMLParserImpl.java

示例9: parse

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
public static Document parse(InputStream is) throws IOException, JDOMException {
	SAXBuilder builder = new SAXBuilder();

       // DTD validation is makes an HTTP request and is slow. Don't need this feature, so disable it.
       builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

       Document doc = builder.build(is);
	return doc; 
}
 
开发者ID:dnault,项目名称:xml-patch,代码行数:10,代码来源:XmlHelper.java

示例10: createSaxBuilder

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
public static SAXBuilder createSaxBuilder() {
    SAXBuilder sb = new SAXBuilder();
    // don't validate and don't load dtd
    sb.setXMLReaderFactory(XMLReaders.NONVALIDATING);
    sb.setFeature("http://xml.org/sax/features/validation", false);
    sb.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
    sb.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    // JNLP needs DOCTYPE
    //sb.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
    sb.setFeature("http://xml.org/sax/features/external-general-entities", false);
    sb.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
    return sb;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:14,代码来源:XmlUtils.java

示例11: getTransformedXml

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
public static String getTransformedXml(String inputXml, String stylesheetXml, String xmlFormat, boolean omitXmlDeclaration) {
    StringWriter writer = new StringWriter();
    SAXBuilder builder = new SAXBuilder();
    builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    try {
        Document inputDoc = builder.build(new StringReader(inputXml));
        StringReader reader = new StringReader(stylesheetXml);
        XSLTransformer transformer = new XSLTransformer(reader);
        Document outputDoc = transformer.transform(inputDoc);
        XMLOutputter xmlOutput = new XMLOutputter();
        Format format = null;
        if (xmlFormat.equals(COMPACT_FORMAT)) {
            format = Format.getCompactFormat();
        } else if (xmlFormat.equals(RAW_FORMAT)) {
            format = Format.getRawFormat();
        } else {
            format = Format.getPrettyFormat();
        }
        
        format.setOmitDeclaration(omitXmlDeclaration);
        xmlOutput.setFormat(format);
        xmlOutput.output(outputDoc, writer);
        writer.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return writer.toString();
}
 
开发者ID:JumpMind,项目名称:metl,代码行数:30,代码来源:XsltProcessor.java

示例12: setFeatures

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
public static void setFeatures(SAXBuilder reader, String features) throws SAXException {
    if (!StringUtils.isEmpty(features)) {
        Map<String, Boolean> featuresMap = parseFeatures(features);
        for (String key : featuresMap.keySet()) {
            reader.setFeature(key, featuresMap.get(key));
        }
    }
}
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:9,代码来源:XmlUtils.java

示例13: getJDomBuilder

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
private SAXBuilder getJDomBuilder() {
    final SAXBuilder jdomBuilder = new SAXBuilder();
    jdomBuilder.setJDOMFactory(new SlimJDOMFactory());
    jdomBuilder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    return jdomBuilder;
}
 
开发者ID:ayakovlevgh,项目名称:jodtemplate,代码行数:7,代码来源:JDOMHelper.java

示例14: getJDomBuilder

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
private static SAXBuilder getJDomBuilder() {
    final SAXBuilder jdomBuilder = new SAXBuilder();
    jdomBuilder.setJDOMFactory(new SlimJDOMFactory());
    jdomBuilder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    return jdomBuilder;
}
 
开发者ID:ayakovlevgh,项目名称:jodtemplate,代码行数:7,代码来源:TestUtils.java

示例15: handleUsingXPath

import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected void handleUsingXPath(Message inputMessage, ISendMessageCallback callback, boolean unitOfWorkBoundaryReached) {
    ArrayList<String> inputRows = ((TextMessage) inputMessage).getPayload();
    ArrayList<EntityData> payload = new ArrayList<EntityData>();
    if (inputRows != null) {
        for (String xml : inputRows) {
            SAXBuilder builder = new SAXBuilder();
            builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
            builder.setFeature("http://xml.org/sax/features/validation", false);
            try {
                Document document = builder.build(new StringReader(xml));
                removeNamespaces(document);
                for (XmlFormatterEntitySetting entitySetting : entitySettings) {
                    List<XmlFormatterAttributeSetting> attributeSettings = entitySetting.getAttributeSettings();
                    List<Element> entityMatches = (List<Element>) entitySetting.getExpression().evaluate(document.getRootElement());
                    for (Element element : entityMatches) {
                        String text = toXML(element);
                        Document childDocument = builder.build(new ByteArrayInputStream(text.getBytes(Charset.forName("utf-8"))));
                        getComponentStatistics().incrementNumberEntitiesProcessed(threadNumber);
                        EntityData data = new EntityData();
                        for (XmlFormatterAttributeSetting attributeSetting : attributeSettings) {
                            boolean resultsFound = false;
                            Element targetElement = element;
                            Document targetDocument = childDocument;
                            do {
                                List<Object> attributeMatches = (List<Object>) attributeSetting.getExpression().evaluate(targetDocument);
                                for (Object object : attributeMatches) {
                                    resultsFound = true;
                                    if (object instanceof Attribute) {
                                        data.put(attributeSetting.getSetting().getAttributeId(), ((Attribute) object).getValue());
                                    } else if (object instanceof Content) {
                                        data.put(attributeSetting.getSetting().getAttributeId(), ((Content) object).getValue());
                                    } else if (object instanceof Element) {
                                        data.put(attributeSetting.getSetting().getAttributeId(), ((Element) object).getTextTrim());
                                    } else {
                                        data.put(attributeSetting.getSetting().getAttributeId(), object);
                                    }
                                }

                                if (!resultsFound && !attributeSetting.getExpression().getExpression().startsWith("/" + element.getName())
                                        && targetElement.getParentElement() != null) {
                                    targetElement = targetElement.getParentElement();
                                    targetDocument = builder
                                            .build(new ByteArrayInputStream(toXML(targetElement).getBytes(Charset.forName("utf-8"))));
                                } else if (!resultsFound) {
                                    info("Did not find a match for: %s\n in:\n %s", attributeSetting.getExpression().getExpression(),
                                            text);
                                    targetDocument = null;
                                    targetElement = null;
                                }
                            } while (!resultsFound && targetElement != null);
                        }
                        if (data.size() > 0) {
                            payload.add(data);
                        } else {
                            log(LogLevel.WARN,
                                    "Found entity element: <%s/> with no matching attributes.  Please make sure your xpath expressions match",
                                    element.getName());
                        }
                    }
                }

                if (payload.size() > rowsPerMessage) {
                    callback.sendEntityDataMessage(null, payload);
                    payload = new ArrayList<>();
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    if (payload.size() > 0) {
        callback.sendEntityDataMessage(null, payload);
    }

}
 
开发者ID:JumpMind,项目名称:metl,代码行数:78,代码来源:XmlParser.java


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