use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class MavenIndicesManager method loadUserArchetypes.
private void loadUserArchetypes() {
try {
Path file = getUserArchetypesFile();
if (!PathKt.exists(file)) {
return;
}
// Store artifact to set to remove duplicate created by old IDEA (https://youtrack.jetbrains.com/issue/IDEA-72105)
Collection<MavenArchetype> result = new LinkedHashSet<>();
List<Element> children = JdomKt.loadElement(file).getChildren(ELEMENT_ARCHETYPE);
for (int i = children.size() - 1; i >= 0; i--) {
Element each = children.get(i);
String groupId = each.getAttributeValue(ELEMENT_GROUP_ID);
String artifactId = each.getAttributeValue(ELEMENT_ARTIFACT_ID);
String version = each.getAttributeValue(ELEMENT_VERSION);
String repository = each.getAttributeValue(ELEMENT_REPOSITORY);
String description = each.getAttributeValue(ELEMENT_DESCRIPTION);
if (StringUtil.isEmptyOrSpaces(groupId) || StringUtil.isEmptyOrSpaces(artifactId) || StringUtil.isEmptyOrSpaces(version)) {
continue;
}
result.add(new MavenArchetype(groupId, artifactId, version, repository, description));
}
ArrayList<MavenArchetype> listResult = new ArrayList<>(result);
Collections.reverse(listResult);
myUserArchetypes = listResult;
} catch (IOException | JDOMException e) {
MavenLog.LOG.warn(e);
}
}
use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class YouTrackRepository method getIssues.
public Task[] getIssues(@Nullable String request, int max, long since) throws Exception {
String query = getDefaultSearch();
if (StringUtil.isNotEmpty(request)) {
query += " " + request;
}
String requestUrl = "/rest/project/issues/?filter=" + encodeUrl(query) + "&max=" + max + "&updatedAfter" + since;
HttpMethod method = doREST(requestUrl, false);
try {
InputStream stream = method.getResponseBodyAsStream();
// todo workaround for http://youtrack.jetbrains.net/issue/JT-7984
String s = StreamUtil.readText(stream, CharsetToolkit.UTF8_CHARSET);
for (int i = 0; i < s.length(); i++) {
if (!XMLChar.isValid(s.charAt(i))) {
s = s.replace(s.charAt(i), ' ');
}
}
Element element;
try {
//InputSource source = new InputSource(stream);
//source.setEncoding("UTF-8");
//element = new SAXBuilder(false).build(source).getRootElement();
element = new SAXBuilder(false).build(new StringReader(s)).getRootElement();
} catch (JDOMException e) {
LOG.error("Can't parse YouTrack response for " + requestUrl, e);
throw e;
}
if ("error".equals(element.getName())) {
throw new Exception("Error from YouTrack for " + requestUrl + ": '" + element.getText() + "'");
}
List<Element> children = element.getChildren("issue");
final List<Task> tasks = ContainerUtil.mapNotNull(children, (NullableFunction<Element, Task>) o -> createIssue(o));
return tasks.toArray(new Task[tasks.size()]);
} finally {
method.releaseConnection();
}
}
use of org.jdom.JDOMException in project intellij-community by JetBrains.
the class DotProjectFileHelper method saveDotProjectFile.
public static void saveDotProjectFile(@NotNull Module module, @NotNull String storageRoot) throws IOException {
try {
Document doc;
if (ModuleType.get(module) instanceof JavaModuleType) {
doc = JDOMUtil.loadDocument(DotProjectFileHelper.class.getResource("template.project.xml"));
} else {
doc = JDOMUtil.loadDocument(DotProjectFileHelper.class.getResource("template.empty.project.xml"));
}
doc.getRootElement().getChild(EclipseXml.NAME_TAG).setText(module.getName());
final File projectFile = new File(storageRoot, EclipseXml.PROJECT_FILE);
if (!FileUtil.createIfDoesntExist(projectFile)) {
return;
}
EclipseJDOMUtil.output(doc.getRootElement(), projectFile, module.getProject());
ApplicationManager.getApplication().runWriteAction(() -> {
LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(projectFile.getPath()));
});
} catch (JDOMException e) {
LOG.error(e);
}
}
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 aliyun-oss-java-sdk by aliyun.
the class PerftestRunner method buildScenario.
public void buildScenario(final String scenarioTypeString) {
File confFile = new File(System.getProperty("user.dir") + File.separator + "runner_conf.xml");
InputStream input = null;
try {
input = new FileInputStream(confFile);
} catch (FileNotFoundException e) {
log.error(e);
Assert.fail(e.getMessage());
}
SAXBuilder builder = new SAXBuilder();
try {
Document doc = builder.build(input);
Element root = doc.getRootElement();
scenario = new TestScenario();
scenario.setHost(root.getChildText("host"));
scenario.setAccessId(root.getChildText("accessid"));
scenario.setAccessKey(root.getChildText("accesskey"));
scenario.setBucketName(root.getChildText("bucket"));
scenario.setType(determineScenarioType(scenarioTypeString));
Element target = root.getChild(scenarioTypeString);
if (target != null) {
scenario.setContentLength(Long.parseLong(target.getChildText("size")));
scenario.setPutThreadNumber(Integer.parseInt(target.getChildText("putthread")));
scenario.setGetThreadNumber(Integer.parseInt(target.getChildText("getthread")));
scenario.setDurationInSeconds(Integer.parseInt(target.getChildText("time")));
scenario.setGetQPS(Integer.parseInt(target.getChildText("getqps")));
scenario.setPutQPS(Integer.parseInt(target.getChildText("putqps")));
} else {
log.error("Unable to locate XML element " + scenarioTypeString);
Assert.fail("Unable to locate XML element " + scenarioTypeString);
}
} catch (JDOMException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
Aggregations