List of usage examples for org.dom4j Element add
void add(Namespace namespace);
Namespace
to this element. From source file:cc.warlock.core.client.logging.LoggingConfiguration.java
License:Open Source License
public List<Element> getTopLevelElements() { Element logging = DocumentHelper.createElement("logging"); logging.addAttribute("enabled", enableLogging + ""); logging.addAttribute("format", logFormat); Element dir = DocumentHelper.createElement("dir"); logging.add(dir); dir.setText(logDirectory.getAbsolutePath()); return Arrays.asList(new Element[] { logging }); }
From source file:cc.warlock.core.client.settings.internal.ClientSettings.java
License:Open Source License
@Override protected void saveTo(List<Element> elements) { Element element = DocumentHelper.createElement("client-settings"); element.addAttribute("version", version + ""); element.addAttribute("client-id", client.getClientId()); elements.add(element);//from w w w . jav a2 s. c o m for (IConfigurationProvider provider : childProviders) { for (Element childElement : provider.getTopLevelElements()) { element.add(childElement); } } }
From source file:cc.warlock.core.client.settings.internal.HighlightConfigurationProvider.java
License:Open Source License
@Override protected void saveTo(List<Element> elements) { //System.out.println("Saving highlights"); Element highlightsElement = DocumentHelper.createElement("highlights"); for (IHighlightString string : highlights) { Element hElement = highlightsElement.addElement("highlight"); fillElement(hElement, string);/* w w w . j ava 2 s . com*/ createStyleElement(hElement, string.getStyle()); } for (Map.Entry<String, IWarlockStyle> entry : namedStyles.entrySet()) { highlightsElement.add(createStyleElement(entry.getValue())); } elements.add(highlightsElement); }
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.com elements.add(windows); }
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); }/*from www. j a va 2 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
protected void addScriptConfigElements(Element scriptConfig) { for (File dir : scriptDirectories) { Element dirElement = DocumentHelper.createElement("dir"); dirElement.setText(dir.getAbsolutePath()); scriptConfig.add(dirElement); }//from www .ja v a 2s. c o 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); }/* w ww .ja v a 2 s . c o m*/ } }
From source file:cc.warlock.rcp.configuration.GameViewConfiguration.java
License:Open Source License
public List<Element> getTopLevelElements() { ArrayList<Element> elements = new ArrayList<Element>(); Element gameView = DocumentHelper.createElement("game-view"); gameView.addAttribute("buffer", bufferLines + ""); gameView.addAttribute("suppressPrompt", suppressPrompt + ""); Element defaultColors = DocumentHelper.createElement("default-colors"); gameView.add(defaultColors); defaultColors.addAttribute("background", defaultBackground.toHexString()); defaultColors.addAttribute("foreground", defaultForeground.toHexString()); defaultColors.addAttribute("echo-background", defaultEchoBackground.toHexString()); defaultColors.addAttribute("echo-foreground", defaultEchoForeground.toHexString()); Element defaultFont = DocumentHelper.createElement("default-font"); gameView.add(defaultFont);/*from w w w . j a va2s.co m*/ defaultFont.addAttribute("face", defaultFontFace); defaultFont.addAttribute("size", defaultFontSize + ""); elements.add(gameView); return elements; }
From source file:ch.javasoft.xml.config.XmlConfig.java
License:BSD License
private static Document createDocument(Element configElement, String configName) { final Document doc = DocumentHelper.createDocument(); final Element configList = DocumentHelper.createElement(XmlElement.config_list.getXmlName()); configElement.addAttribute(XmlAttribute.name.getXmlName(), configName); configList.addAttribute(XmlAttribute.def.getXmlName(), configName); configList.add(configElement); doc.setRootElement(configList);/* w ww . j a v a 2 s. c o m*/ return doc; }
From source file:ch.javasoft.xml.config.XmlConfig.java
License:BSD License
@SuppressWarnings("unchecked") private void printUsageLines(PrintStream stream, Iterator<Element> usageChildIt) throws XmlConfigException { while (usageChildIt.hasNext()) { Element el = usageChildIt.next(); if (XmlUtil.isExpectedElementName(el, XmlElement.line)) { Element copy = el.createCopy(); List<Element> res = resolve(copy, XmlUtil.getElementPath(copy, true /*recurseParents*/)); for (Element r : res) { stream.println(r.attributeValue(XmlAttribute.value.getXmlName())); }// w ww .ja va2s .c om } else if (XmlUtil.isExpectedElementName(el, XmlElement.usage)) { Element parentCopy = el.getParent().createCopy(); Element copy = el.createCopy(); parentCopy.add(copy); List<Element> res = resolve(copy, XmlUtil.getElementPath(copy, true /*recurseParents*/)); for (Element r : res) { printUsageLines(stream, r.elementIterator()); } } } }