Example usage for org.dom4j DocumentHelper createElement

List of usage examples for org.dom4j DocumentHelper createElement

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createElement.

Prototype

public static Element createElement(String name) 

Source Link

Usage

From source file:cc.warlock.core.client.settings.internal.IgnoreConfigurationProvider.java

License:Open Source License

@Override
protected void saveTo(List<Element> elements) {
    Element ignoresElement = DocumentHelper.createElement("ignores");

    for (IIgnore ignore : ignores) {
        Element iElement = ignoresElement.addElement("ignore");
        fillElement(iElement, ignore);/*from  w w  w. j a  v  a  2s .  co m*/
    }

    elements.add(ignoresElement);
}

From source file:cc.warlock.core.client.settings.internal.TriggerConfigurationProvider.java

License:Open Source License

@Override
protected void saveTo(List<Element> elements) {
    Element triggersElement = DocumentHelper.createElement("triggers");

    for (ITrigger trigger : triggers) {
        Element tElement = triggersElement.addElement("trigger");
        fillElement(tElement, trigger);//from   w w w . j a  v  a2s .c o m

        elements.add(tElement);
    }

    elements.add(triggersElement);
}

From source file:cc.warlock.core.client.settings.internal.VariableConfigurationProvider.java

License:Open Source License

@Override
protected void saveTo(List<Element> elements) {
    Element varsElement = DocumentHelper.createElement("variables");

    for (Map.Entry<String, IVariable> entry : variables.entrySet()) {
        Element element = varsElement.addElement("variable");
        element.addAttribute("id", entry.getKey());
        element.addText(entry.getValue().getValue());

    }/*from w  w w .  j  a  v  a 2 s  .  c  o m*/
    elements.add(varsElement);
}

From source file:cc.warlock.core.client.settings.internal.WindowSettingsConfigurationProvider.java

License:Open Source License

@Override
protected void saveTo(List<Element> elements) {
    Element windows = DocumentHelper.createElement("windows");

    for (IWindowSettings settings : windowSettings) {
        Element window = windows.addElement("window");
        window.addAttribute("id", settings.getId());
        window.addAttribute("background", colorString(settings.getBackgroundColor()));
        window.addAttribute("foreground", colorString(settings.getForegroundColor()));

        window.add(fontToElement(settings.getFont(), "font"));
        window.add(fontToElement(settings.getColumnFont(), "columnFont"));
    }/*from   ww  w . j a v  a  2 s .co m*/

    elements.add(windows);
}

From source file:cc.warlock.core.client.settings.macro.internal.MacroConfigurationProvider.java

License:Open Source License

@Override
protected void saveTo(List<Element> elements) {
    Element macrosElement = DocumentHelper.createElement("macros");
    for (IMacro macro : macros) {
        if (macro.getHandlers().size() == 1) {

            IMacroHandler first = macro.getHandlers().iterator().next();
            if (first instanceof CommandMacroHandler) {
                CommandMacroHandler handler = (CommandMacroHandler) first;

                Element mElement = macrosElement.addElement("macro");
                mElement.addAttribute("command", handler.getCommand());
                mElement.addAttribute("keycode", macro.getKeyCode() + "");
                mElement.addAttribute("modifiers", macro.getModifiers() + "");
            }/* w w w.j a  va 2  s  . c o m*/
        }
    }

    elements.add(macrosElement);
}

From source file:cc.warlock.core.configuration.WarlockConfiguration.java

License:Open Source License

public void save() {
    Document document = DocumentHelper.createDocument();
    Element warlockConfig = DocumentHelper.createElement("warlock-config");

    document.setRootElement(warlockConfig);

    for (IConfigurationProvider provider : providers) {
        List<Element> elements = provider.getTopLevelElements();

        for (Element element : elements) {
            warlockConfig.add(element);/* w  ww  .j  av  a2  s  .c  o m*/
        }
    }

    for (Element unhandled : unhandledElements) {
        // Make sure to resave unhandled elements, just in case the corresponding handler wasn't instantiated
        warlockConfig.add(unhandled.createCopy());
    }

    try {
        if (configFile.exists()) {
            File backupFile = new File(configFile.getPath() + ".bak");
            if (backupFile.exists())
                backupFile.renameTo(new File(backupFile.getPath() + ".1"));
            configFile.renameTo(backupFile);
        }
        OutputFormat format = OutputFormat.createPrettyPrint();
        FileOutputStream stream = new FileOutputStream(configFile);
        XMLWriter writer = new XMLWriter(stream, format);
        writer.write(document);
        stream.close();

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:cc.warlock.core.script.configuration.ScriptConfiguration.java

License:Open Source License

public List<Element> getTopLevelElements() {
    ArrayList<Element> elements = new ArrayList<Element>();

    Element scriptConfig = DocumentHelper.createElement("script-config");
    elements.add(scriptConfig);/*from www.j a v  a 2  s  .co m*/

    addScriptConfigElements(scriptConfig);

    return elements;
}

From source file:cc.warlock.core.script.configuration.ScriptConfiguration.java

License:Open Source License

protected void addScriptConfigElements(Element scriptConfig) {
    for (File dir : scriptDirectories) {
        Element dirElement = DocumentHelper.createElement("dir");
        dirElement.setText(dir.getAbsolutePath());

        scriptConfig.add(dirElement);/*  w w  w  .  j  a  v  a 2 s  .co m*/
    }

    Element autoScanElement = DocumentHelper.createElement("autoScan");
    autoScanElement.addAttribute("timeout", "" + scanTimeout.get());
    autoScanElement.setText(autoScan.get() + "");
    scriptConfig.add(autoScanElement);

    Element suppressExceptionsElement = DocumentHelper.createElement("suppressExceptions");
    suppressExceptionsElement.setText(suppressExceptions.get() + "");
    scriptConfig.add(suppressExceptionsElement);

    Element scriptPrefixElement = DocumentHelper.createElement("script-prefix");
    scriptPrefixElement.setText(scriptPrefix);
    scriptConfig.add(scriptPrefixElement);

    addEngineExtensionsConfig(scriptConfig);
}

From source file:cc.warlock.core.script.configuration.ScriptConfiguration.java

License:Open Source License

protected void addEngineExtensionsConfig(Element scriptConfig) {
    for (Map.Entry<String, ArrayList<String>> entry : engineExtensions.entrySet()) {
        Element engineElement = DocumentHelper.createElement("engine-file-extensions");
        engineElement.addAttribute("engineId", entry.getKey());
        scriptConfig.add(engineElement);

        for (String extension : entry.getValue()) {
            Element extElement = DocumentHelper.createElement("extension");
            extElement.setText(extension);
            engineElement.add(extElement);
        }//from   www. ja  v a  2s .c om
    }
}

From source file:cc.warlock.core.stormfront.ProfileConfiguration.java

License:Open Source License

public List<Element> getTopLevelElements() {
    ArrayList<Element> elements = new ArrayList<Element>();

    for (Account account : accounts.values()) {
        Element aElement = DocumentHelper.createElement("account");
        aElement.addAttribute("name", account.getAccountName());
        aElement.addAttribute("password", Account.encryptPassword(account.getPassword()));

        for (Profile profile : account.getProfiles()) {
            Element pElement = aElement.addElement("profile");
            pElement.addAttribute("id", profile.getId());
            pElement.addAttribute("name", profile.getName());
            pElement.addAttribute("gameCode", profile.getGameCode());
            pElement.addAttribute("gameName", profile.getGameName());
        }/*from  ww  w  .j av  a2  s. c om*/
        elements.add(aElement);
    }
    return elements;
}