Example usage for org.jdom2 Element setAttribute

List of usage examples for org.jdom2 Element setAttribute

Introduction

In this page you can find the example usage for org.jdom2 Element setAttribute.

Prototype

public Element setAttribute(final String name, final String value) 

Source Link

Document

This sets an attribute value for this element.

Usage

From source file:de.relaunch64.popelganda.database.Settings.java

License:Open Source License

/**
 * This method creates all the settings-child-elements, but only, if they don't
 * already exist. We do this because when loading older settings-xml-document-structures,
 * we might have new elements that would not be initialised. but now we can call this 
 * method after loading the xml-document, and create elements and default values for all
 * new elements. This ensures compatibility to older/news settings-file-versions.
 */// w  w w .  j av  a2  s  .  c om
private void fillElements() {
    root = settingsFile.getRootElement();
    for (int cnt = 0; cnt < recentDocCount; cnt++) {
        // create field-identifier
        String fi = SETTING_RECENT_DOC + String.valueOf(cnt + 1);
        // retrieve content
        if (null == root.getChild(fi)) {
            // create a filepath-element
            Element el = new Element(fi);
            el.setText("");
            // and add it to the document
            root.addContent(el);
        }
    }
    if (null == root.getChild(SETTING_REOPEN_FILES)) {
        // create element for font
        Element el = new Element(SETTING_REOPEN_FILES);
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_MAINFONT)) {
        // create element for font
        Element el = new Element(SETTING_MAINFONT);
        root.addContent(el);
        el.setText(Font.MONOSPACED);
        el.setAttribute("size", "12");
    }
    if (null == root.getChild(SETTING_LAST_USED_PATH)) {
        // create element
        Element el = new Element(SETTING_LAST_USED_PATH);
        el.setText("");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_ANTIALIAS)) {
        // create element
        Element el = new Element(SETTING_ANTIALIAS);
        el.setText(AntiAlias.SUBPIXEL);
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_SIDEBAR_ISHIDDEN)) {
        // create element
        Element el = new Element(SETTING_SIDEBAR_ISHIDDEN);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_USE_NOTABS)) {
        // create element
        Element el = new Element(SETTING_USE_NOTABS);
        el.setText("0");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_FINDBYTYPE)) {
        // create element
        Element el = new Element(SETTING_FINDBYTYPE);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_WAITFORPROCESS)) {
        // create element
        Element el = new Element(SETTING_WAITFORPROCESS);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_CODE_FOLDING)) {
        // create element
        Element el = new Element(SETTING_CODE_FOLDING);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_CF_BRACES)) {
        // create element
        Element el = new Element(SETTING_CF_BRACES);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_CF_DIRECTIVES)) {
        // create element
        Element el = new Element(SETTING_CF_DIRECTIVES);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_CF_LABELS)) {
        // create element
        Element el = new Element(SETTING_CF_LABELS);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_CF_MANUAL)) {
        // create element
        Element el = new Element(SETTING_CF_MANUAL);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_CF_STRUCTS)) {
        // create element
        Element el = new Element(SETTING_CF_STRUCTS);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_CF_SECTIONS)) {
        // create element
        Element el = new Element(SETTING_CF_SECTIONS);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_SCALE_FONT)) {
        // create element
        Element el = new Element(SETTING_SCALE_FONT);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_CHECKUPDATES)) {
        // create element
        Element el = new Element(SETTING_CHECKUPDATES);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_FINDFIELDFOCUS)) {
        // create element
        Element el = new Element(SETTING_FINDFIELDFOCUS);
        el.setText("0");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_ALT_ASM_MODE)) {
        // create element
        Element el = new Element(SETTING_ALT_ASM_MODE);
        el.setText("0");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_SHOW_LINEHIGLIGHT)) {
        // create element
        Element el = new Element(SETTING_SHOW_LINEHIGLIGHT);
        el.setText("0");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_SHOW_BUFFERSIZE)) {
        // create element
        Element el = new Element(SETTING_SHOW_BUFFERSIZE);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_SHOW_EXT_IN_TAB)) {
        // create element
        Element el = new Element(SETTING_SHOW_EXT_IN_TAB);
        el.setText("0");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_SHOW_CLOSEBUTTON)) {
        // create element
        Element el = new Element(SETTING_SHOW_CLOSEBUTTON);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_SHOW_TOOLBAR)) {
        // create element
        Element el = new Element(SETTING_SHOW_TOOLBAR);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_SHOW_TOOLBARTEXT)) {
        // create element
        Element el = new Element(SETTING_SHOW_TOOLBARTEXT);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_SUGGEST_SORT_CASE)) {
        // create element
        Element el = new Element(SETTING_SUGGEST_SORT_CASE);
        el.setText("0");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_REOPEN_FILES_ON_STARTUP)) {
        // create element
        Element el = new Element(SETTING_REOPEN_FILES_ON_STARTUP);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_SAVEONCOMPILE)) {
        // create element
        Element el = new Element(SETTING_SAVEONCOMPILE);
        el.setText("1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_NIMBUS_ON_OSX)) {
        // create element
        Element el = new Element(SETTING_NIMBUS_ON_OSX);
        el.setText("0");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_USE_SCROLL_TABS)) {
        // create element
        Element el = new Element(SETTING_USE_SCROLL_TABS);
        el.setText("0");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_PREF_ASM)) {
        // create element
        Element el = new Element(SETTING_PREF_ASM);
        el.setText(String.valueOf(Assemblers.ASM_KICKASSEMBLER.getID()));
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_SIDEBAR_SORT)) {
        // create element
        Element el = new Element(SETTING_SIDEBAR_SORT);
        el.setText(String.valueOf(SORT_CASE));
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_SYNTAX_SCHEME)) {
        // create element
        Element el = new Element(SETTING_SYNTAX_SCHEME);
        el.setText(String.valueOf(ColorSchemes.SCHEME_DEFAULT));
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_LAST_SCRIPT)) {
        // create element
        Element el = new Element(SETTING_LAST_SCRIPT);
        el.setText("0");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_LOGSPLITLAYOUT)) {
        // create a filepath-element
        Element el = new Element(SETTING_LOGSPLITLAYOUT);
        el.setText(String.valueOf(JSplitPane.HORIZONTAL_SPLIT));
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_TABWIDTH)) {
        // create a filepath-element
        Element el = new Element(SETTING_TABWIDTH);
        el.setText("4");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_LISTGOTOINDEX)) {
        // create a filepath-element
        Element el = new Element(SETTING_LISTGOTOINDEX);
        el.setText("-1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_DIVIDER_LOCATION)) {
        // create a filepath-element
        Element el = new Element(SETTING_DIVIDER_LOCATION);
        el.setText("-1");
        // and add it to the document
        root.addContent(el);
    }
    if (null == root.getChild(SETTING_LINE_NUMBER_ALIGNMENT)) {
        // create a filepath-element
        Element el = new Element(SETTING_LINE_NUMBER_ALIGNMENT);
        el.setText(String.valueOf(Gutter.RIGHT));
        // and add it to the document
        root.addContent(el);
    }
}

