Search in sources :

Example 16 with Element

use of org.jdom.Element in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoRunConfigurationTestCase method doTestProducedConfigurations.

protected void doTestProducedConfigurations(@Nullable PsiElement context) {
    assertNotNull(context);
    ConfigurationContext configurationContext = new ConfigurationContext(context);
    List<ConfigurationFromContext> configurationAndSettings = configurationContext.getConfigurationsFromContext();
    Element configurationsElement = new Element("configurations");
    if (configurationAndSettings != null) {
        for (ConfigurationFromContext setting : configurationAndSettings) {
            try {
                RunConfiguration configuration = setting.getConfiguration();
                Element configurationElement = new Element("configurations");
                configurationElement.setAttribute("name", configuration.getName());
                configurationElement.setAttribute("class", configuration.getClass().getSimpleName());
                configuration.writeExternal(configurationElement);
                configurationsElement.addContent(configurationElement);
            } catch (WriteExternalException e) {
                throw new RuntimeException(e);
            }
        }
    }
    assertSameLinesWithFile(getTestDataPath() + "/" + getTestName(true) + ".xml", JDOMUtil.writeElement(configurationsElement));
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Example 17 with Element

use of org.jdom.Element in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoBuildTagsSettingsConverterProvider method createConverter.

@NotNull
@Override
public ProjectConverter createConverter(@NotNull ConversionContext context) {
    return new ProjectConverter() {

        private GoBuildTargetSettings newSettings;

        @NotNull
        private File getGoBuildFlagsFile() {
            return new File(context.getSettingsBaseDir(), "goBuildFlags.xml");
        }

        @Nullable
        @Override
        public ConversionProcessor<ProjectSettings> createProjectFileConverter() {
            return new ConversionProcessor<ProjectSettings>() {

                @Override
                public boolean isConversionNeeded(@NotNull ProjectSettings settings) {
                    Element oldSettings = JDomSerializationUtil.findComponent(settings.getRootElement(), "GoBuildFlags");
                    return oldSettings != null;
                }

                @Override
                public void process(@NotNull ProjectSettings settings) throws CannotConvertException {
                    Element oldSettings = JDomSerializationUtil.findComponent(settings.getRootElement(), "GoBuildFlags");
                    if (oldSettings != null) {
                        newSettings = XmlSerializer.deserialize(oldSettings, GoBuildTargetSettings.class);
                        oldSettings.detach();
                    }
                }
            };
        }

        @Override
        public Collection<File> getAdditionalAffectedFiles() {
            return Collections.singletonList(getGoBuildFlagsFile());
        }

        @Override
        public boolean isConversionNeeded() {
            return getGoBuildFlagsFile().exists();
        }

        @Override
        public void preProcessingFinished() throws CannotConvertException {
            File oldSettingsFile = getGoBuildFlagsFile();
            if (oldSettingsFile.exists()) {
                Element oldSettingsRoot = JDomConvertingUtil.loadDocument(oldSettingsFile).getRootElement();
                Element buildFlagsSettings = JDomSerializationUtil.findComponent(oldSettingsRoot, "GoBuildFlags");
                if (buildFlagsSettings != null) {
                    newSettings = XmlSerializer.deserialize(buildFlagsSettings, GoBuildTargetSettings.class);
                    buildFlagsSettings.detach();
                    //noinspection ResultOfMethodCallIgnored
                    oldSettingsFile.delete();
                }
            }
        }

        @Nullable
        @Override
        public ConversionProcessor<ModuleSettings> createModuleFileConverter() {
            return new ConversionProcessor<ModuleSettings>() {

                @Override
                public boolean isConversionNeeded(@NotNull ModuleSettings settings) {
                    return getGoBuildFlagsFile().exists();
                }

                @Override
                public void process(@NotNull ModuleSettings settings) throws CannotConvertException {
                    Element rootElement = settings.getRootElement();
                    Element goComponent = JDomSerializationUtil.findOrCreateComponentElement(rootElement, GoConstants.GO_MODULE_SESTTINGS_SERVICE_NAME);
                    Element buildTags = XmlSerializer.serialize(newSettings);
                    Element existingBuildTags = goComponent.getChild(buildTags.getName());
                    if (existingBuildTags != null) {
                        existingBuildTags.detach();
                    }
                    goComponent.addContent(buildTags);
                }
            };
        }
    };
}
Also used : Element(org.jdom.Element) GoBuildTargetSettings(com.goide.project.GoBuildTargetSettings) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with Element

use of org.jdom.Element in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoProjectModelConverterProvider method addProjectDirToLibraries.

private static void addProjectDirToLibraries(@NotNull File file, @NotNull Element rootElement) throws CannotConvertException {
    GoProjectLibrariesService librariesService = new GoProjectLibrariesService();
    librariesService.setLibraryRootUrls("file://$PROJECT_DIR$");
    Element componentElement = JDomSerializationUtil.findOrCreateComponentElement(rootElement, GoConstants.GO_LIBRARIES_SERVICE_NAME);
    XmlSerializer.serializeInto(librariesService.getState(), componentElement);
    saveFile(file, rootElement, "Cannot save libraries settings");
}
Also used : Element(org.jdom.Element) GoProjectLibrariesService(com.goide.project.GoProjectLibrariesService)

Example 19 with Element

use of org.jdom.Element in project nhin-d by DirectProject.

the class HumanReadableTextAssembler method assembleHtmlBody.

/**
   * This method will assemble html bounce message
   * 
   * @return bounce html message
   * @throws IOException
   */
protected String assembleHtmlBody(List<Address> rejectedRecipients, String errorMessage) throws IOException {
    List<UnescapedText> lstToUnescape = new ArrayList<UnescapedText>();
    Element html = new Element("html");
    Element body = new Element("body");
    html.addContent(body);
    {
        Element p = new Element("p");
        body.addContent(p);
        UnescapedText text = new UnescapedText(bounceHeader);
        lstToUnescape.add(text);
        p.addContent(text);
    }
    {
        Element p = new Element("p");
        body.addContent(p);
        p.setText(this.recipientsTitle);
        Element ul = new Element("ul");
        p.addContent(ul);
        for (Address address : rejectedRecipients) {
            Element li = new Element("li");
            ul.addContent(li);
            li.addContent(address.toString());
        }
    }
    {
        Element p = new Element("p");
        body.addContent(p);
        p.setText(this.errorMessageTitle);
        Element br = new Element("br");
        p.addContent(br);
        if ((errorMessage != null) && errorMessage.length() > 0) {
            p.addContent(errorMessage);
        } else {
            UnescapedText text = new UnescapedText(this.errorMessageDefault);
            lstToUnescape.add(text);
            p.addContent(text);
        }
    }
    {
        Element p = new Element("p");
        body.addContent(p);
        UnescapedText text = new UnescapedText(bounceFooter);
        lstToUnescape.add(text);
        p.addContent(text);
    }
    Document document = new Document(html);
    String randomStr;
    {
        // Determine which string indicator can be used to indicate that a
        // string should not be escaped.
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        XMLOutputter outputter = new NoEscapeXMLOutputter(Format.getPrettyFormat());
        outputter.output(document, byteArrayOutputStream);
        String htmlString = new String(byteArrayOutputStream.toByteArray());
        randomStr = getUniqueString();
        while (htmlString.indexOf(randomStr) > -1) {
            randomStr = getUniqueString();
        }
    }
    String htmlString;
    {
        for (UnescapedText unescapedText : lstToUnescape) {
            unescapedText.setUnescapedIndicator(randomStr);
        }
        XMLOutputter outputter = new UnescapedAwareXMLOutputter(Format.getPrettyFormat(), randomStr);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        outputter.output(document, byteArrayOutputStream);
        htmlString = new String(byteArrayOutputStream.toByteArray());
    }
    return htmlString;
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Address(javax.mail.Address) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.jdom.Document)

Example 20 with Element

use of org.jdom.Element in project symmetric-ds by JumpMind.

the class AbstractXmlPublisherExtensionPoint method toXmlElement.

protected void toXmlElement(DataEventType dml, Element xml, String catalogName, String schemaName, String tableName, String[] columnNames, String[] data, String[] keyNames, String[] keys) {
    Element row = new Element("row");
    xml.addContent(row);
    if (StringUtils.isNotBlank(catalogName)) {
        row.setAttribute("catalog", catalogName);
    }
    if (StringUtils.isNotBlank(schemaName)) {
        row.setAttribute("schema", schemaName);
    }
    row.setAttribute("entity", tableName);
    row.setAttribute("dml", dml.getCode());
    String[] colNames = null;
    if (data == null) {
        colNames = keyNames;
        data = keys;
    } else {
        colNames = columnNames;
    }
    for (int i = 0; i < data.length; i++) {
        String col = colNames[i];
        Element dataElement = new Element("data");
        row.addContent(dataElement);
        dataElement.setAttribute("key", col);
        if (data[i] != null) {
            dataElement.setText(replaceInvalidChars(data[i]));
        } else {
            dataElement.setAttribute("nil", "true", getXmlNamespace());
        }
    }
}
Also used : Element(org.jdom.Element) IExtensionPoint(org.jumpmind.extension.IExtensionPoint) INodeGroupExtensionPoint(org.jumpmind.symmetric.ext.INodeGroupExtensionPoint)

Aggregations

Element (org.jdom.Element)1236 NotNull (org.jetbrains.annotations.NotNull)103 Nullable (org.jetbrains.annotations.Nullable)98 IOException (java.io.IOException)81 ArrayList (java.util.ArrayList)76 List (java.util.List)70 VirtualFile (com.intellij.openapi.vfs.VirtualFile)67 Document (org.jdom.Document)67 File (java.io.File)64 JDOMException (org.jdom.JDOMException)53 PsiElement (com.intellij.psi.PsiElement)44 SAXBuilder (org.jdom.input.SAXBuilder)40 Attribute (org.jdom.Attribute)32 Iterator (java.util.Iterator)31 InvalidDataException (com.intellij.openapi.util.InvalidDataException)30 WriteExternalException (com.intellij.openapi.util.WriteExternalException)30 THashMap (gnu.trove.THashMap)30 XMLOutputter (org.jdom.output.XMLOutputter)27 JpsElement (org.jetbrains.jps.model.JpsElement)24 NonNls (org.jetbrains.annotations.NonNls)22