use of org.jdom.JDOMException 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.JDOMException in project Asqatasun by Asqatasun.
the class KbCsvMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
FileReader fin = new FileReader(inCsv);
BufferedReader reader = new BufferedReader(fin);
if (!outCsv.getParentFile().exists()) {
outCsv.getParentFile().mkdirs();
}
PrintWriter writer = new PrintWriter(outCsv);
writer.println(formatCsvLine("name", "url", "campain", "test", "result"));
String readed;
while ((readed = reader.readLine()) != null) {
// CSV params: 0=campain, 1=test
String[] params = readed.split(";");
if (params.length != 2) {
getLog().warn("Incorrect line: " + readed);
continue;
}
String ruleUrl = baseUrl + params[0] + "/" + params[1] + "/";
for (int i = 0; i < KB_TEST_RESULTS.length; i++) {
String url = ruleUrl + KB_TEST_RESULTS[i] + "/?lang=en";
try {
for (String result : getUrls(url)) {
// Substring 28 to remove URL beginning
String targetName = sanitizeClassName(result.substring(28));
writer.println(formatCsvLine(targetName, result, params[0], params[1], TG_TEST_RESULTS[i]));
}
} catch (JaxenException ex) {
getLog().warn("Unable to select URLs for address " + url, ex);
} catch (JDOMException ex) {
getLog().warn("Invalid XML at " + url, ex);
}
}
}
writer.close();
reader.close();
fin.close();
} catch (IOException ex) {
throw new MojoExecutionException("Unexpected IO Exception", ex);
}
}
use of org.jdom.JDOMException in project maven-plugins by apache.
the class AbstractEffectiveMojo method addMavenNamespace.
/**
* Add a Pom/Settings namespaces to the effective XML content.
*
* @param effectiveXml not null the effective POM or Settings
* @param isPom if <code>true</code> add the Pom xsd url, otherwise add the settings xsd url.
* @return the content of the root element, i.e. <project/> or <settings/> with the Maven namespace or
* the original <code>effective</code> if an error occurred.
* @see #POM_XSD_URL
* @see #SETTINGS_XSD_URL
*/
protected static String addMavenNamespace(String effectiveXml, boolean isPom) {
SAXBuilder builder = new SAXBuilder();
try {
Document document = builder.build(new StringReader(effectiveXml));
Element rootElement = document.getRootElement();
// added namespaces
Namespace pomNamespace = Namespace.getNamespace("", "http://maven.apache.org/POM/4.0.0");
rootElement.setNamespace(pomNamespace);
Namespace xsiNamespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
rootElement.addNamespaceDeclaration(xsiNamespace);
if (rootElement.getAttribute("schemaLocation", xsiNamespace) == null) {
rootElement.setAttribute("schemaLocation", "http://maven.apache.org/POM/4.0.0 " + (isPom ? POM_XSD_URL : SETTINGS_XSD_URL), xsiNamespace);
}
ElementFilter elementFilter = new ElementFilter(Namespace.getNamespace(""));
for (Iterator<?> i = rootElement.getDescendants(elementFilter); i.hasNext(); ) {
Element e = (Element) i.next();
e.setNamespace(pomNamespace);
}
StringWriter w = new StringWriter();
Format format = Format.getPrettyFormat();
XMLOutputter out = new XMLOutputter(format);
out.output(document.getRootElement(), w);
return w.toString();
} catch (JDOMException e) {
return effectiveXml;
} catch (IOException e) {
return effectiveXml;
}
}
use of org.jdom.JDOMException in project maven-plugins by apache.
the class EffectivePomMojo method prettyFormat.
/**
* @param effectivePom not null
* @return pretty format of the xml or the original <code>effectivePom</code> if an error occurred.
*/
private static String prettyFormat(String effectivePom) {
SAXBuilder builder = new SAXBuilder();
try {
Document effectiveDocument = builder.build(new StringReader(effectivePom));
StringWriter w = new StringWriter();
Format format = Format.getPrettyFormat();
XMLOutputter out = new XMLOutputter(format);
out.output(effectiveDocument, w);
return w.toString();
} catch (JDOMException e) {
return effectivePom;
} catch (IOException e) {
return effectivePom;
}
}
use of org.jdom.JDOMException in project intellij-plugins by StepicOrg.
the class ModuleUtils method createStepModule.
static void createStepModule(@NotNull Project project, @NotNull StepNode step, @NotNull ModifiableModuleModel moduleModel) {
StudyNode lesson = step.getParent();
if (lesson != null) {
String moduleDir = String.join("/", project.getBasePath(), lesson.getPath());
StepModuleBuilder stepModuleBuilder = new StepModuleBuilder(moduleDir, step);
try {
stepModuleBuilder.createModule(moduleModel);
} catch (IOException | ModuleWithNameAlreadyExists | JDOMException | ConfigurationException e) {
logger.warn("Cannot create step: " + step.getDirectory(), e);
}
}
}
Aggregations