From source file:de.relaunch64.popelganda.database.Settings.java

License:Open Source License

/**
 * Add a new recent document to the position {@code nr} in the list of recent documents.
 * @param nr the number of the requested recent document. use a value from 1 to {@link #recentDocCount recentDocCount}.
 * @param fp the filepath to the recently used document as string
 * @param assembler//from  w  ww.j av  a2s.  co m
 * @param userScript
 */
public void setRecentDoc(int nr, String fp, Assembler assembler, int userScript) {
    // check for valid parameter
    if (null == fp || -1 == nr) {
        return;
    }
    // retrieve element
    Element el = root.getChild(SETTING_RECENT_DOC + String.valueOf(nr));
    // if element does not exist, create new...
    if (null == el) {
        el = new Element(SETTING_RECENT_DOC + String.valueOf(nr));
        // and add it to the document
        root.addContent(el);
    }
    // add filepath
    el.setText(fp);
    el.setAttribute(REC_DOC_ASSEMBLER, String.valueOf(assembler.getID()));
    el.setAttribute(REC_DOC_SCRIPT, String.valueOf(userScript));
}

From source file:de.relaunch64.popelganda.database.Settings.java

License:Open Source License

public void setMainFont(Font f) {
    Element el = root.getChild(SETTING_MAINFONT);
    if (null == el) {
        el = new Element(SETTING_MAINFONT);
        root.addContent(el);//from w  w  w.j ava2  s.c  o m
    }
    el.setText(f.getName());
    el.setAttribute("size", String.valueOf(f.getSize()));
}

From source file:de.relaunch64.popelganda.database.Settings.java

License:Open Source License

