List of usage examples for org.jdom2 Element setText
public Element setText(final String text)
From source file:broadwick.graph.writer.GraphMl.java
License:Apache License
/** * Add an edge to the graphML document./*from w ww .j ava 2s. co m*/ * @param edge the edge to be added to the graph element. * @param element the graph element of the graphML document */ private static void addEdge(final Edge edge, final Element element) { final String id = edge.getId(); final String source = edge.getSource().getId(); final String target = edge.getDestination().getId(); final Element elem = new Element("edge"); elem.setAttribute("id", "e" + id); elem.setAttribute("source", source); elem.setAttribute("target", target); for (final Iterator it = edge.getAttributes().iterator(); it.hasNext();) { final EdgeAttribute attr = (EdgeAttribute) it.next(); final Element data = new Element("data"); data.setAttribute("key", attr.getName()); data.setText(attr.getValue()); elem.addContent(data); } element.addContent(elem); }
From source file:broadwick.graph.writer.GraphMl.java
License:Apache License
/** * Add a node to the graphML document./*w w w .ja va 2 s . c o m*/ * @param vertex the id of the node. * @param element the graph element of the graphML document. */ private static void addNode(final Vertex vertex, final Element element) { final Element node = new Element("node"); node.setAttribute("id", vertex.getId()); for (VertexAttribute attr : vertex.getAttributes()) { final Element data = new Element("data"); data.setAttribute("key", attr.getName()); data.setText(attr.getValue().toString()); node.addContent(data); } element.addContent(node); }
From source file:by.epam.lw05.xml.ListToXml.java
private static Document listToDocument(List<Gun> guns) { Element root = new Element("arsenal", "tns", "http://www.example.com/Tarifes"); root.addNamespaceDeclaration(Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")); Attribute attr = new Attribute("schemaLocation", "http://www.example.com/Tarifes myschema.xsd", Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")); root.setAttribute(attr);//from w ww.j ava 2s .c o m for (Gun gun : guns) { Element combatUnit = new Element("combatunit"); combatUnit.setAttribute("serial", String.valueOf(gun.getSerial())); Element model = new Element("model"); model.setText(gun.getModel()); combatUnit.addContent(model); Element handy = new Element("handy"); handy.setText(gun.getHandy()); combatUnit.addContent(handy); Element origin = new Element("origin"); origin.setText(String.valueOf(gun.getOrigin())); combatUnit.addContent(origin); Element ttx = new Element("ttx"); Element distance = new Element("distance"); distance.setText(String.valueOf(gun.getDistance())); ttx.addContent(distance); Element optics = new Element("optics"); optics.setText(String.valueOf(gun.isOptics())); ttx.addContent(optics); combatUnit.addContent(ttx); root.addContent(combatUnit); } return new Document(root); }
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
/** * Get a JDOM element from a UserRequest object. * * @param userRequest The UserRequest./*from ww w .ja va 2 s . c om*/ * @return A JDOM UserRequest representation. * @throws WriterException */ protected final Element getElement(UserRequest userRequest) throws WriterException { if (userRequest == null) { throw new WriterException("null UserRequest"); } // Create the userRequest Element. Element userRequestElement = new Element(USER_REQUEST); // user element Element userElement = getElement(userRequest.getUser()); userRequestElement.addContent(userElement); // password element Element passwordElement = new Element(PASSWORD); passwordElement.setText(String.valueOf(userRequest.getPassword())); userRequestElement.addContent(passwordElement); return userRequestElement; }
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
/** * Get a JDOM element from a Principal object. * * @param identity The Principal.// w w w.j av a 2 s. c om * @return A JDOM UserDetails representation. * @throws WriterException */ protected final Element getElement(Principal identity) throws WriterException { if (identity == null) { String error = "null Principal"; throw new WriterException(error); } Element identityElement = new Element(IDENTITY); if ((identity instanceof HttpPrincipal)) { identityElement.setAttribute(TYPE, IdentityType.USERNAME.getValue()); } else if ((identity instanceof NumericPrincipal)) { identityElement.setAttribute(TYPE, IdentityType.CADC.getValue()); } else if ((identity instanceof OpenIdPrincipal)) { identityElement.setAttribute(TYPE, IdentityType.OPENID.getValue()); } else if ((identity instanceof X500Principal)) { identityElement.setAttribute(TYPE, IdentityType.X500.getValue()); } else if ((identity instanceof DNPrincipal)) { identityElement.setAttribute(TYPE, IdentityType.ENTRY_DN.getValue()); } else { String error = "Unsupported Principal type " + identity.getClass().getSimpleName(); throw new IllegalArgumentException(error); } identityElement.setText(identity.getName()); return identityElement; }
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
/** * Get a JDOM element from a PosixDetails object. * * @param details The PosixDetails.//from w w w . j av a 2 s. co m * @return A JDOM PosixDetails representation. */ protected final Element getElement(PosixDetails details) throws WriterException { if (details == null) { String error = "null PosixDetails"; throw new WriterException(error); } Element detailsElement = new Element(POSIX_DETAILS); Element usernameElement = new Element(USERNAME); usernameElement.setText(details.getUsername()); detailsElement.addContent(usernameElement); Element uidElement = new Element(UID); uidElement.setText(String.valueOf(details.getUid())); detailsElement.addContent(uidElement); Element gidElement = new Element(GID); gidElement.setText(String.valueOf(details.getGid())); detailsElement.addContent(gidElement); Element homeDirElement = new Element(HOME_DIRECTORY); homeDirElement.setText(details.getHomeDirectory()); detailsElement.addContent(homeDirElement); return detailsElement; }
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
/** * Get a JDOM element from a PersonalDetails object. * * @param details The PersonalDetails.//from w w w . j a v a 2 s . c o m * @return JDOM PersonalDetails representation. */ protected final Element getElement(PersonalDetails details) throws WriterException { if (details == null) { String error = "null PersonalDetails"; throw new WriterException(error); } Element detailsElement = new Element(PERSONAL_DETAILS); Element firstNameElement = new Element(FIRST_NAME); firstNameElement.setText(details.getFirstName()); detailsElement.addContent(firstNameElement); Element lastNameElement = new Element(LAST_NAME); lastNameElement.setText(details.getLastName()); detailsElement.addContent(lastNameElement); if (details.email != null) { Element emailElement = new Element(EMAIL); emailElement.setText(details.email); detailsElement.addContent(emailElement); } if (details.address != null) { Element addressElement = new Element(ADDRESS); addressElement.setText(details.address); detailsElement.addContent(addressElement); } if (details.institute != null) { Element instituteElement = new Element(INSTITUTE); instituteElement.setText(details.institute); detailsElement.addContent(instituteElement); } if (details.city != null) { Element cityElement = new Element(CITY); cityElement.setText(details.city); detailsElement.addContent(cityElement); } if (details.country != null) { Element countryElement = new Element(COUNTRY); countryElement.setText(details.country); detailsElement.addContent(countryElement); } return detailsElement; }
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
/** * Get a JDOM element from a Group object. * * @param group The UserRequest./*from ww w . j a va 2 s .c om*/ * @param deepCopy Return all Group elements. * @return A JDOM Group representation. * @throws WriterException */ protected final Element getElement(Group group, boolean deepCopy) throws WriterException { if (group == null) { throw new WriterException("null Group"); } // Create the root group element. Element groupElement = new Element(GROUP); String groupURI = group.getID().toString(); groupElement.setAttribute(new Attribute(URI, groupURI)); // Group owner if (group.getOwner() != null) { Element ownerElement = new Element(OWNER); Element userElement = getElement(group.getOwner()); ownerElement.addContent(userElement); groupElement.addContent(ownerElement); } if (deepCopy) { // Group description if (group.description != null) { Element descriptionElement = new Element(DESCRIPTION); descriptionElement.setText(group.description); groupElement.addContent(descriptionElement); } // lastModified if (group.lastModified != null) { Element lastModifiedElement = new Element(LAST_MODIFIED); DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC); lastModifiedElement.setText(df.format(group.lastModified)); groupElement.addContent(lastModifiedElement); } // Group properties if (!group.getProperties().isEmpty()) { Element propertiesElement = new Element(PROPERTIES); for (GroupProperty property : group.getProperties()) { propertiesElement.addContent(getElement(property)); } groupElement.addContent(propertiesElement); } // Group groupMembers. if ((group.getGroupMembers() != null) && (!group.getGroupMembers().isEmpty())) { Element groupMembersElement = new Element(GROUP_MEMBERS); for (Group groupMember : group.getGroupMembers()) { groupMembersElement.addContent(getElement(groupMember, false)); } groupElement.addContent(groupMembersElement); } // Group userMembers if ((group.getUserMembers() != null) && (!group.getUserMembers().isEmpty())) { Element userMembersElement = new Element(USER_MEMBERS); for (User userMember : group.getUserMembers()) { userMembersElement.addContent(getElement(userMember)); } groupElement.addContent(userMembersElement); } // Group groupAdmins. if ((group.getGroupAdmins() != null) && (!group.getGroupAdmins().isEmpty())) { Element groupAdminsElement = new Element(GROUP_ADMINS); for (Group groupMember : group.getGroupAdmins()) { groupAdminsElement.addContent(getElement(groupMember, false)); } groupElement.addContent(groupAdminsElement); } // Group userAdmins if ((group.getUserAdmins() != null) && (!group.getUserAdmins().isEmpty())) { Element userAdminsElement = new Element(USER_ADMINS); for (User userMember : group.getUserAdmins()) { userAdminsElement.addContent(getElement(userMember)); } groupElement.addContent(userAdminsElement); } } return groupElement; }
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
/** * Get a JDOM element from a GroupProperty object. * * @param property The GroupProperty.//from ww w . j a v a2 s . c om * @return A JDOM GroupProperty representation. * @throws WriterException */ protected final Element getElement(GroupProperty property) throws WriterException { if (property == null) { throw new WriterException("null GroupProperty"); } Element propertyElement = new Element(PROPERTY); propertyElement.setAttribute(KEY, property.getKey()); if (property.isReadOnly()) { propertyElement.setAttribute(READ_ONLY, Boolean.TRUE.toString()); } Object value = property.getValue(); if ((value instanceof String)) { propertyElement.setAttribute(TYPE, STRING); } else if ((value instanceof Integer)) { propertyElement.setAttribute(TYPE, INTEGER); } else { String error = "Unsupported value type: " + value.getClass().getSimpleName(); throw new IllegalArgumentException(error); } propertyElement.setText(String.valueOf(property.getValue())); return propertyElement; }
From source file:ca.nrc.cadc.caom2.xml.ArtifactAccessWriter.java
License:Open Source License
public void write(ArtifactAccess aa, Writer writer) throws IOException { Element root = new Element(ArtifactAccessReader.ENAMES.artifactAccess.name()); Element ae = new Element(ArtifactAccessReader.ENAMES.artifact.name()); root.addContent(ae);/*from ww w .j a v a 2 s. c o m*/ addChild(ae, ArtifactAccessReader.ENAMES.uri.name(), aa.getArtifact().getURI().toASCIIString()); addChild(ae, ArtifactAccessReader.ENAMES.productType.name(), aa.getArtifact().getProductType().getValue()); addChild(ae, ArtifactAccessReader.ENAMES.releaseType.name(), aa.getArtifact().getReleaseType().getValue()); if (aa.getArtifact().contentChecksum != null) { addChild(ae, ArtifactAccessReader.ENAMES.contentChecksum.name(), aa.getArtifact().contentChecksum.toASCIIString()); } if (aa.getArtifact().contentLength != null) { addChild(ae, ArtifactAccessReader.ENAMES.contentLength.name(), aa.getArtifact().contentLength.toString()); } if (aa.getArtifact().contentType != null) { addChild(ae, ArtifactAccessReader.ENAMES.contentType.name(), aa.getArtifact().contentType); } Element pub = new Element(ArtifactAccessReader.ENAMES.isPublic.name()); pub.setText(Boolean.toString(aa.isPublic)); root.addContent(pub); Element rg = new Element(ArtifactAccessReader.ENAMES.readGroups.name()); if (!aa.getReadGroups().isEmpty() || writeEmptyCollections) { root.addContent(rg); } addGroups(aa.getReadGroups(), rg); Document doc = new Document(root); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(doc, writer); }