use of org.dom4j.io.SAXReader in project OpenOLAT by OpenOLAT.
the class ItemFileResourceValidator method readDocument.
private Document readDocument(InputStream in) {
try {
SAXReader reader = new SAXReader();
reader.setEntityResolver(new IMSEntityResolver());
reader.setValidation(false);
return reader.read(in, "");
} catch (Exception e) {
return null;
}
}
use of org.dom4j.io.SAXReader in project OpenOLAT by OpenOLAT.
the class QTIImportProcessor method processSidecarMetadata.
private boolean processSidecarMetadata(QuestionItemImpl item, DocInfos docInfos) {
InputStream metadataIn = null;
try {
Path path = docInfos.root;
if (path != null && path.getFileName() != null) {
Path metadata = path.resolve(path.getFileName().toString() + "_metadata.xml");
metadataIn = Files.newInputStream(metadata);
SAXReader reader = new SAXReader();
Document document = reader.read(metadataIn);
Element rootElement = document.getRootElement();
QTIMetadataConverter enricher = new QTIMetadataConverter(rootElement, qItemTypeDao, qEduContextDao, qpoolService);
enricher.toQuestion(item);
}
return true;
} catch (NoSuchFileException e) {
// nothing to do
return true;
} catch (Exception e) {
log.error("", e);
return false;
} finally {
IOUtils.closeQuietly(metadataIn);
}
}
use of org.dom4j.io.SAXReader in project plugin-compat-tester by jenkinsci.
the class MavenPom method transformPom.
public void transformPom(MavenCoordinates coreCoordinates) throws PomTransformationException {
File pom = new File(rootDir.getAbsolutePath() + "/" + pomFileName);
File backupedPom = new File(rootDir.getAbsolutePath() + "/" + pomFileName + ".backup");
try {
FileUtils.rename(pom, backupedPom);
Document doc;
try {
doc = new SAXReader().read(backupedPom);
} catch (DocumentException x) {
throw new IOException(x);
}
Element parent = doc.getRootElement().element("parent");
if (parent != null) {
Element groupIdElem = parent.element(GROUP_ID_ELEMENT);
if (groupIdElem != null) {
groupIdElem.setText(coreCoordinates.groupId);
}
Element artifactIdElem = parent.element(ARTIFACT_ID_ELEMENT);
if (artifactIdElem != null) {
artifactIdElem.setText(coreCoordinates.artifactId);
}
Element versionIdElem = parent.element(VERSION_ELEMENT);
if (versionIdElem != null) {
versionIdElem.setText(coreCoordinates.version);
}
}
writeDocument(pom, doc);
} catch (Exception e) {
throw new PomTransformationException("Error while transforming pom : " + pom.getAbsolutePath(), e);
}
}
use of org.dom4j.io.SAXReader in project plugin-compat-tester by jenkinsci.
the class MavenPom method addDependencies.
public void addDependencies(Map<String, VersionNumber> toAdd, Map<String, VersionNumber> toReplace, Map<String, VersionNumber> toAddTest, Map<String, VersionNumber> toReplaceTest, VersionNumber coreDep, Map<String, String> pluginGroupIds, List<String> toConvert) throws IOException {
File pom = new File(rootDir.getAbsolutePath() + "/" + pomFileName);
Document doc;
try {
doc = new SAXReader().read(pom);
} catch (DocumentException x) {
throw new IOException(x);
}
Element dependencies = doc.getRootElement().element("dependencies");
if (dependencies == null) {
dependencies = doc.getRootElement().addElement("dependencies");
}
for (Element mavenDependency : (List<Element>) dependencies.elements("dependency")) {
Element artifactId = mavenDependency.element(ARTIFACT_ID_ELEMENT);
if (artifactId == null || !"maven-plugin".equals(artifactId.getTextTrim())) {
continue;
}
Element version = mavenDependency.element(VERSION_ELEMENT);
if (version == null || version.getTextTrim().startsWith("${")) {
// Prior to 1.532, plugins sometimes assumed they could pick up the Maven plugin version from their parent POM.
if (version != null) {
mavenDependency.remove(version);
}
version = mavenDependency.addElement(VERSION_ELEMENT);
version.addText(coreDep.toString());
}
}
Map<String, VersionNumber> toReplaceUsed = new LinkedHashMap<>();
Map<String, VersionNumber> toReplaceTestUsed = new LinkedHashMap<>();
for (Element mavenDependency : (List<Element>) dependencies.elements("dependency")) {
Element artifactId = mavenDependency.element(ARTIFACT_ID_ELEMENT);
Element groupId = mavenDependency.element(GROUP_ID_ELEMENT);
if (artifactId == null || groupId == null) {
continue;
}
String expectedGroupId = pluginGroupIds.get(artifactId.getTextTrim());
if (expectedGroupId == null || !groupId.getTextTrim().equals(expectedGroupId)) {
continue;
}
String trimmedArtifactId = artifactId.getTextTrim();
excludeSecurity144Compat(mavenDependency);
VersionNumber replacement = toReplace.get(trimmedArtifactId);
if (replacement == null) {
replacement = toReplaceTest.get(trimmedArtifactId);
if (replacement == null) {
continue;
}
toReplaceTestUsed.put(trimmedArtifactId, replacement);
}
Element version = mavenDependency.element(VERSION_ELEMENT);
if (version != null) {
mavenDependency.remove(version);
}
version = mavenDependency.addElement(VERSION_ELEMENT);
if (toConvert.contains(artifactId)) {
// Remove the test scope
Element scope = mavenDependency.element("scope");
if (scope != null) {
mavenDependency.remove(scope);
}
}
version.addText(replacement.toString());
toReplaceUsed.put(trimmedArtifactId, replacement);
}
// If the replacement dependencies weren't explicitly present in the pom, add them directly now
toReplace.entrySet().removeAll(toReplaceUsed.entrySet());
toReplaceTest.entrySet().removeAll(toReplaceTestUsed.entrySet());
toAdd.putAll(toReplace);
toAddTest.putAll(toReplaceTest);
dependencies.addComment("SYNTHETIC");
addPlugins(toAdd, pluginGroupIds, dependencies, null);
addPlugins(toAddTest, pluginGroupIds, dependencies, "test");
writeDocument(pom, doc);
}
use of org.dom4j.io.SAXReader in project tdq-studio-se by Talend.
the class SQLHistory method loadFromFileV350.
private void loadFromFileV350() {
try {
File file = new File(ApplicationFiles.SQLHISTORY_FILE_NAME_V350);
SAXReader reader = new SAXReader();
Element root = reader.read(file).getRootElement();
_history.clear();
_filteredHistory.clear();
for (Element elem : root.elements(SQLHistoryElement.ELEMENT)) _history.add(new SQLHistoryElement(elem));
} catch (DocumentException e) {
SQLExplorerPlugin.error("Cannot load history (v3.5.0 format)", e);
}
}
Aggregations