List of usage examples for org.dom4j Element addText
Element addText(String text);
Text
node with the given text to this element. From source file:de.xaniox.heavyspleef.flag.presets.ItemStackFlag.java
License:Open Source License
static void serializeObject(Object value, Element element) { element.addAttribute("type", value.getClass().getName()); if (value instanceof Collection<?>) { Collection<?> collection = (Collection<?>) value; Iterator<?> iterator = collection.iterator(); while (iterator.hasNext()) { Object val = iterator.next(); Element valElement = element.addElement("entry"); serializeObject(val, valElement); }/*from w ww .j a va 2s.co m*/ } else { element.addText(value.toString()); } }
From source file:de.xaniox.heavyspleef.flag.presets.LocationFlag.java
License:Open Source License
@Override public void marshal(Element element) { Element worldElement = element.addElement("world"); Element xElement = element.addElement("x"); Element yElement = element.addElement("y"); Element zElement = element.addElement("z"); Location value = getValue();/*from w w w .ja v a 2 s .com*/ Validate.notNull(value, "getValue() cannot be null when marshalling flag value"); worldElement.addText(value.getWorld().getName()); xElement.addText(String.valueOf(value.getX())); yElement.addText(String.valueOf(value.getY())); zElement.addText(String.valueOf(value.getZ())); if (value.getYaw() != 0f) { element.addElement("yaw").addText(String.valueOf(value.getYaw())); } if (value.getPitch() != 0f) { element.addElement("pitch").addText(String.valueOf(value.getPitch())); } }
From source file:de.xaniox.heavyspleef.flag.presets.LocationListFlag.java
License:Open Source License
@Override public void marshalListItem(Element element, Location item) { Element worldElement = element.addElement("world"); Element xElement = element.addElement("x"); Element yElement = element.addElement("y"); Element zElement = element.addElement("z"); worldElement.addText(item.getWorld().getName()); xElement.addText(String.valueOf(item.getX())); yElement.addText(String.valueOf(item.getY())); zElement.addText(String.valueOf(item.getZ())); if (item.getYaw() != 0f) { element.addElement("yaw").addText(String.valueOf(item.getYaw())); }// www. jav a2 s .c om if (item.getPitch() != 0f) { element.addElement("pitch").addText(String.valueOf(item.getPitch())); } }
From source file:dk.netarkivet.harvester.datamodel.H1HeritrixTemplate.java
License:Open Source License
/** * Method to add a list of crawler traps with a given element name. It is used both to add per-domain traps and * global traps.//from ww w .jav a 2s . c o m * * @param elementName The name of the added element. * @param crawlerTraps A list of crawler trap regular expressions to add to this job. */ @SuppressWarnings("unchecked") public static void editOrderXMLAddCrawlerTraps(Document orderXMLdoc, String elementName, List<String> crawlerTraps) { if (crawlerTraps.size() == 0) { return; } // Get the node to update // If there is an acceptIfPrerequisite decideRule in the template, crawler traps should be // placed before (cf. issue NAS-2205) // If no such rule exists then we append the crawler traps as to the existing decideRuleds. Node rulesMapNode = orderXMLdoc.selectSingleNode(DECIDERULES_MAP_XPATH); if (rulesMapNode == null || !(rulesMapNode instanceof Element)) { throw new IllegalState("Unable to update order.xml document. It does not have the right form to add" + "crawler trap deciderules."); } Element rulesMap = (Element) rulesMapNode; // Create the root node and append it top existing rules Element decideRule = rulesMap.addElement("newObject"); // If an acceptiIfPrerequisite node exists, detach and insert before it Node acceptIfPrerequisiteNode = orderXMLdoc.selectSingleNode(DECIDERULES_ACCEPT_IF_PREREQUISITE_XPATH); if (acceptIfPrerequisiteNode != null) { List<Node> elements = rulesMap.elements(); int insertPosition = elements.indexOf(acceptIfPrerequisiteNode); decideRule.detach(); elements.add(insertPosition, decideRule); } else { rulesMap.elements().size(); } // Add all regexps in the list to a single MatchesListRegExpDecideRule decideRule.addAttribute("name", elementName); decideRule.addAttribute("class", Heritrix1Constants.MATCHESLISTREGEXPDECIDERULE_CLASSNAME); Element decision = decideRule.addElement("string"); decision.addAttribute("name", "decision"); decision.addText("REJECT"); Element listlogic = decideRule.addElement("string"); listlogic.addAttribute("name", "list-logic"); listlogic.addText("OR"); Element regexpList = decideRule.addElement("stringList"); regexpList.addAttribute("name", "regexp-list"); for (String trap : crawlerTraps) { regexpList.addElement("string").addText(trap); } }
From source file:dk.netarkivet.harvester.datamodel.H1HeritrixTemplate.java
License:Open Source License
@Override public void insertCrawlerTraps(String elementName, List<String> crawlerTraps) { if (crawlerTraps.size() == 0) { return;/* ww w . jav a2 s . c o m*/ } //System.out.println("Calling insertCrawlerTraps(String elementName, List<String> crawlerTraps) "); // Get the node to update // If there is an acceptIfPrerequisite decideRule in the template, crawler traps should be // placed before (cf. issue NAS-2205) // If no such rule exists then we append the crawler traps as to the existing decideRuleds. Node rulesMapNode = template.selectSingleNode(DECIDERULES_MAP_XPATH); if (rulesMapNode == null || !(rulesMapNode instanceof Element)) { throw new IllegalState("Unable to update order.xml document. It does not have the right form to add" + "crawler trap deciderules."); } Element rulesMap = (Element) rulesMapNode; // Create the root node and append it top existing rules Element decideRule = rulesMap.addElement("newObject"); // If an acceptiIfPrerequisite node exists, detach and insert before it Node acceptIfPrerequisiteNode = template.selectSingleNode(DECIDERULES_ACCEPT_IF_PREREQUISITE_XPATH); if (acceptIfPrerequisiteNode != null) { List<Node> elements = rulesMap.elements(); int insertPosition = elements.indexOf(acceptIfPrerequisiteNode); decideRule.detach(); elements.add(insertPosition, decideRule); } else { rulesMap.elements().size(); } // Add all regexps in the list to a single MatchesListRegExpDecideRule decideRule.addAttribute("name", elementName); decideRule.addAttribute("class", Heritrix1Constants.MATCHESLISTREGEXPDECIDERULE_CLASSNAME); Element decision = decideRule.addElement("string"); decision.addAttribute("name", "decision"); decision.addText("REJECT"); Element listlogic = decideRule.addElement("string"); listlogic.addAttribute("name", "list-logic"); listlogic.addText("OR"); Element regexpList = decideRule.addElement("stringList"); regexpList.addAttribute("name", "regexp-list"); for (String trap : crawlerTraps) { regexpList.addElement("string").addText(trap); } }
From source file:dk.netarkivet.harvester.datamodel.H1HeritrixTemplate.java
License:Open Source License
@Override public void insertWarcInfoMetadata(Job ajob, String origHarvestdefinitionName, String scheduleName, String performer) {/* w ww. j a va 2 s . com*/ Node WARCWRITERNODE = template.selectSingleNode(WARCWRITERPROCESSOR_XPATH); if (WARCWRITERNODE == null) { throw new IOFailure("Unable to locate the '" + WARCWRITERPROCESSOR_XPATH + "' element in order.xml: " + template.asXML()); } Element warcwriterElement = (Element) WARCWRITERNODE; Element metadataMap = warcwriterElement.addElement("map"); metadataMap.addAttribute("name", "metadata-items"); Element metadataItem = null; metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_VERSION); metadataItem.addText(HARVESTINFO_VERSION_NUMBER); metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_JOBID); metadataItem.addText("" + ajob.getJobID()); metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_CHANNEL); metadataItem.addText(ajob.getChannel()); metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_HARVESTNUM); metadataItem.addText("" + ajob.getHarvestNum()); metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_ORIGHARVESTDEFINITIONID); metadataItem.addText("" + ajob.getOrigHarvestDefinitionID()); metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_MAXBYTESPERDOMAIN); metadataItem.addText("" + ajob.getMaxBytesPerDomain()); metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_MAXOBJECTSPERDOMAIN); metadataItem.addText("" + ajob.getMaxObjectsPerDomain()); metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_ORDERXMLNAME); metadataItem.addText(ajob.getOrderXMLName()); metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_ORIGHARVESTDEFINITIONNAME); metadataItem.addText(origHarvestdefinitionName); /* optional schedule-name, only for selective harvests. */ if (scheduleName != null) { metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_SCHEDULENAME); metadataItem.addText(scheduleName); } metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_HARVESTFILENAMEPREFIX); metadataItem.addText(ajob.getHarvestFilenamePrefix()); metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_JOBSUBMITDATE); metadataItem.addText("" + ajob.getSubmittedDate()); /* optional HARVESTINFO_PERFORMER */ if (performer != null) { metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_PERFORMER); metadataItem.addText(performer); } /* optional HARVESTINFO_AUDIENCE */ if (ajob.getHarvestAudience() != null) { metadataItem = metadataMap.addElement("string"); metadataItem.addAttribute("name", HARVESTINFO_AUDIENCE); metadataItem.addText(ajob.getHarvestAudience()); } }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.StudiesXmlSerializer.java
License:BSD License
@Override protected Element createElement(final Study study, final boolean inCollection) { Element studyElement = rootElement().create(); STUDY_ASSIGNED_IDENTIFIER.addTo(studyElement, study.getNaturalKey()); if (study.getProvider() != null) { STUDY_PROVIDER.addTo(studyElement, study.getProvider()); }// ww w . j av a2s . co m if (study.getLongTitle() != null && study.getLongTitle().length() > 0) { Element eltLongTitle = XsdElement.LONG_TITLE.create(); eltLongTitle.addText(study.getLongTitle()); studyElement.add(eltLongTitle); } for (StudySecondaryIdentifier studySecondaryIdent : study.getSecondaryIdentifiers()) { studyElement.add(studySecondaryIdentifierXmlSerializer.createElement(studySecondaryIdent)); } return studyElement; }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.StudySnapshotXmlSerializer.java
License:BSD License
@Override public Element createElement(Study study) { Element elt = XsdElement.STUDY_SNAPSHOT.create(); XsdAttribute.STUDY_SNAPSHOT_ASSIGNED_IDENTIFIER.addTo(elt, study.getAssignedIdentifier()); if (study.getProvider() != null) { XsdAttribute.STUDY_PROVIDER.addTo(elt, study.getProvider()); }//from ww w. jav a2s. c o m if (study.getLongTitle() != null && study.getLongTitle().length() > 0) { Element eltLongTitle = XsdElement.LONG_TITLE.create(); eltLongTitle.addText(study.getLongTitle()); elt.add(eltLongTitle); } for (StudySecondaryIdentifier studySecondaryIdent : study.getSecondaryIdentifiers()) { elt.add(studySecondaryIdentifierXmlSerializer.createElement(studySecondaryIdent)); } Set<Population> pops = study.getPopulations(); for (Population pop : pops) { elt.add(populationXmlSerializer.createElement(pop)); } elt.add(plannedCalendarXmlSerializer.createElement(study.getPlannedCalendar())); Element eSources = studyXmlSerializerHelper.generateSourcesElementWithActivities(study); elt.add(eSources); return elt; }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.StudyXmlSerializer.java
License:BSD License
public Element createElement(Study study) { Element elt = XsdElement.STUDY.create(); STUDY_ASSIGNED_IDENTIFIER.addTo(elt, study.getAssignedIdentifier()); LAST_MODIFIED_DATE.addToDateTime(elt, study.getLastModifiedDate()); if (study.getProvider() != null) { STUDY_PROVIDER.addTo(elt, study.getProvider()); }//from ww w . j a v a 2s.c o m if (study.getLongTitle() != null && study.getLongTitle().length() > 0) { Element eltLongTitle = XsdElement.LONG_TITLE.create(); eltLongTitle.addText(study.getLongTitle()); elt.add(eltLongTitle); } for (StudySecondaryIdentifier studySecondaryIdent : study.getSecondaryIdentifiers()) { elt.add(studySecondaryIdentifierXmlSerializer.createElement(studySecondaryIdent)); } Element eCalendar = getPlannedCalendarXmlSerializer().createElement(study.getPlannedCalendar()); elt.add(eCalendar); for (Amendment amendment : study.getAmendmentsList()) { Element eAmendment = getAmendmentSerializer(study).createElement(amendment); elt.add(eAmendment); } if (study.getDevelopmentAmendment() != null) { Amendment developmentAmendment = study.getDevelopmentAmendment(); Element developmentAmendmentElement = getDevelopmentAmendmentSerializer(study) .createElement(developmentAmendment); elt.add(developmentAmendmentElement); } Element eSources = studyXmlSerializerHelper.generateSourcesElementWithActivities(study); elt.add(eSources); return elt; }
From source file:edu.scripps.fl.pubchem.promiscuity.PCPromiscuityOutput.java
License:Apache License
public void compoundPromiscuityToXML(Map<Long, CompoundPromiscuityInfo> map, PCPromiscuityParameters params, File file) throws Exception { jsp = new JSProcessor(); jsp.init();// w w w . ja v a2 s.c om try { InputStream is = getClass().getResourceAsStream("/compress.txt"); jsp.setCodeSource(new InputStreamReader(is)); String[] descriptorColumns = descriptorNames; List<Long> ids = params.getIds(); URL url = getClass().getClassLoader().getResource("Result.xml"); Document doc = new XMLDocument().readDocFromURL(url); Element root = doc.getRootElement(); String db = params.getDatabase(); String idString = "SID"; if (db.equalsIgnoreCase("pccompound")) idString = "CID"; for (Long id : ids) { Element result = root.addElement("Result"); result.addElement(idString).addText(id.toString()); CompoundPromiscuityInfo cpInfo = map.get(id); if (cpInfo == null) result.addElement("NoResults").addText("Error Processing this compound."); else { if (cpInfo.getOnHold()) result.addElement("OnHold").addText("True"); else { if (db.equalsIgnoreCase("pcsubstance")) { Element CIDe = result.addElement("CID"); if (cpInfo.getCID() != null) CIDe.addText(cpInfo.getCID().toString()); } Map<String, Object> descriptors = cpInfo.getDescriptors(); Map<String, CategorizedFunctionalGroups> categorizedFGMap = cpInfo .getCategorizedFunctionalGroupsMap(); Element descriptorsE = result.addElement("Descriptors"); for (String category : functionalGroupCategories) { Element fgCategoryE = descriptorsE.addElement(category); CategorizedFunctionalGroups cFGs = categorizedFGMap.get(category); if (cFGs != null) { List<FunctionalGroup> fgs = cFGs.getFunctionalGroups(); List<String> groups = new ArrayList<String>(); for (FunctionalGroup group : fgs) { groups.add(group.getName()); } fgCategoryE.addText(StringUtils.join(groups, ", ")); } } Element possibleFalse = descriptorsE.addElement("PossibleFalseAromaticityDetection"); if (cpInfo.isPossibleFalseAromaticityDetection()) possibleFalse.addText("true"); for (String cc : descriptorColumns) { Element descriptorCC = descriptorsE.addElement(StringUtils.remove(cc, " ")); if (descriptors.get(cc) != null) descriptorCC.addText(descriptors.get(cc).toString()); } Element proteinsE = result.addElement("Proteins"); if (params.getPerProteinMode()) { Map<Protein, Map<String, PromiscuityCount<?>>> proteinCounts = cpInfo .getPerProteinCounts(); Set<Protein> proteins = proteinCounts.keySet(); for (Protein protein : proteins) { Element proteinE = proteinsE.addElement("Protein"); proteinE.addElement("Name").addText(protein.getName()); Element promiscuityCountsE = proteinE.addElement("PromiscuityCounts"); addCounts(promiscuityCountsE, proteinCounts.get(protein), id, db); } Map<String, PromiscuityCount<?>> noProteinCounts = cpInfo.getNoProteinCounts(); Element noProtein = proteinsE.addElement("Protein"); noProtein.addElement("Name").addText(""); Element noProteinCountsE = noProtein.addElement("PromiscuityCounts"); addCounts(noProteinCountsE, noProteinCounts, id, db); root.addAttribute("format", "protein"); } else { Map<String, PromiscuityCount<?>> counts = cpInfo.getCounts(); Element allProteins = proteinsE.addElement("Protein"); allProteins.addElement("Name").addText("All Proteins"); Element allProteinCountsE = allProteins.addElement("PromiscuityCounts"); addCounts(allProteinCountsE, counts, id, db); root.addAttribute("format", "compound"); } } } } new XMLDocument().write(doc, file); log.info("Finished writing xml to: " + file.getAbsolutePath()); } finally { jsp.exit(); } }