use of org.jdom.xpath.XPath in project intellij-community by JetBrains.
the class FogBugzRepository method getCases.
@SuppressWarnings("unchecked")
private Task[] getCases(String q) throws Exception {
loginIfNeeded();
PostMethod method = new PostMethod(getUrl() + "/api.asp");
method.addParameter("token", myToken);
method.addParameter("cmd", "search");
method.addParameter("q", q);
method.addParameter("cols", "sTitle,fOpen,dtOpened,dtLastUpdated,ixCategory");
int status = getHttpClient().executeMethod(method);
if (status != 200) {
throw new Exception("Error listing cases: " + method.getStatusLine());
}
Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument();
List<Element> errorNodes = XPath.newInstance("/response/error").selectNodes(document);
if (!errorNodes.isEmpty()) {
throw new Exception("Error listing cases: " + errorNodes.get(0).getText());
}
final XPath commentPath = XPath.newInstance("events/event");
final List<Element> nodes = (List<Element>) XPath.newInstance("/response/cases/case").selectNodes(document);
final List<Task> tasks = ContainerUtil.mapNotNull(nodes, (NotNullFunction<Element, Task>) element -> createCase(element, commentPath));
return tasks.toArray(new Task[tasks.size()]);
}
use of org.jdom.xpath.XPath in project intellij-community by JetBrains.
the class FogBugzRepository method login.
private void login(@NotNull PostMethod method) throws Exception {
LOG.debug("Requesting new token");
int status = getHttpClient().executeMethod(method);
if (status != 200) {
throw new Exception("Error logging in: " + method.getStatusLine());
}
Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument();
XPath path = XPath.newInstance("/response/token");
Element result = (Element) path.selectSingleNode(document);
if (result == null) {
Element error = (Element) XPath.newInstance("/response/error").selectSingleNode(document);
throw new Exception(error == null ? "Error logging in" : error.getText());
}
myToken = result.getTextTrim();
}
use of org.jdom.xpath.XPath in project intellij-community by JetBrains.
the class XPathResponseHandler method lazyCompile.
@NotNull
private XPath lazyCompile(@NotNull String path) throws Exception {
XPath xPath = myCompiledCache.get(path);
if (xPath == null) {
try {
xPath = XPath.newInstance(path);
myCompiledCache.put(path, xPath);
} catch (JDOMException e) {
throw new Exception(String.format("Malformed XPath expression '%s'", path));
}
}
return xPath;
}
use of org.jdom.xpath.XPath in project intellij-community by JetBrains.
the class XPathResponseHandler method selectTasksList.
@NotNull
@Override
protected List<Object> selectTasksList(@NotNull String response, int max) throws Exception {
Document document = new SAXBuilder(false).build(new StringReader(response));
Element root = document.getRootElement();
XPath xPath = lazyCompile(getSelector(TASKS).getPath());
@SuppressWarnings("unchecked") List<Object> rawTaskElements = xPath.selectNodes(root);
if (!rawTaskElements.isEmpty() && !(rawTaskElements.get(0) instanceof Element)) {
throw new Exception(String.format("Expression '%s' should match list of XML elements. Got '%s' instead.", xPath.getXPath(), rawTaskElements.toString()));
}
return rawTaskElements.subList(0, Math.min(rawTaskElements.size(), max));
}
use of org.jdom.xpath.XPath in project intellij-community by JetBrains.
the class XsltDocumentationProvider method getUrlFor.
@Nullable
public List<String> getUrlFor(PsiElement psiElement, PsiElement psiElement1) {
if (psiElement instanceof XsltElement)
return null;
final String category;
final String name;
final String tagName = getTagName(psiElement);
if (tagName != null) {
name = tagName;
category = "element";
} else if (psiElement instanceof XPathFunction) {
name = ((XPathFunction) psiElement).getName();
category = "function";
} else if (psiElement instanceof DocElement) {
name = ((DocElement) psiElement).getName();
category = ((DocElement) psiElement).getCategory();
} else {
return null;
}
try {
final Document document = getDocumentationDocument();
final XPath xPath = XPath.newInstance("//x:" + category + "[@name = '" + name + "']");
xPath.addNamespace("x", document.getRootElement().getNamespaceURI());
final Element e = (Element) xPath.selectSingleNode(document);
if (e != null) {
return Collections.singletonList(e.getParentElement().getAttributeValue("base") + e.getAttributeValue("href"));
}
} catch (Exception e) {
Logger.getInstance(getClass().getName()).error(e);
}
return null;
}
Aggregations