List of usage examples for org.dom4j Element add
void add(Namespace namespace);
Namespace
to this element. From source file:de.ailis.wlandsuite.game.parts.Strings.java
License:Open Source License
/** * Returns the strings as XML.//from www .jav a 2 s . c om * * @return The strings as XML */ public Element toXml() { Element element, subElement; int stringNo; // Create the root XML element element = XmlUtils.createElement("strings"); // Add all the strings stringNo = 0; for (final String string : this) { // Create and append string element subElement = XmlUtils.createElement("string"); subElement.addAttribute("id", Integer.toString(stringNo)); subElement.addText(StringUtils.escape(string, "ASCII")); element.add(subElement); stringNo++; } // Return the XML element return element; }
From source file:de.ailis.wlandsuite.game.parts.TileMap.java
License:Open Source License
/** * Returns the tile map as XML./*from ww w . j a v a 2 s. co m*/ * * @param backgroundTile * The background tile for which ".." is printed * @return The tile map as XML */ public Element toXml(final int backgroundTile) { Element element; StringWriter text; PrintWriter writer; int mapSize; // Create the root element element = XmlUtils.createElement("tileMap"); if (this.unknown != 0) { element.addAttribute("unknown", StringUtils.toHex(this.unknown)); } // Determine the map size mapSize = this.map.length; // Write the tile map content text = new StringWriter(); writer = new PrintWriter(text); writer.println(); for (int y = 0; y < mapSize; y++) { writer.print(" "); for (int x = 0; x < mapSize; x++) { int b; if (x > 0) { writer.print(" "); } b = this.map[y][x]; if (b == backgroundTile) { writer.append(".."); } else { writer.format("%02x", new Object[] { b }); } } writer.println(); } writer.print(" "); element.add(DocumentHelper.createText(text.toString())); // Return the XML code return element; }
From source file:de.ailis.wlandsuite.game.parts.Unknown.java
License:Open Source License
/** * Returns the unknown data as XML./* w ww.j av a2s. c o m*/ * * @param elementName * The element name * @return The unknown data as XML */ public Element toXml(final String elementName) { Element element; StringWriter text; PrintWriter writer; element = XmlUtils.createElement(elementName); text = new StringWriter(); writer = new PrintWriter(text); writer.println(); writer.print(" "); for (int i = 0; i < this.bytes.length; i++) { if (i > 0) { if (i % 16 == 0) { writer.println(); } if ((i < this.bytes.length) && (i % 4 == 0)) { writer.print(" "); } else { writer.print(" "); } } writer.format("%02x", new Object[] { this.bytes[i] }); } writer.println(); writer.print(" "); element.add(DocumentHelper.createText(text.toString())); return element; }
From source file:de.innovationgate.utils.WGUtils.java
License:Apache License
/** * Sorts the child elements of an element based on their indiviual XPath * result. This utility method should be used instead of direct sorting of * the elements()-list of a parent element, since this will fail with * exception on most occasions./*from ww w. j a v a 2 s. c o m*/ * * @param parent * The parent element * @param xpath * The xpath that is evaluated on each child element */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static void sortChildElements(Element parent, String xpath) { // Create a copy of the elements list and sort it List list = new ArrayList(parent.elements()); DocumentHelper.sort(list, xpath); // Iterate over sorted list. Remove and add all in order Iterator it = list.iterator(); while (it.hasNext()) { Element element = (Element) it.next(); parent.remove(element); parent.add(element); } }
From source file:de.innovationgate.wga.common.WGAXML.java
License:Apache License
/** * add a default domain element to the given parentElement (<domains>) * @param parent//from w w w . j a va2s.c o m * @param domainName * @return the created domain element */ public static Element addDomain(Element parent, String domainName) { Element domain = DocumentFactory.getInstance().createElement("domain"); domain.addAttribute("name", domainName); domain.addAttribute("loginattempts", "5"); Element login = domain.addElement("login"); login.addAttribute("mode", "user"); login.addAttribute("username", ""); login.addAttribute("password", ""); domain.addElement("defaultdboptions"); domain.addElement("defaultpublisheroptions"); Element errorPage = domain.addElement("errorpage"); errorPage.addAttribute("enabled", "false"); parent.add(domain); return domain; }
From source file:de.innovationgate.wga.common.WGAXML.java
License:Apache License
/** * set the given information on the given domainElement * @param domainElement//from ww w .j a v a2 s.co m * @param domainName * @param loginMode valid values - (WGAXML.DOMAIN_LOGINMODE_USERLOGINS, WGAXML.DOMAIN_LOGINMODE_MASTERLOGIN) * @param masterLoginUsername * @param masterLoginPassword * @return the updated domainElement */ public static Element setBasicDomainInformation(Element domainElement, String domainName, String loginMode, String masterLoginUsername, String masterLoginPassword) { domainElement.addAttribute("name", domainName); Element login = (Element) domainElement.selectSingleNode("login"); if (login == null) { login = (Element) DocumentFactory.getInstance().createElement("login"); domainElement.add(login); } login.addAttribute("mode", loginMode); login.addAttribute("username", masterLoginUsername); login.addAttribute("password", Base64.encode(masterLoginPassword.getBytes())); return domainElement; }
From source file:de.innovationgate.wga.common.WGAXML.java
License:Apache License
/** * add a default database element to the given parentElement (<contentdbs>) * @param parent//from w w w . j a v a2 s. c o m * @param implClass * @return the created contentdb-element */ public static Element addContentDB(Element parent, String implClass) { DocumentFactory factory = DocumentFactory.getInstance(); Element database = factory.createElement("contentdb"); database.addAttribute("enabled", "true"); database.addAttribute("lazyconnect", "false"); Element elem = factory.createElement("type"); database.add(elem); elem.add(factory.createText(implClass)); elem = factory.createElement("dbkey"); database.add(elem); elem.add(factory.createText("(Enter database key here)")); elem = factory.createElement("dbpath"); database.add(elem); elem.add(factory.createText("(Enter database path here)")); elem = factory.createElement("title"); database.add(elem); elem = factory.createElement("domain"); database.add(elem); elem.add(factory.createText("default")); elem = factory.createElement("design"); database.add(elem); elem.addAttribute("provider", "none"); elem.addAttribute("mode", ""); elem.addAttribute("key", ""); elem = factory.createElement("dboptions"); database.add(elem); createDefaultDbOptions(elem); elem = factory.createElement("publisheroptions"); database.add(elem); createDefaultPublisherOptions(elem); database.add(factory.createElement("storedqueries")); database.add(factory.createElement("fieldmappings")); Element cache = database.addElement("cache"); cache.addAttribute("path", ""); cache.addAttribute("type", "de.innovationgate.wgpublisher.cache.WGACacheHSQLDB"); cache.addAttribute("maxpages", "3000"); //lucene config per db Element luceneDBConfig = factory.createElement("lucene"); luceneDBConfig.addAttribute("enabled", "false"); luceneDBConfig.addElement("itemrules"); LuceneIndexItemRule.addDefaultRule(luceneDBConfig); luceneDBConfig.addElement("filerules"); LuceneIndexFileRule.addDefaultRule(luceneDBConfig); database.add(luceneDBConfig); // Client restrictions Element clientrestrictions = database.addElement("clientrestrictions"); clientrestrictions.addAttribute("enabled", "false"); clientrestrictions.addElement("restrictions"); parent.add(database); return database; }
From source file:de.innovationgate.wga.common.WGAXML.java
License:Apache License
/** * copy a whole contentDB definition and inserts it as new db with the given key * @param contentDBElement The element to copy * @param newDBKey The new database key for the copy * @return new created contentDBElement//from w w w. j a v a 2s . c o m */ public static Element copyContentDB(Element contentDBElement, String newDBKey) { Element copy = (Element) contentDBElement.clone(); copy.selectSingleNode("dbkey").setText(newDBKey.toLowerCase()); Element contentdbs = contentDBElement.getParent(); contentdbs.add(copy); return copy; }
From source file:de.innovationgate.wga.common.WGAXML.java
License:Apache License
/** * add a default persDbElement to the given parentElement (<personalisationdbs>) * @param parent/* ww w.j a v a 2 s. c om*/ * @param implClass * @return the created persDbElement */ public static Element addPersDB(Element parent, String implClass) { DocumentFactory factory = DocumentFactory.getInstance(); Element database = factory.createElement("personalisationdb"); database.addAttribute("enabled", "true"); database.addAttribute("lazyconnect", "false"); Element elem = factory.createElement("type"); database.add(elem); elem.add(factory.createText(implClass)); elem = factory.createElement("dbpath"); database.add(elem); elem.add(factory.createText("(Enter database path here)")); elem = factory.createElement("domain"); database.add(elem); elem.add(factory.createText("default")); elem = factory.createElement("persconfig"); database.add(elem); elem.addAttribute("mode", "auto"); elem = factory.createElement("dboptions"); database.add(elem); createDefaultDbOptions(elem); elem = factory.createElement("publisheroptions"); database.add(elem); createDefaultPublisherOptions(elem); database.add(factory.createElement("userclasses")); parent.add(database); return database; }
From source file:de.innovationgate.wga.common.WGAXML.java
License:Apache License
/** * set the given information on the given persDbElement * @param persDbElement/*w ww .ja va2 s . c o m*/ * @param enabled * @param lazyConnect * @param dbImplClass * @param dbPath * @param mode - valid values (WGAXML.PERS_MODE_AUTO, WGAXML.PERS_MODE_LOGIN, WGAXML.PERS_MODE_CUSTOM) * @param statistics - valid values (WGAXML.PERS_STATISTICS_OFF, WGAXML.PERS_STATISTICS_SESSION, WGAXML.PERS_STATISTICS_HIT) * @param defaultLogin * @param username * @param password * @param domain * @return the updated persDbElement */ public static Element setBasicPersDBInformation(Element persDbElement, boolean enabled, boolean lazyConnect, String dbImplClass, String dbPath, String mode, String statistics, boolean defaultLogin, String username, String password, String domain) { persDbElement.addAttribute("enabled", String.valueOf(enabled)); persDbElement.addAttribute("lazyconnect", String.valueOf(lazyConnect)); persDbElement.selectSingleNode("type").setText(dbImplClass); persDbElement.selectSingleNode("dbpath").setText(dbPath); Element persconfig = (Element) persDbElement.selectSingleNode("persconfig"); persconfig.addAttribute("mode", mode); persconfig.addAttribute("statistics", statistics); Element login = (Element) persDbElement.selectSingleNode("login"); if (login == null) { login = (Element) DocumentFactory.getInstance().createElement("login"); persDbElement.add(login); } if (defaultLogin) { login.addAttribute("password", ""); login.addAttribute("username", ""); } else { login.addAttribute("password", Base64.encode(password.getBytes())); login.addAttribute("username", username); } login.addAttribute("encoding", "base64"); persDbElement.selectSingleNode("domain").setText(domain); return persDbElement; }