Search in sources :

Example 91 with Document

use of org.jdom.Document 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);
    }
}
Also used : JavaModuleType(com.intellij.openapi.module.JavaModuleType) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) File(java.io.File)

Example 92 with Document

use of org.jdom.Document in project intellij-community by JetBrains.

the class EclipseUserLibrariesHelper method appendProjectLibraries.

public static void appendProjectLibraries(final Project project, @Nullable final File userLibrariesFile) throws IOException {
    if (userLibrariesFile == null)
        return;
    if (userLibrariesFile.exists() && !userLibrariesFile.isFile())
        return;
    final File parentFile = userLibrariesFile.getParentFile();
    if (parentFile == null)
        return;
    if (!parentFile.isDirectory()) {
        if (!parentFile.mkdir())
            return;
    }
    final Element userLibsElement = new Element("eclipse-userlibraries");
    final List<Library> libraries = new ArrayList<>(Arrays.asList(ProjectLibraryTable.getInstance(project).getLibraries()));
    ContainerUtil.addAll(libraries, LibraryTablesRegistrar.getInstance().getLibraryTable().getLibraries());
    for (Library library : libraries) {
        Element libElement = new Element("library");
        libElement.setAttribute("name", library.getName());
        writeUserLibrary(library, libElement);
        userLibsElement.addContent(libElement);
    }
    JDOMUtil.writeDocument(new Document(userLibsElement), userLibrariesFile, "\n");
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) Library(com.intellij.openapi.roots.libraries.Library) Document(org.jdom.Document) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 93 with Document

use of org.jdom.Document in project zaproxy by zaproxy.

the class DriverConfiguration method write.

public void write() {
    final Document doc = new Document();
    final Element root = new Element("driverConfiguration");
    doc.addContent(root);
    for (int i = 0; i < names.size(); i++) {
        final Element driver = new Element("driver");
        root.addContent(driver);
        final Element name = new Element("name");
        driver.addContent(name);
        name.addContent(names.get(i));
        final Element path = new Element("path");
        driver.addContent(path);
        path.addContent(paths.get(i));
        final Element slot = new Element("slot");
        driver.addContent(slot);
        slot.addContent(slots.get(i).toString());
        final Element slotListIndex = new Element("slotListIndex");
        driver.addContent(slotListIndex);
        slotListIndex.addContent(slotListIndexes.get(i).toString());
    }
    try {
        final OutputStream fileOutputStream = new BufferedOutputStream(new FileOutputStream(file));
        final XMLOutputter out = new XMLOutputter();
        out.output(doc, fileOutputStream);
        fileOutputStream.close();
    } catch (final FileNotFoundException e) {
        JOptionPane.showMessageDialog(null, new String[] { "Error accessing key store: ", e.toString() }, "Error", JOptionPane.ERROR_MESSAGE);
        logger.error(e.getMessage(), e);
    } catch (final IOException e) {
        JOptionPane.showMessageDialog(null, new String[] { "Error accessing key store: ", e.toString() }, "Error", JOptionPane.ERROR_MESSAGE);
        logger.error(e.getMessage(), e);
    }
    setChanged();
    notifyObservers();
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Element(org.jdom.Element) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.jdom.Document) BufferedOutputStream(java.io.BufferedOutputStream)

Example 94 with Document

use of org.jdom.Document in project intellij-community by JetBrains.

the class TaskSettingsTest method testCarriageReturnInFormat.

public void testCarriageReturnInFormat() throws Exception {
    TaskRepository repository = new YouTrackRepository();
    String format = "foo \n bar";
    repository.setCommitMessageFormat(format);
    ((TaskManagerImpl) myTaskManager).setRepositories(Collections.singletonList(repository));
    TaskManagerImpl.Config config = ((TaskManagerImpl) myTaskManager).getState();
    Element element = XmlSerializer.serialize(config);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    JDOMUtil.writeDocument(new Document(element), stream, "\n");
    Element element1 = JDOMUtil.load(new ByteArrayInputStream(stream.toByteArray()));
    TaskManagerImpl.Config deserialize = XmlSerializer.deserialize(element1, TaskManagerImpl.Config.class);
    ((TaskManagerImpl) myTaskManager).loadState(deserialize);
    TaskRepository[] repositories = myTaskManager.getAllRepositories();
    assertEquals(format, repositories[0].getCommitMessageFormat());
}
Also used : YouTrackRepository(com.intellij.tasks.youtrack.YouTrackRepository) ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.jdom.Element) TaskManagerImpl(com.intellij.tasks.impl.TaskManagerImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.jdom.Document)

Example 95 with Document

use of org.jdom.Document in project intellij-community by JetBrains.

the class XsltDocumentationProvider method getDocumentationDocument.

private Document getDocumentationDocument() throws IOException, JDOMException {
    Document d = com.intellij.reference.SoftReference.dereference(myDocument);
    if (d == null) {
        d = new SAXBuilder().build(XsltSupport.class.getResource("resources/documentation.xml"));
        myDocument = new SoftReference<>(d);
    }
    return d;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Document(org.jdom.Document)

Aggregations

Document (org.jdom.Document)144 Element (org.jdom.Element)102 SAXBuilder (org.jdom.input.SAXBuilder)51 IOException (java.io.IOException)49 JDOMException (org.jdom.JDOMException)29 File (java.io.File)27 ArrayList (java.util.ArrayList)22 XMLOutputter (org.jdom.output.XMLOutputter)22 List (java.util.List)16 StringReader (java.io.StringReader)15 Format (org.jdom.output.Format)12 VCDocument (org.vcell.util.document.VCDocument)11 XPath (org.jdom.xpath.XPath)10 StringWriter (java.io.StringWriter)9 InputStream (java.io.InputStream)8 URL (java.net.URL)8 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)7 FileNotFoundException (java.io.FileNotFoundException)5 Writer (java.io.Writer)5