Search in sources :

Example 36 with Attribute

use of org.jdom.Attribute in project intellij-plugins by JetBrains.

the class FlexCompilerConfigFileUtilBase method makeLibrariesMergedIntoCode.

private static void makeLibrariesMergedIntoCode(final Element rootElement, final boolean externalLibs, final boolean includedLibs) {
    final Namespace namespace = rootElement.getNamespace();
    final Collection<String> paths = removeLibs(rootElement, externalLibs, includedLibs);
    if (!paths.isEmpty()) {
        final Element compilerElement = rootElement.getChild(COMPILER, namespace);
        Element libraryPathElement = compilerElement.getChild(LIBRARY_PATH, namespace);
        if (libraryPathElement == null) {
            libraryPathElement = new Element(LIBRARY_PATH, namespace);
            libraryPathElement.setAttribute(new Attribute(APPEND, "true"));
            compilerElement.addContent(libraryPathElement);
        }
        for (final String path : paths) {
            final Element pathElement = new Element(PATH_ELEMENT, namespace);
            pathElement.addContent(path);
            libraryPathElement.addContent(pathElement);
        }
    }
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element) Namespace(org.jdom.Namespace)

Example 37 with Attribute

use of org.jdom.Attribute in project intellij-plugins by JetBrains.

the class OsgiRunConfiguration method readExternal.

@Override
public void readExternal(final Element element) throws InvalidDataException {
    workingDir = element.getAttributeValue(WORKING_DIR_ATTRIBUTE);
    vmParameters = element.getAttributeValue(VM_PARAMETERS_ATTRIBUTE);
    programParameters = element.getAttributeValue(PROGRAM_PARAMETERS_ATTRIBUTE);
    includeAllBundlesInClassPath = Boolean.valueOf(element.getAttributeValue(INCLUDE_ALL_BUNDLES_IN_CLASS_PATH_ATTRIBUTE, "false"));
    useAlternativeJre = Boolean.valueOf(element.getAttributeValue(USE_ALTERNATIVE_JRE_ATTRIBUTE, "false"));
    alternativeJrePath = element.getAttributeValue(ALTERNATIVE_JRE_PATH, "");
    generateWorkingDir = Boolean.valueOf(element.getAttributeValue(GENERATE_WORKING_DIR_ATTRIBUTE));
    try {
        frameworkStartLevel = Integer.parseInt(element.getAttributeValue(FRAMEWORK_START_LEVEL, "1"));
    } catch (NumberFormatException e) {
        frameworkStartLevel = 1;
    }
    try {
        defaultStartLevel = Integer.parseInt(element.getAttributeValue(DEFAULT_START_LEVEL, "5"));
    } catch (NumberFormatException e) {
        defaultStartLevel = 5;
    }
    List<Element> children = element.getChildren(BUNDLE_ELEMENT);
    bundlesToDeploy.clear();
    for (Element child : children) {
        String name = child.getAttributeValue(NAME_ATTRIBUTE);
        String url = child.getAttributeValue(URL_ATTRIBUTE);
        String startLevel = child.getAttributeValue(START_LEVEL_ATTRIBUTE);
        String typeName = child.getAttributeValue(TYPE_ATTRIBUTE);
        SelectedBundle.BundleType type;
        try {
            type = SelectedBundle.BundleType.valueOf(typeName);
        } catch (IllegalArgumentException e) {
            LOG.error("unexpected bundle type '" + typeName + "'");
            type = SelectedBundle.BundleType.Module;
        }
        String path = url != null ? VfsUtilCore.urlToPath(url) : null;
        SelectedBundle selectedBundle = new SelectedBundle(type, name, path);
        if (startLevel != null) {
            try {
                selectedBundle.setStartLevel(Integer.parseInt(startLevel));
            } catch (NumberFormatException ignored) {
            }
        }
        String startAfterInstallationString = child.getAttributeValue(START_AFTER_INSTALLATION_ATTRIBUTE);
        if (startAfterInstallationString != null) {
            selectedBundle.setStartAfterInstallation(Boolean.parseBoolean(startAfterInstallationString));
        }
        bundlesToDeploy.add(selectedBundle);
    }
    // try to load the framework instance
    Element framework = element.getChild(FRAMEWORK_ELEMENT);
    if (framework != null) {
        String name = framework.getAttributeValue(INSTANCE_ATTRIBUTE);
        if (name != null) {
            ApplicationSettings settings = ServiceManager.getService(ApplicationSettings.class);
            instanceToUse = settings.getFrameworkInstance(name);
        }
    }
    Element additionalProperties = element.getChild(ADDITIONAL_PROPERTIES_ELEMENT);
    if (additionalProperties == null) {
        //noinspection SpellCheckingInspection
        additionalProperties = element.getChild("additinalProperties");
    }
    if (additionalProperties != null) {
        List<Attribute> attributes = additionalProperties.getAttributes();
        for (Attribute attribute : attributes) {
            this.additionalProperties.put(attribute.getName(), attribute.getValue());
        }
    }
    super.readExternal(element);
}
Also used : ApplicationSettings(org.osmorc.settings.ApplicationSettings) SelectedBundle(org.osmorc.run.ui.SelectedBundle) Attribute(org.jdom.Attribute) Element(org.jdom.Element)

