List of usage examples for org.dom4j DocumentHelper createElement
public static Element createElement(String name)
From source file:lost.tok.html.IndexPage.java
License:Open Source License
/** * Returns a list of either sources or roots as an html elements * If the list is empty, returns an empty div element instead * @param isRoot true if the list should be of roots * @return an html div element containing the entire list */// ww w . java2 s. co m public Element getSourcesElement(boolean genRoot) { Element main = DocumentHelper.createElement("div"); //$NON-NLS-1$ String listTitle = genRoot ? Messages.getString("IndexPage.Roots") //$NON-NLS-1$ : Messages.getString("IndexPage.Sources"); //$NON-NLS-1$ main.addElement("h2").addText(listTitle); //$NON-NLS-1$ int numItems = 0; // the number of items in the list Element rootsList = main.addElement("ul"); //$NON-NLS-1$ for (Source src : sources) { if (src.isRoot() != genRoot) continue; Element item = rootsList.addElement("li"); //$NON-NLS-1$ String srcPath = src.getFile().getProjectRelativePath().toString(); Element a = item.addElement("a"); //$NON-NLS-1$ SourcePage sPage = srcPathToPage.get(srcPath); a.addAttribute("href", getPathTo(sPage)); //$NON-NLS-1$ // a.addAttribute("tooltip", value) a.addText(src.getTitle()); item.addText(Messages.getString("IndexPage.by")); //$NON-NLS-1$ item.addElement("em").addText(src.getAuthor()); //$NON-NLS-1$ item.addText(" (" + srcPath + ")"); //$NON-NLS-1$ //$NON-NLS-2$ numItems++; } if (numItems > 0) return main; // else, we return an empty div return DocumentHelper.createElement("div"); //$NON-NLS-1$ }
From source file:lost.tok.html.IndexPage.java
License:Open Source License
/** * Returns a list of links to discussions, or empty div if no discussions exist * @return an html div element containing the entire list */// ww w .jav a2 s . c o m public Element getDiscussionElement() { Element main = DocumentHelper.createElement("div"); //$NON-NLS-1$ if (discussions.length == 0) return main; // empty div main.addElement("h2").addText(Messages.getString("IndexPage.Discussions")); //$NON-NLS-1$ //$NON-NLS-2$ Element rootsList = main.addElement("ul"); //$NON-NLS-1$ for (Discussion disc : discussions) { Element item = rootsList.addElement("li"); //$NON-NLS-1$ Element a = item.addElement("a"); //$NON-NLS-1$ DiscussionPage dPage = discNameToPage.get(disc.getDiscName()); a.addAttribute("href", getPathTo(dPage)); //$NON-NLS-1$ // TODO(Shay, low): Add a normal tooltip in the index page // a.addAttribute("tooltip", disc.getLinkType() ); a.addText(disc.getDiscName()); item.addText(Messages.getString("IndexPage.by")); //$NON-NLS-1$ item.addElement("em").addText(disc.getCreatorName()); //$NON-NLS-1$ item.addText(" (" + disc.getDiscFileName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } return main; }
From source file:lost.tok.html.Menu.java
License:Open Source License
/** Returns the html's div element of the menu */ public Element getMenuDiv() { //Element div = DocumentHelper.createElement("div"); Element script = DocumentHelper.createElement("script"); //$NON-NLS-1$ script.addAttribute("type", "text/javascript"); //$NON-NLS-1$ //$NON-NLS-2$ script.addComment(getDTreeCode());/*w w w. j av a2 s . co m*/ return script; }
From source file:mesquite.chromaseq.lib.ChromaseqInfoFile.java
License:Open Source License
public ChromaseqInfoFile() { rootElement = DocumentHelper.createElement("mesquite"); chromaseqElement = rootElement.addElement("chromaseq"); doc = DocumentHelper.createDocument(rootElement); chromaseqElement.addAttribute("version", "" + infoFileVersion); processedFolderElement = chromaseqElement.addElement("processedFolder"); }
From source file:mesquite.chromaseq.lib.SequenceProfile.java
License:Open Source License
public String getXML() { Element mesquiteElement = DocumentHelper.createElement("mesquite"); Document doc = DocumentHelper.createDocument(mesquiteElement); Element sequenceProfileElement = DocumentHelper.createElement("sequenceProfile"); mesquiteElement.add(sequenceProfileElement); XMLUtil.addFilledElement(sequenceProfileElement, "version", "1"); Element boundedByTokensElement = DocumentHelper.createElement("boundedByTokens"); sequenceProfileElement.add(boundedByTokensElement); XMLUtil.addFilledElement(boundedByTokensElement, "name", name); XMLUtil.addFilledElement(boundedByTokensElement, "description", DocumentHelper.createCDATA(description)); XMLUtil.addFilledElement(boundedByTokensElement, "location", DocumentHelper.createCDATA(location)); XMLUtil.addFilledElement(boundedByTokensElement, "moltype", DocumentHelper.createCDATA(moltype)); XMLUtil.addFilledElement(boundedByTokensElement, "productName", DocumentHelper.createCDATA(productName)); XMLUtil.addFilledElement(boundedByTokensElement, "seqIDSuffix", DocumentHelper.createCDATA(seqIDSuffix)); XMLUtil.addFilledElement(boundedByTokensElement, "gcode", DocumentHelper.createCDATA("" + gcode)); XMLUtil.addFilledElement(boundedByTokensElement, "note", DocumentHelper.createCDATA("" + note)); // XMLUtil.addFilledElement(boundedByTokensElement, "CDS",DocumentHelper.createCDATA(MesquiteBoolean.toTrueFalseString(CDS))); return XMLUtil.getDocumentAsXMLString(doc); }
From source file:mesquite.chromaseq.SampleAndPrimerFileNameParser.ChromFileNameParsing.java
License:Open Source License
public String getXML() { Element mesquiteElement = DocumentHelper.createElement("mesquite"); Document doc = DocumentHelper.createDocument(mesquiteElement); Element nameRules = DocumentHelper.createElement("chromFileNameParsingRules"); mesquiteElement.add(nameRules);//from w w w .ja v a 2s.co m XMLUtil.addFilledElement(nameRules, "version", "1"); Element boundedByTokensElement = DocumentHelper.createElement("boundedByTokens"); nameRules.add(boundedByTokensElement); XMLUtil.addFilledElement(boundedByTokensElement, "name", name); XMLUtil.addFilledElement(boundedByTokensElement, "sampleCodeFirst", MesquiteBoolean.toTrueFalseString(sampleCodeFirst)); XMLUtil.addFilledElement(boundedByTokensElement, "dnaCodeStartToken", DocumentHelper.createCDATA(dnaCodeStartToken)); XMLUtil.addFilledElement(boundedByTokensElement, "dnaCodeEndToken", DocumentHelper.createCDATA(dnaCodeEndToken)); XMLUtil.addFilledElement(boundedByTokensElement, "dnaCodeSuffixToken", DocumentHelper.createCDATA(dnaCodeSuffixToken)); XMLUtil.addFilledElement(boundedByTokensElement, "dnaCodeRemovalToken", DocumentHelper.createCDATA(dnaCodeRemovalToken)); XMLUtil.addFilledElement(boundedByTokensElement, "primerStartToken", DocumentHelper.createCDATA(primerStartToken)); XMLUtil.addFilledElement(boundedByTokensElement, "primerEndToken", DocumentHelper.createCDATA(primerEndToken)); return XMLUtil.getDocumentAsXMLString(doc); }
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. j a v a 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 . j a v a 2 s . com 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.lib.XMLUtil.java
License:Open Source License
public static Element addFilledElement(Element containingElement, String name, String content) { if (content == null || name == null) return null; Element element = DocumentHelper.createElement(name); element.addText(content);//from www. j av a 2 s . co m containingElement.add(element); return element; }
From source file:mesquite.lib.XMLUtil.java
License:Open Source License
public static Element addFilledElement(Element containingElement, String name, CDATA cdata) { if (cdata == null || name == null) return null; Element element = DocumentHelper.createElement(name); element.add(cdata);//from ww w .ja va2s . co m containingElement.add(element); return element; }