本文整理汇总了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());
}
}
示例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;
}
示例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);
}
}
}
示例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);
}
示例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);
}
}
示例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());
}
示例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());
}
示例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()));
}
示例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;
}
示例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;
}
示例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();
}
示例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));
}
}
}
示例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;
}
示例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;
}
示例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);
}
}