Example 38 with Attribute

use of org.jdom.Attribute in project intellij-plugins by StepicOrg.

the class StudySerializationUtils method convertToThirdVersion.

public static Element convertToThirdVersion(@NotNull Element state) throws StudyUnrecognizedFormatException {
    Element stepManager = getStepManager(state);
    Element courseNode = getCourseNode(stepManager);
    removeOption(courseNode, DESCRIPTION);
    removeOption(courseNode, NAME);
    removeOption(courseNode, ID);
    removeOption(courseNode, ADAPTIVE);
    removeOption(stepManager, USER);
    List<Element> sectionNodes = getSectionNodes(stepManager);
    if (sectionNodes == null) {
        return state;
    }
    sectionNodes.forEach(sectionNode -> {
        removeOption(sectionNode, ID);
        removeOption(sectionNode, NAME);
        removeOption(sectionNode, POSITION);
    });
    sectionNodes.stream().map(sectionNode -> getListFieldWithNameOrNull(sectionNode, LESSON_NODES, LESSON_NODE_CLASS)).filter(Objects::nonNull).forEach(lessonNodes -> {
        lessonNodes.forEach(lessonNode -> {
            removeOption(lessonNode, ID);
            removeOption(lessonNode, NAME);
            removeOption(lessonNode, POSITION);
        });
        lessonNodes.stream().map(lessonNode -> getListFieldWithNameOrNull(lessonNode, STEP_NODES, STEP_NODE_CLASS)).filter(Objects::nonNull).forEach(stepNodes -> {
            stepNodes.forEach(stepNode -> {
                removeOption(stepNode, ID);
                removeOption(stepNode, NAME);
                removeOption(stepNode, POSITION);
                removeOption(stepNode, STEP_FILES);
                removeOption(stepNode, TEXT);
                removeOption(stepNode, TIME_LIMITS);
            });
            stepNodes.forEach(stepNode -> {
                Element currentLang = getFieldWithNameOrNull(stepNode, CURRENT_LANG);
                if (currentLang != null) {
                    Attribute currentLangValue = currentLang.getAttribute(VALUE);
                    replaceLanguage(currentLangValue);
                }
                Element limits = getFieldWithNameOrNull(stepNode, LIMITS);
                replaceLanguages(limits, MAP, ENTRY, KEY);
                Element supportedLanguages;
                supportedLanguages = getFieldWithNameOrNull(stepNode, SUPPORTED_LANGUAGES);
                replaceLanguages(supportedLanguages, LIST, OPTION, VALUE);
            });
        });
    });
    return state;
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element)

Example 39 with Attribute

use of org.jdom.Attribute in project intellij-plugins by StepicOrg.

the class StudySerializationUtils method getSectionNodes.

private static List<Element> getSectionNodes(@NotNull Element stepManager) throws StudyUnrecognizedFormatException {
    Element defaultLang = getFieldWithNameOrNull(stepManager, DEFAULT_LANG);
    if (defaultLang == null) {
        defaultLang = createField(stepManager, DEFAULT_LANG, INVALID);
    }
    Attribute defaultLangValue = defaultLang.getAttribute(VALUE);
    replaceLanguage(defaultLangValue);
    Element courseNode = getCourseNode(stepManager);
    return getListFieldWithNameOrNull(courseNode, SECTIONS_NODES, SECTION_NODE_CLASS);
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element)

Example 40 with Attribute

use of org.jdom.Attribute in project intellij-plugins by StepicOrg.

the class StudySerializationUtils method replaceLanguages.

private static void replaceLanguages(@Nullable Element collection, @NotNull String collectionType, @NotNull String itemType, @NotNull String valueAttrName) {
    if (collection != null) {
        Element items = collection.getChild(collectionType);
        if (items != null) {
            List<Element> itemList = items.getChildren(itemType);
            itemList.forEach(entry -> {
                Attribute value = entry.getAttribute(valueAttrName);
                replaceLanguage(value);
            });
        }
    }
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element)

Aggregations

Attribute (org.jdom.Attribute)40 Element (org.jdom.Element)30 DataConversionException (org.jdom.DataConversionException)6 ArrayList (java.util.ArrayList)4 Document (org.jdom.Document)3 SAXBuilder (org.jdom.input.SAXBuilder)3 NotNull (org.jetbrains.annotations.NotNull)3 PathMacrosImpl (com.intellij.application.options.PathMacrosImpl)2 PathMacroFilter (com.intellij.openapi.application.PathMacroFilter)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 EntityResolver (org.xml.sax.EntityResolver)2 AbstractColorsScheme (com.intellij.openapi.editor.colors.impl.AbstractColorsScheme)1 DefaultColorsScheme (com.intellij.openapi.editor.colors.impl.DefaultColorsScheme)1 SchemeImportException (com.intellij.openapi.options.SchemeImportException)1 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)1 ReplacementVariableDefinition (com.intellij.structuralsearch.ReplacementVariableDefinition)1 LwRootContainer (com.intellij.uiDesigner.lw.LwRootContainer)1 THashSet (gnu.trove.THashSet)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1