List of usage examples for org.dom4j Element addAttribute
Element addAttribute(QName qName, String value);
From source file:XmlTestBuilder.java
License:Open Source License
protected Element createElement(Element parent, AST node) { Element result = parent.addElement("ast"); int type = node.getType(); String typeName = (String) tokens.get(new Integer(type)); if (typeName == null) { result.addAttribute("type", Integer.toString(type)); } else {//from w ww . ja v a 2 s .c om result.addAttribute("name", typeName); } String text = node.getText(); if (text != null) { if (text.indexOf('\n') == -1) { result.addAttribute("text", node.getText()); } else { result.addCDATA(text); } } return result; }
From source file:architecture.common.license.License.java
License:Apache License
public String toXML() { DocumentFactory factory = DocumentFactory.getInstance(); Document document = factory.createDocument(); Element root = document.addElement("license"); root.addAttribute("id", String.valueOf(getLicenseId())); root.addAttribute("name", getName()); if (edition != null) root.addAttribute("edition", getEdition()); root.addAttribute("creationDate", formatDate(getCreationDate())); root.addAttribute("version", getVersion().getVersionString()); root.addAttribute("type", getType().name()); if (getClient() != null) { Element client = root.addElement("client"); if (getClient().getName() != null) client.addAttribute("name", getClient().getName()); if (getClient().getCompany() != null) client.addAttribute("company", getClient().getCompany()); }/*from ww w. ja va 2s . c o m*/ for (Module m : getModules()) { Element me = root.addElement("module"); me.addAttribute("name", m.getName()); } for (java.util.Map.Entry<String, String> entry : getProperties().entrySet()) { Element prop = root.addElement("property"); prop.addAttribute("name", (String) entry.getKey()); prop.setText((String) entry.getValue()); } return document.asXML(); }
From source file:at.jabberwocky.impl.core.io.PacketReader.java
private Document parseDocument() throws DocumentException, IOException, XmlPullParserException { DocumentFactory df = docFactory;// ww w . j a v a2 s.com Document document = df.createDocument(); Element parent = null; XmlPullParser pp = parser; int count = 0; while (true) { int type = -1; type = pp.nextToken(); switch (type) { case XmlPullParser.PROCESSING_INSTRUCTION: { String text = pp.getText(); int loc = text.indexOf(" "); if (loc >= 0) { document.addProcessingInstruction(text.substring(0, loc), text.substring(loc + 1)); } else { document.addProcessingInstruction(text, ""); } break; } case XmlPullParser.COMMENT: { if (parent != null) { parent.addComment(pp.getText()); } else { document.addComment(pp.getText()); } break; } case XmlPullParser.CDSECT: { String text = pp.getText(); if (parent != null) { parent.addCDATA(text); } else { if (text.trim().length() > 0) { throw new DocumentException("Cannot have text content outside of the root document"); } } break; } case XmlPullParser.ENTITY_REF: { String text = pp.getText(); if (parent != null) { parent.addText(text); } else { if (text.trim().length() > 0) { throw new DocumentException("Cannot have an entityref outside of the root document"); } } break; } case XmlPullParser.END_DOCUMENT: { return document; } case XmlPullParser.START_TAG: { QName qname = (pp.getPrefix() == null) ? df.createQName(pp.getName(), pp.getNamespace()) : df.createQName(pp.getName(), pp.getPrefix(), pp.getNamespace()); Element newElement = null; // Do not include the namespace if this is the start tag of a new packet // This avoids including "jabber:client", "jabber:server" or // "jabber:component:accept" if ("jabber:client".equals(qname.getNamespaceURI()) || "jabber:server".equals(qname.getNamespaceURI()) || "jabber:component:accept".equals(qname.getNamespaceURI()) || "http://jabber.org/protocol/httpbind".equals(qname.getNamespaceURI())) { newElement = df.createElement(pp.getName()); } else { newElement = df.createElement(qname); } int nsStart = pp.getNamespaceCount(pp.getDepth() - 1); int nsEnd = pp.getNamespaceCount(pp.getDepth()); for (int i = nsStart; i < nsEnd; i++) { if (pp.getNamespacePrefix(i) != null) { newElement.addNamespace(pp.getNamespacePrefix(i), pp.getNamespaceUri(i)); } } for (int i = 0; i < pp.getAttributeCount(); i++) { QName qa = (pp.getAttributePrefix(i) == null) ? df.createQName(pp.getAttributeName(i)) : df.createQName(pp.getAttributeName(i), pp.getAttributePrefix(i), pp.getAttributeNamespace(i)); newElement.addAttribute(qa, pp.getAttributeValue(i)); } if (parent != null) { parent.add(newElement); } else { document.add(newElement); } parent = newElement; count++; break; } case XmlPullParser.END_TAG: { if (parent != null) { parent = parent.getParent(); } count--; if (count < 1) { return document; } break; } case XmlPullParser.TEXT: { String text = pp.getText(); if (parent != null) { parent.addText(text); } else { if (text.trim().length() > 0) { throw new DocumentException("Cannot have text content outside of the root document"); } } break; } default: } } }
From source file:bio.pih.genoogle.io.Output.java
/** * @param searchResults//from www . j av a 2 s . c o m * * @return {@link Document} containing the {@link SearchResults} in XML form. */ public static Document genoogleOutputToXML(List<SearchResults> searchResults) { assert searchResults != null; DocumentFactory factory = DocumentFactory.getInstance(); Document doc = factory.createDocument(); doc.setName("genoogle"); Element output = doc.addElement(Genoogle.SOFTWARE_NAME); output.addAttribute("version", Genoogle.VERSION.toString()); output.addAttribute("copyright", Genoogle.COPYRIGHT); Element iterationsElement = output.addElement("iterations"); for (int i = 0; i < searchResults.size(); i++) { SearchResults searchResult = searchResults.get(i); Element iterationElement = iterationsElement.addElement("iteration"); iterationElement.addAttribute("number", String.valueOf(i)); SymbolList query = searchResult.getParams().getQuery(); if (query instanceof RichSequence) { iterationElement.addAttribute("query", ((RichSequence) query).getHeader()); } iterationElement.add(searchResultToXML(searchResult)); } return doc; }
From source file:bio.pih.genoogle.io.Output.java
/** * @param params/*from w w w. j a v a 2 s . c om*/ * @return {@link Element} containing the {@link SearchParams} at XML form. */ public static Element paramsToXML(SearchParams params) { assert params != null; DocumentFactory factory = DocumentFactory.getInstance(); Element paramsElement = factory.createElement("params"); paramsElement.addAttribute("databank", params.getDatabank()); paramsElement.addAttribute("maxSubSequencesDistance", Integer.toString(params.getMaxSubSequencesDistance())); paramsElement.addAttribute("minHspLength", Integer.toString(params.getMinHspLength())); paramsElement.addAttribute("maxHitsResults", Integer.toString(params.getMaxHitsResults())); paramsElement.addAttribute("sequencesExtendDropoff", Integer.toString(params.getSequencesExtendDropoff())); paramsElement.addAttribute("matchScore", Integer.toString(params.getMatchScore())); paramsElement.addAttribute("mismatchScore", Integer.toString(params.getMismatchScore())); return paramsElement; }
From source file:bio.pih.genoogle.io.Output.java
/** * @param hit//from w w w.j a v a2 s .c om * @return {@link Element} containing the {@link Hit} at XML form. */ public static Element hitToXML(Hit hit) { assert hit != null; DocumentFactory factory = DocumentFactory.getInstance(); Element hitElement = factory.createElement("hit"); hitElement.addAttribute("id", hit.getId()); hitElement.addAttribute("gi", hit.getGi()); hitElement.addAttribute("description", hit.getDescription()); hitElement.addAttribute("accession", hit.getAccession()); hitElement.addAttribute("length", Integer.toString(hit.getLength())); hitElement.addAttribute("databank", hit.getDatabankName()); hitElement.add(hspsToXML(hit.getHSPs())); return hitElement; }
From source file:bio.pih.genoogle.io.Output.java
/** * @param hsp//www . j a v a 2 s . com * @return {@link Element} containing the {@link HSP} at XML form. */ public static Element hspToXML(HSP hsp) { assert hsp != null; DocumentFactory factory = DocumentFactory.getInstance(); Element hspElement = factory.createElement("hsp"); hspElement.addAttribute("score", Integer.toString((int) hsp.getScore())); hspElement.addAttribute("normalized-score", Integer.toString((int) hsp.getNormalizedScore())); hspElement.addAttribute("e-value", eValueToString(hsp.getEValue())); hspElement.addAttribute("query-from", Integer.toString(hsp.getQueryFrom())); hspElement.addAttribute("query-to", Integer.toString(hsp.getQueryTo())); hspElement.addAttribute("hit-from", Integer.toString(hsp.getHitFrom())); hspElement.addAttribute("hit-to", Integer.toString(hsp.getHitTo())); hspElement.addAttribute("identity-len", Integer.toString(hsp.getIdentityLength())); hspElement.addAttribute("align-len", Integer.toString(hsp.getAlignLength())); hspElement.addElement("query").addText(hsp.getQuerySeq()); hspElement.addElement("align").addText(hsp.getPathSeq()); hspElement.addElement("targt").addText(hsp.getTargetSeq()); return hspElement; }
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);/*from w w w. jav a 2 s. c om*/ dir.setText(logDirectory.getAbsolutePath()); return Arrays.asList(new Element[] { logging }); }
From source file:cc.warlock.core.client.settings.internal.ClientConfigurationProvider.java
License:Open Source License
protected void addFontAttributes(WarlockFont font, Element fontEl) { fontEl.addAttribute("family", (font == null || font.getFamilyName() == null || font.getFamilyName().equals("")) ? "default" : font.getFamilyName()); fontEl.addAttribute("size", (font == null || font.getSize() == -1) ? "default" : "" + font.getSize()); }
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);/*ww w . j a va2 s . co m*/ for (IConfigurationProvider provider : childProviders) { for (Element childElement : provider.getTopLevelElements()) { element.add(childElement); } } }