Search in sources :

Example 11 with Document

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();
}
Also used : XPath(org.jdom.xpath.XPath) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) Document(org.jdom.Document) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException)

Example 12 with Document

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));
}
Also used : XPath(org.jdom.xpath.XPath) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) StringReader(java.io.StringReader) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with Document

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;
}
Also used : XPath(org.jdom.xpath.XPath) XPathFunction(org.intellij.lang.xpath.psi.XPathFunction) XsltElement(org.intellij.lang.xpath.xslt.psi.XsltElement) XsltElement(org.intellij.lang.xpath.xslt.psi.XsltElement) LightElement(com.intellij.psi.impl.light.LightElement) Element(org.jdom.Element) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) IncorrectOperationException(com.intellij.util.IncorrectOperationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with Document

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);
            }
        }
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) Document(org.jdom.Document) InvalidDataException(com.intellij.openapi.util.InvalidDataException) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Example 15 with Document

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;
}
Also used : JVMNameUtil(com.intellij.debugger.engine.JVMNameUtil) JavaDebuggerSupport(com.intellij.debugger.ui.JavaDebuggerSupport) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) Document(org.jdom.Document) Nls(org.jetbrains.annotations.Nls) BorderLayoutPanel(com.intellij.util.ui.components.BorderLayoutPanel) JBUI(com.intellij.util.ui.JBUI) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper) FileTypes(com.intellij.openapi.fileTypes.FileTypes) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) FileChooserFactory(com.intellij.openapi.fileChooser.FileChooserFactory) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Debugger(org.jetbrains.annotations.Debugger) AnnotatedElementsSearch(com.intellij.psi.search.searches.AnnotatedElementsSearch) StreamEx(one.util.streamex.StreamEx) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Registry(com.intellij.openapi.util.registry.Registry) IntStreamEx(one.util.streamex.IntStreamEx) com.intellij.psi(com.intellij.psi) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) XmlSerializer(com.intellij.util.xmlb.XmlSerializer) ArrayUtil(com.intellij.util.ArrayUtil) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) TableColumnModel(javax.swing.table.TableColumnModel) ArrayList(java.util.ArrayList) JDOMUtil(com.intellij.openapi.util.JDOMUtil) AbstractTableModel(javax.swing.table.AbstractTableModel) Project(com.intellij.openapi.project.Project) DebuggerBundle(com.intellij.debugger.DebuggerBundle) PlatformIcons(com.intellij.util.PlatformIcons) DecompiledLocalVariable(com.intellij.debugger.jdi.DecompiledLocalVariable) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) StringUtil(com.intellij.openapi.util.text.StringUtil) ItemRemovable(com.intellij.util.ui.ItemRemovable) JBTable(com.intellij.ui.table.JBTable) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Element(org.jdom.Element) FileChooser(com.intellij.openapi.fileChooser.FileChooser) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Element(org.jdom.Element) TableColumnModel(javax.swing.table.TableColumnModel) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Document(org.jdom.Document) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) List(java.util.List) ArrayList(java.util.ArrayList) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) BorderLayoutPanel(com.intellij.util.ui.components.BorderLayoutPanel) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ConfigurationException(com.intellij.openapi.options.ConfigurationException) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Document (org.jdom.Document)90 Element (org.jdom.Element)67 IOException (java.io.IOException)40 SAXBuilder (org.jdom.input.SAXBuilder)40 JDOMException (org.jdom.JDOMException)24 File (java.io.File)16 XMLOutputter (org.jdom.output.XMLOutputter)16 ArrayList (java.util.ArrayList)13 List (java.util.List)12 StringReader (java.io.StringReader)10 XPath (org.jdom.xpath.XPath)10 Format (org.jdom.output.Format)9 StringWriter (java.io.StringWriter)8 InputStream (java.io.InputStream)7 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)7 Writer (java.io.Writer)5 URL (java.net.URL)5 JDOMUtil.loadDocument (com.intellij.openapi.util.JDOMUtil.loadDocument)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4