List of usage examples for org.jdom2 Element Element
public Element(final String name)
From source file:com.lapis.jsfexporter.xml.XMLExportType.java
License:Apache License
@Override public Element exportRow(IExportRow row) { Element currentElement = (Element) row.getParentRowId(); if (currentElement == null) { currentElement = rootElement;/* ww w .j a va 2s . c o m*/ } for (String namePart : row.getName()) { Element subElement = new Element(cleanElementName(namePart)); currentElement.addContent(subElement); currentElement = subElement; } for (IExportCell cell : row.getCells()) { Element cellElement = currentElement; for (String namePart : cell.getName()) { Element subElement = cellElement.getChild(namePart); if (subElement == null) { subElement = new Element(cleanElementName(namePart)); cellElement.addContent(subElement); } cellElement = subElement; } if (!cellElement.getText().equals("")) { String cellName = cellElement.getName(); cellElement = cellElement.getParentElement(); Element newCellElement = new Element(cellName); cellElement.addContent(newCellElement); cellElement = newCellElement; } cellElement.setText(cell.getValue()); } return currentElement; }
From source file:com.medvision360.medrecord.basex.AbstractXmlConverter.java
License:Creative Commons License
protected void set(Element element, String xpath, String value) { Element currentElement = element; String[] paths = xpath.split("/"); for (int i = 0; i < paths.length; i++) { String pathPart = paths[i].trim(); if (pathPart.isEmpty()) { continue; }/*from w w w . j a va 2s . c o m*/ Element newElement = element.getChild(pathPart); if (newElement == null) { newElement = new Element(pathPart); currentElement.addContent(newElement); } currentElement = newElement; } currentElement.setText(value); }
From source file:com.medvision360.medrecord.basex.MockLocatableSerializer.java
License:Creative Commons License
@Override public void serialize(Locatable locatable, OutputStream os, String encoding) throws IOException { String rmEntity = locatable.getArchetypeDetails().getArchetypeId().rmEntity(); Element root = new Element(rmEntity); root.setAttribute("archetype_node_id", locatable.getArchetypeNodeId()); set(root, "/uid/value", locatable.getUid().getValue()); set(root, "/archetype_id/value", locatable.getArchetypeDetails().getArchetypeId().getValue()); set(root, "/name/value", locatable.getName().getValue()); Document d = new Document(root); Format format = Format.getPrettyFormat(); format.setEncoding(encoding);/*from w w w . j a v a 2s .com*/ XMLOutputter output = new XMLOutputter(format); output.output(d, os); }
From source file:com.medvision360.medrecord.basex.MockLocatableSerializer.java
License:Creative Commons License
private void set(Element element, String xpath, String value) { Element currentElement = element; String[] paths = xpath.split("/"); for (int i = 0; i < paths.length; i++) { String pathPart = paths[i].trim(); if (pathPart.isEmpty()) { continue; }//from ww w . j av a2 s. c om Element newElement = element.getChild(pathPart); if (newElement == null) { newElement = new Element(pathPart); } currentElement.addContent(newElement); currentElement = newElement; } currentElement.setText(value); }
From source file:com.medvision360.medrecord.basex.XmlEHRConverter.java
License:Creative Commons License
@Override public void serialize(EHR EHR, OutputStream os, String encoding) throws IOException, SerializeException { Element root = new Element("EHR"); set(root, "/systemID/value", EHR.getSystemID().getValue()); set(root, "/ehrID/value", EHR.getEhrID().getValue()); set(root, "/timeCreated/value", EHR.getTimeCreated().getValue()); set(root, "/ehrStatus/id/value", EHR.getEhrStatus().getId().getValue()); set(root, "/ehrStatus/namespace", EHR.getEhrStatus().getNamespace()); set(root, "/ehrStatus/type", EHR.getEhrStatus().getType()); ObjectRef directory = EHR.getDirectory(); if (directory != null) { set(root, "/directory/id/value", directory.getId().getValue()); set(root, "/directory/namespace", directory.getNamespace()); set(root, "/directory/type", directory.getType()); }//from ww w . ja v a 2 s.c o m if (EHR instanceof SoftDeletable) { SoftDeletable deletable = (SoftDeletable) EHR; set(root, "/deleted", Boolean.toString(deletable.isDeleted())); } else { set(root, "/deleted", Boolean.toString(false)); } Document d = new Document(root); outputDocument(d, os, encoding); }
From source file:com.medvision360.medrecord.basex.XmlWrappedArchetypeConverter.java
License:Creative Commons License
@Override public WrappedArchetype serialize(WrappedArchetype archetype, OutputStream os, String encoding) throws IOException, SerializeException { String asString = archetype.getAsString(); if (asString == null || "".equals(asString)) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); m_delegate.serialize(archetype, bos, encoding); byte[] bytes = bos.toByteArray(); asString = new String(bytes, encoding); }//from ww w .j a v a2s . c o m Element root = new Element("archetype"); set(root, "/asString", asString); set(root, "/locked", Boolean.toString(archetype.isLocked())); Document d = new Document(root); outputDocument(d, os, encoding); return new WrappedArchetype(asString, archetype.getArchetype(), archetype.isLocked()); }
From source file:com.novell.ldapchai.cr.ChaiHelpdeskAnswer.java
License:Open Source License
public Element toXml() throws ChaiOperationException { final Element answerElement = new Element(ChaiResponseSet.XML_NODE_ANSWER_VALUE); answerElement.setText(encryptValue(answer, challengeText)); answerElement.setAttribute(ChaiResponseSet.XML_ATTRIBUTE_CONTENT_FORMAT, FormatType.HELPDESK.toString()); return answerElement; }
From source file:com.novell.ldapchai.cr.ChaiResponseSet.java
License:Open Source License
static String rsToChaiXML(final ChaiResponseSet rs) throws ChaiValidationException, ChaiOperationException { final Element rootElement = new Element(XML_NODE_ROOT); rootElement.setAttribute(XML_ATTRIBUTE_MIN_RANDOM_REQUIRED, String.valueOf(rs.getChallengeSet().getMinRandomRequired())); rootElement.setAttribute(XML_ATTRIBUTE_LOCALE, rs.getChallengeSet().getLocale().toString()); rootElement.setAttribute(XML_ATTRIBUTE_VERSION, VALUE_VERSION); rootElement.setAttribute(XML_ATTRIBUTE_CHAI_VERSION, ChaiConstant.CHAI_API_VERSION); if (rs.caseInsensitive) { rootElement.setAttribute(XML_ATTRIBUTE_CASE_INSENSITIVE, "true"); }/* ww w . j av a2 s. c o m*/ if (rs.csIdentifier != null) { rootElement.setAttribute(XML_ATTRIBUTE_CHALLENGE_SET_IDENTIFER, rs.csIdentifier); } if (rs.timestamp != null) { rootElement.setAttribute(XML_ATTRIBUTE_TIMESTAMP, DATE_FORMATTER.format(rs.timestamp)); } if (rs.crMap != null) { for (final Challenge loopChallenge : rs.crMap.keySet()) { final Answer answer = rs.crMap.get(loopChallenge); final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_RESPONSE); rootElement.addContent(responseElement); } } if (rs.helpdeskCrMap != null) { for (final Challenge loopChallenge : rs.helpdeskCrMap.keySet()) { final Answer answer = rs.helpdeskCrMap.get(loopChallenge); final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_HELPDESK_RESPONSE); rootElement.addContent(responseElement); } } final Document doc = new Document(rootElement); final XMLOutputter outputter = new XMLOutputter(); final Format format = Format.getRawFormat(); format.setTextMode(Format.TextMode.PRESERVE); format.setLineSeparator(""); outputter.setFormat(format); return outputter.outputString(doc); }
From source file:com.novell.ldapchai.cr.ChaiResponseSet.java
License:Open Source License
private static Element challengeToXml(final Challenge loopChallenge, final Answer answer, final String elementName) throws ChaiOperationException { final Element responseElement = new Element(elementName); responseElement/*w w w .j a va 2 s. c o m*/ .addContent(new Element(XML_NODE_CHALLENGE).addContent(new Text(loopChallenge.getChallengeText()))); final Element answerElement = answer.toXml(); responseElement.addContent(answerElement); responseElement.setAttribute(XML_ATTRIBUTE_ADMIN_DEFINED, String.valueOf(loopChallenge.isAdminDefined())); responseElement.setAttribute(XML_ATTRIBUTE_REQUIRED, String.valueOf(loopChallenge.isRequired())); responseElement.setAttribute(XNL_ATTRIBUTE_MIN_LENGTH, String.valueOf(loopChallenge.getMinLength())); responseElement.setAttribute(XNL_ATTRIBUTE_MAX_LENGTH, String.valueOf(loopChallenge.getMaxLength())); return responseElement; }
From source file:com.novell.ldapchai.cr.HashSaltAnswer.java
License:Open Source License
public Element toXml() { final Element answerElement = new Element(ChaiResponseSet.XML_NODE_ANSWER_VALUE); answerElement.setText(version.toString() + VERSION_SEPARATOR + answerHash); if (salt != null && salt.length() > 0) { answerElement.setAttribute(ChaiResponseSet.XML_ATTRIBUTE_SALT, salt); }// w w w . j a v a2 s. co m answerElement.setAttribute(ChaiResponseSet.XML_ATTRIBUTE_CONTENT_FORMAT, formatType.toString()); if (hashCount > 1) { answerElement.setAttribute(ChaiResponseSet.XML_ATTRIBUTE_HASH_COUNT, String.valueOf(hashCount)); } return answerElement; }