use of org.jdom.Document 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.Document 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.Document 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;
}
use of org.jdom.Document in project intellij-community by JetBrains.
the class ClientPropertiesManager method checkInitDefaultManager.
private static void checkInitDefaultManager() {
synchronized (DEFAULT_MANAGER_LOCK) {
// in Upsource projectOpened can be executed concurrently for 2 projects
if (ourDefaultManager == null) {
ourDefaultManager = new ClientPropertiesManager();
try {
//noinspection HardCodedStringLiteral
final Document document = new SAXBuilder().build(ClientPropertiesManager.class.getResource("/" + COMPONENT_NAME + ".xml"));
final Element child = document.getRootElement();
ourDefaultManager.readExternal(child);
} catch (Exception e) {
LOG.error(e);
}
}
}
}
use of org.jdom.Document in project intellij-community by JetBrains.
the class CaptureConfigurable method createComponent.
@Nullable
@Override
public JComponent createComponent() {
myTableModel = new MyTableModel();
JBTable table = new JBTable(myTableModel);
table.setColumnSelectionAllowed(false);
TableColumnModel columnModel = table.getColumnModel();
TableUtil.setupCheckboxColumn(columnModel.getColumn(MyTableModel.ENABLED_COLUMN));
ToolbarDecorator decorator = ToolbarDecorator.createDecorator(table);
decorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
myTableModel.addRow();
}
});
decorator.setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.removeSelectedItems(table);
}
});
decorator.setMoveUpAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.moveSelectedItemsUp(table);
}
});
decorator.setMoveDownAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.moveSelectedItemsDown(table);
}
});
decorator.addExtraAction(new DumbAwareActionButton("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) {
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() == 1;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> {
try {
int idx = myTableModel.add(c.clone());
table.getSelectionModel().setSelectionInterval(idx, idx);
} catch (CloneNotSupportedException ex) {
LOG.error(ex);
}
});
}
});
decorator.addExtraAction(new DumbAwareActionButton("Enable Selected", "Enable Selected", PlatformIcons.SELECT_ALL_ICON) {
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() > 0;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> c.myEnabled = true);
table.repaint();
}
});
decorator.addExtraAction(new DumbAwareActionButton("Disable Selected", "Disable Selected", PlatformIcons.UNSELECT_ALL_ICON) {
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() > 0;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> c.myEnabled = false);
table.repaint();
}
});
new DumbAwareAction("Toggle") {
@Override
public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabled(table.getSelectedRowCount() == 1);
}
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> c.myEnabled = !c.myEnabled);
table.repaint();
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), table);
decorator.addExtraAction(new DumbAwareActionButton("Import", "Import", AllIcons.Actions.Install) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, false, true, true) {
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || "xml".equals(file.getExtension()) || file.getFileType() == FileTypes.ARCHIVE);
}
@Override
public boolean isFileSelectable(VirtualFile file) {
return file.getFileType() == StdFileTypes.XML;
}
};
descriptor.setDescription("Please select a file to import.");
descriptor.setTitle("Import Capture Points");
VirtualFile[] files = FileChooser.chooseFiles(descriptor, e.getProject(), null);
if (ArrayUtil.isEmpty(files))
return;
table.getSelectionModel().clearSelection();
for (VirtualFile file : files) {
try {
Document document = JDOMUtil.loadDocument(file.getInputStream());
List<Element> children = document.getRootElement().getChildren();
children.forEach(element -> {
int idx = myTableModel.addIfNeeded(XmlSerializer.deserialize(element, CapturePoint.class));
table.getSelectionModel().addSelectionInterval(idx, idx);
});
} catch (Exception ex) {
final String msg = ex.getLocalizedMessage();
Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
}
}
}
});
decorator.addExtraAction(new DumbAwareActionButton("Export", "Export", AllIcons.Actions.Export) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Export Selected Capture Points to File...", "", "xml"), e.getProject()).save(null, null);
if (wrapper == null)
return;
Element rootElement = new Element("capture-points");
selectedCapturePoints(table).forEach(c -> {
try {
CapturePoint clone = c.clone();
clone.myEnabled = false;
rootElement.addContent(XmlSerializer.serialize(clone));
} catch (CloneNotSupportedException ex) {
LOG.error(ex);
}
});
try {
JDOMUtil.write(rootElement, wrapper.getFile());
} catch (Exception ex) {
final String msg = ex.getLocalizedMessage();
Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
}
}
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() > 0;
}
});
BorderLayoutPanel panel = JBUI.Panels.simplePanel();
panel.addToCenter(decorator.createPanel());
myCaptureVariables = new JCheckBox(DebuggerBundle.message("label.capture.configurable.capture.variables"));
panel.addToBottom(myCaptureVariables);
return panel;
}
Aggregations