use of org.jdom.Document in project intellij-community by JetBrains.
the class ModelLoader method load.
protected final void load(String name) {
try {
InputStream stream = getClass().getResourceAsStream(name);
Document document = new SAXBuilder().build(stream);
stream.close();
loadDocument(document.getRootElement());
} catch (Throwable e) {
LOG.error(e);
}
}
use of org.jdom.Document in project intellij-community by JetBrains.
the class XmlSerializer method deserialize.
@NotNull
public static <T> T deserialize(@NotNull URL url, Class<T> aClass) throws XmlSerializationException {
try {
Document document = JDOMUtil.loadDocument(url);
document = JDOMXIncluder.resolve(document, url.toExternalForm());
return deserialize(document.getRootElement(), aClass);
} catch (IOException e) {
throw new XmlSerializationException(e);
} catch (JDOMException e) {
throw new XmlSerializationException(e);
}
}
use of org.jdom.Document in project zaproxy by zaproxy.
the class ContentMatcher method loadXMLPatternDefinitions.
/**
* Load a pattern list from an XML formatted file.
* Pattern should be enclosed around a {@code <Patterns>} tag and should be
* defined as {@code <Pattern type="xxx"></Pattern>}. Use "regex" to define
* a Regex formatted pattern or "string" for an exact matching pattern.
* @param xmlInputStream the {@code InputStream} used to read the patterns
* @throws JDOMException if an error occurred while parsing
* @throws IOException if an I/O error occurred while reading the {@code InputStream}
*/
protected void loadXMLPatternDefinitions(InputStream xmlInputStream) throws JDOMException, IOException {
strings = new ArrayList<BoyerMooreMatcher>();
patterns = new ArrayList<Pattern>();
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(xmlInputStream);
Element el = doc.getRootElement();
String value;
// go ahead for boundaries and tests
for (Object obj : el.getChildren(TAG_PATTERN)) {
el = (Element) obj;
value = el.getText();
// Check if the pattern has been set to null
if (value != null && !value.isEmpty()) {
// Check if a regex expression has been set
if (el.getAttributeValue(TAG_PATTERN_TYPE).equalsIgnoreCase(TAG_PATTERN_TYPE_REGEX)) {
patterns.add(Pattern.compile(el.getText()));
// Otherwise it's by default an exact match model
} else {
strings.add(new BoyerMooreMatcher(el.getText()));
}
}
}
}
use of org.jdom.Document in project intellij-community by JetBrains.
the class PluginManagerCore method loadDescriptorFromJar.
@Nullable
private static IdeaPluginDescriptorImpl loadDescriptorFromJar(@NotNull File file, @NotNull String fileName, @NotNull JDOMXIncluder.PathResolver pathResolver) {
try {
URL jarURL = URLUtil.getJarEntryURL(file, META_INF + '/' + fileName);
ZipFile zipFile = new ZipFile(file);
try {
ZipEntry entry = zipFile.getEntry(META_INF + '/' + fileName);
if (entry != null) {
Document document = JDOMUtil.loadDocument(zipFile.getInputStream(entry));
IdeaPluginDescriptorImpl descriptor = new IdeaPluginDescriptorImpl(file);
descriptor.readExternal(document, jarURL, pathResolver);
return descriptor;
}
} finally {
zipFile.close();
}
} catch (XmlSerializationException e) {
getLogger().info("Cannot load " + file, e);
prepareLoadingPluginsErrorMessage(Collections.singletonList("File '" + file.getName() + "' contains invalid plugin descriptor."));
} catch (Throwable e) {
getLogger().info("Cannot load " + file, e);
}
return null;
}
use of org.jdom.Document in project ACS by ACS-Community.
the class TestHighLevelNodes method testXmlMACI.
public void testXmlMACI() throws Exception {
logger.info("MACI XML string -- Classic: " + xmlXml);
SAXBuilder sb = new SAXBuilder();
InputStream is = new ByteArrayInputStream(rdbXml.getBytes("UTF-8"));
Document doc = sb.build(is);
XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
ByteArrayOutputStream out = new ByteArrayOutputStream();
xout.output(doc, out);
logger.info("MACI XML string -- RDB: " + out.toString());
// This fails at the moment because XML returns namespace info, TMCDB doesn't
assertXMLEqual("MACI XML pieces are similar ", xmlXml, rdbXml);
}
Aggregations