public void setReopenFiles(EditorPanes ep) {
    Element el = root.getChild(SETTING_REOPEN_FILES);
    if (null == el) {
        el = new Element(SETTING_REOPEN_FILES);
        root.addContent(el);//ww  w.j  a  v  a2 s.  co  m
    }
    // remove existing content
    el.removeContent();
    // iterate all editorpanes and store file pathes
    for (int i = 0; i < ep.getCount(); i++) {
        // get file path and compiler settings of each file
        File fp = ep.getFilePath(i);
        int c = ep.getAssembler(i).getID();
        int s = ep.getScript(i);
        // save if exists
        if (fp != null && fp.exists()) {
            // create new child element
            Element child = new Element(SETTING_REOPEN_FILES_CHILD);
            // add path and compiler
            child.setText(fp.getAbsolutePath());
            child.setAttribute(ATTR_ASM, String.valueOf(c));
            child.setAttribute(ATTR_SCRIPT, String.valueOf(s));
            // add to database
            el.addContent(child);
        }
    }
}

From source file:de.smartics.maven.plugin.jboss.modules.xml.ModuleXmlBuilder.java

License:Apache License

private void addResources(ModuleDescriptor module, final Collection<Dependency> dependencies) {
    final Element resources = new Element("resources", NS);

    List<String> resourceRootsXml = module.getApplyToModule().getResourceRootsXml();
    for (final String xml : resourceRootsXml) {
        final Element element = xmlFragmentParser.parse(xml);
        resources.addContent(element);//  www . java 2s  .  c om
    }

    if (!dependencies.isEmpty()) {

        final List<SortElement> sorted = createSortedResources(dependencies);
        for (final SortElement element : sorted) {
            final Element resource = new Element("resource-root", NS);
            final String fileName = element.key;
            resource.setAttribute("path", fileName);
            resources.addContent(resource);
        }
    }

    if (!resources.getChildren().isEmpty()) {
        root.addContent(resources);
    }
}

From source file:de.smartics.maven.plugin.jboss.modules.xml.ModuleXmlBuilder.java

License:Apache License

private void addResolvedDependencies(final ModuleDescriptor module, final Collection<Dependency> dependencies,
        final Element dependenciesElement) {
    final Set<SortElement> sorted = createSortedDependencies(module, dependencies);

    final ApplyToDependencies apply = module.getApplyToDependencies();

    for (final SortElement element : sorted) {
        final String name = element.key;
        final Element moduleElement = new Element("module", NS);
        moduleElement.setAttribute("name", name);

        final DependenciesDescriptor dd = apply.getDescriptorThatMatches(name);

        if (isIncludableDependency(element, dd)) {
            handleOptional(element, moduleElement, dd);
            handleExport(moduleElement, dd);
            handleServices(moduleElement, dd);
            handleSlot(module, element, moduleElement);
            dependenciesElement.addContent(moduleElement);
        }/*from www  .ja  v  a 2s .  c o m*/
    }
}

From source file:de.smartics.maven.plugin.jboss.modules.xml.ModuleXmlBuilder.java

License:Apache License

private void handleOptional(final SortElement element, final Element moduleElement,
        final DependenciesDescriptor dd) {
    final Boolean ddOptional = dd.getOptional();
    if ((ddOptional != null && ddOptional) || (ddOptional == null || element.dependency.isOptional())) {
        moduleElement.setAttribute("optional", "true");
    }/* w  w  w  .  j av a  2  s.c o  m*/
}

From source file:de.smartics.maven.plugin.jboss.modules.xml.ModuleXmlBuilder.java

License:Apache License

private void handleExport(final Element moduleElement, final DependenciesDescriptor dd) {
    final Boolean ddExport = dd.getExport();
    if (ddExport != null && ddExport) {
        moduleElement.setAttribute("export", "true");
    }/* w w  w.  j  a v  a 2  s.  c om*/
}

From source file:de.smartics.maven.plugin.jboss.modules.xml.ModuleXmlBuilder.java

License:Apache License

private void handleServices(final Element moduleElement, final DependenciesDescriptor dd) {
    final String services = dd.getServices();
    if (services != null && !"none".equals(services)) {
        moduleElement.setAttribute("services", services);
    }/* w ww .  j  a  v  a2 s .c o  m*/
}

From source file:de.smartics.maven.plugin.jboss.modules.xml.ModuleXmlBuilder.java

License:Apache License

private void handleSlot(final ModuleDescriptor module, final SortElement element, final Element moduleElement) {
    final SlotStrategy slotStrategy = context.getSlotStrategy();
    final Dependency dependency = element.dependency;
    final String defaultSlot = calcDefaultSlot(module, dependency);
    final String slot = slotStrategy.calcSlot(dependency.getArtifact(), defaultSlot);
    if (!SlotStrategy.MAIN_SLOT.equals(slot)) {
        moduleElement.setAttribute("slot", slot);
    }/* w  w  w.  j av a 2  s .c  o  m*/
}