List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument(Element rootElement)
From source file:mesquite.lib.MesquiteXMLPreferencesModule.java
License:Open Source License
/** * Ideally this should not be static but since we don't always have control over the superclass, * make it available for classes that might otherwise not be able to use it due to inheritance * constraints/*from w ww.ja va 2 s .c o m*/ * @param provider * @param versionInt * @return */ public static String preparePreferencesForXML(PropertyNamesProvider provider, int versionInt) { String[] propertyNames = provider.getPreferencePropertyNames(); Element rootElement = DocumentHelper.createElement("mesquite"); Document preferencesDoc = DocumentHelper.createDocument(rootElement); preferencesDoc.setRootElement(rootElement); Element classElement = DocumentHelper.createElement(getShortClassName(provider.getClass())); rootElement.add(classElement); Element versionElement = DocumentHelper.createElement(VERSION); versionElement.setText("" + versionInt); classElement.add(versionElement); for (int i = 0; i < propertyNames.length; i++) { String currentPropertyName = propertyNames[i]; try { Object prefsContent = PropertyUtils.read(provider, currentPropertyName); if (prefsContent != null) { Element nextPrefsElement = DocumentHelper.createElement(PREFERENCE); nextPrefsElement.addAttribute(KEY, currentPropertyName); nextPrefsElement.add(DocumentHelper.createCDATA(prefsContent.toString())); classElement.add(nextPrefsElement); } } catch (Exception e) { MesquiteMessage.warnProgrammer("Could not read property value " + currentPropertyName + " for writing xml preferences on module: " + provider); } //nextPrefsElement.addContent(new CDATA()) } return XMLUtil.getDocumentAsXMLString(preferencesDoc); }
From source file:mesquite.lib.PhoneHomeUtil.java
License:Open Source License
public static void writePhoneRecords(String path, ListableVector phoneRecords) { if (StringUtil.blank(path)) return;//from w ww. ja va 2s .c o m Element mesquiteElement = DocumentHelper.createElement("mesquite"); Document doc = DocumentHelper.createDocument(mesquiteElement); Element phoneRecordElement = DocumentHelper.createElement("phoneRecords"); mesquiteElement.add(phoneRecordElement); Element versionElement = DocumentHelper.createElement("version"); versionElement.addText("1"); phoneRecordElement.add(versionElement); for (int i = 0; i < phoneRecords.size(); i++) { Element recordElement = DocumentHelper.createElement("record"); phoneRecordElement.add(recordElement); PhoneHomeRecord phoneRecord = (PhoneHomeRecord) phoneRecords.elementAt(i); Element element = DocumentHelper.createElement("module"); element.add(DocumentHelper.createCDATA(phoneRecord.getModuleName())); recordElement.add(element); MesquiteModuleInfo mmi = MesquiteTrunk.mesquiteModulesInfoVector.findModule(MesquiteModule.class, phoneRecord.getModuleName()); XMLUtil.addFilledElement(recordElement, "lastVersionUsed", MesquiteInteger.toString(phoneRecord.getLastVersionUsed())); XMLUtil.addFilledElement(recordElement, "lastNotice", MesquiteInteger.toString(phoneRecord.getLastNotice())); XMLUtil.addFilledElement(recordElement, "lastNoticeForMyVersion", MesquiteInteger.toString(phoneRecord.getLastNoticeForMyVersion())); XMLUtil.addFilledElement(recordElement, "lastVersionNoticed", MesquiteInteger.toString(phoneRecord.getLastVersionNoticed())); XMLUtil.addFilledElement(recordElement, "lastNewerVersionReported", MesquiteInteger.toString(phoneRecord.getLastNewerVersionReported())); } String xml = XMLUtil.getDocumentAsXMLString(doc); if (!StringUtil.blank(xml)) MesquiteFile.putFileContents(path, xml, true); }
From source file:mesquite.minimal.Simplicity.Simplicity.java
License:Open Source License
public void renameSettingsFile(int i, String newName) { if (!MesquiteInteger.isCombinable(i) || i < 0 || i >= InterfaceManager.settingsFiles.size()) return;/*from w w w . j av a 2 s . c o m*/ StringArray s = (StringArray) InterfaceManager.settingsFiles.elementAt(i); String path = s.getValue(PATH); String settingsXML = s.getValue(XML); Element root = XMLUtil.getRootXMLElementFromString("mesquite", settingsXML); if (root == null) return; Element element = root.element("simplicitySettings"); if (element != null) { Element versionElement = element.element("version"); if (versionElement == null) return; else { int version = MesquiteInteger.fromString(element.elementText("version")); boolean acceptableVersion = version == 1; if (acceptableVersion) { Element name = element.element("name"); Element settingsFile = DocumentHelper.createElement("mesquite"); Document doc = DocumentHelper.createDocument(settingsFile); Element hidden = DocumentHelper.createElement("simplicitySettings"); settingsFile.add(hidden); XMLUtil.addFilledElement(hidden, "version", "1"); XMLUtil.addFilledElement(hidden, "name", newName); Element hp = element.element("hiddenPackages"); element.remove(hp); hidden.add(hp); hp = element.element("hiddenMenuItems"); element.remove(hp); hidden.add(hp); hp = element.element("hiddenTools"); element.remove(hp); hidden.add(hp); s.setName(newName); MesquiteFile.putFileContents(path, XMLUtil.getDocumentAsXMLString(doc), false); } } } }
From source file:mesquite.minimal.Simplicity.Simplicity.java
License:Open Source License
public String makeSettingsFile(String name) { Element settingsFile = DocumentHelper.createElement("mesquite"); Document doc = DocumentHelper.createDocument(settingsFile); Element hidden = DocumentHelper.createElement("simplicitySettings"); settingsFile.add(hidden);//ww w . j ava2s . co m XMLUtil.addFilledElement(hidden, "version", "1"); XMLUtil.addFilledElement(hidden, "name", name); Element hiddenPkgs = DocumentHelper.createElement("hiddenPackages"); hidden.add(hiddenPkgs); for (int i = 0; i < InterfaceManager.hiddenPackages.size(); i++) { MesquiteString ms = (MesquiteString) InterfaceManager.hiddenPackages.elementAt(i); Element elem = DocumentHelper.createElement("package"); hiddenPkgs.add(elem); XMLUtil.addFilledElement(elem, "name", ms.getName()); } Element hiddenMs = DocumentHelper.createElement("hiddenMenuItems"); hidden.add(hiddenMs); for (int i = 0; i < InterfaceManager.hiddenMenuItems.size(); i++) { MenuVisibility mv = (MenuVisibility) InterfaceManager.hiddenMenuItems.elementAt(i); Element elem = DocumentHelper.createElement("menuItem"); hiddenMs.add(elem); XMLUtil.addFilledElement(elem, "label", mv.label); if (mv.arguments != null) XMLUtil.addFilledElement(elem, "arguments", mv.arguments); XMLUtil.addFilledElement(elem, "command", mv.command); XMLUtil.addFilledElement(elem, "commandableClass", mv.commandableClassName); XMLUtil.addFilledElement(elem, "dutyClass", mv.dutyClass); } Element hiddenT = DocumentHelper.createElement("hiddenTools"); hidden.add(hiddenT); for (int i = 0; i < InterfaceManager.hiddenTools.size(); i++) { MesquiteString s = (MesquiteString) InterfaceManager.hiddenTools.elementAt(i); Element elem = DocumentHelper.createElement("tool"); hiddenT.add(elem); XMLUtil.addFilledElement(elem, "name", s.getName()); XMLUtil.addFilledElement(elem, "description", s.getValue()); } return XMLUtil.getDocumentAsXMLString(doc); }
From source file:org.dom4j.samples.rule.SongFilter.java
License:Open Source License
public Document filtering(org.dom4j.Document doc) throws Exception { Element resultRoot = DocumentHelper.createElement("result"); this.resultDoc = DocumentHelper.createDocument(resultRoot); Rule songElementRule = new Rule(); songElementRule.setPattern(DocumentHelper.createPattern("/Songs/song/mp3/id3")); songElementRule.setAction(new SongElementBuilder()); Rule titleTextNodeFilter = new Rule(); titleTextNodeFilter.setPattern(DocumentHelper.createPattern("/Songs/song/mp3/id3/title")); titleTextNodeFilter.setAction(new NodeTextFilter()); this.style = new Stylesheet(); this.style.addRule(songElementRule); this.style.addRule(titleTextNodeFilter); style.run(doc);//from www. jav a2s .co m return this.resultDoc; }