List of usage examples for org.jdom2 Element addContent
@Override public Element addContent(final Collection<? extends Content> newContent)
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 a v a2 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./* w ww . 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 w w w .j av a 2s .c o m*/ * @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.GroupListWriter.java
License:Open Source License
/** * Get a JDOM element from a Collection of Group objects. * * @param groups Collection of Group's to write. * @return A JDOM Group list representation. * @throws WriterException//from ww w.j av a2s . co m */ protected final Element getElement(Collection<Group> groups) throws WriterException { Element groupsElement = new Element(GROUPS); for (Group group : groups) { groupsElement.addContent(getElement(group)); } return groupsElement; }
From source file:ca.nrc.cadc.ac.xml.UserListWriter.java
License:Open Source License
/** * Get a JDOM element from a Collection of User objects. * * @param users Collection of User's to write. * @return A JDOM Group list representation. * @throws WriterException/*from w w w .ja v a2 s .c o m*/ */ protected final <T extends Principal> Element getElement(Collection<User> users) throws WriterException { Element usersElement = new Element("users"); for (User user : users) { usersElement.addContent(getElement(user)); } return usersElement; }
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); 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()); }/*from www . j a va2 s. c om*/ 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); }
From source file:ca.nrc.cadc.caom2.xml.ArtifactAccessWriter.java
License:Open Source License
private void addChild(Element parent, String ename, String eval) { Element uri = new Element(ename); uri.setText(eval);/*from w w w. j a v a 2s . c om*/ parent.addContent(uri); }
From source file:ca.nrc.cadc.caom2.xml.ArtifactAccessWriter.java
License:Open Source License
private void addGroups(List<URI> groups, Element parent) { for (URI u : groups) { Element uri = new Element(ArtifactAccessReader.ENAMES.uri.name()); uri.setText(u.toASCIIString());// w w w. j a v a2s .c o m parent.addContent(uri); } }
From source file:ca.nrc.cadc.caom2.xml.ObservationWriter.java
License:Open Source License
/** * Builds a JDOM representation of an Algorithm and adds it to the parent * element./* w ww.j av a 2 s .c o m*/ * * @param algorithm * The Algorithm to add to the parent. * @param parent * The parent element for this child element. * @param dateFormat * The IVOA DateFormat. */ protected void addAlgorithmElement(Algorithm algorithm, Element parent, DateFormat dateFormat) { if (algorithm == null) { return; } Element element = getCaom2Element("algorithm"); addElement("name", algorithm.getName(), element); parent.addContent(element); }
From source file:ca.nrc.cadc.caom2.xml.ObservationWriter.java
License:Open Source License
/** * Builds a JDOM representation of an Proposal and adds it to the parent * element.//from w w w . ja va 2s . c o m * * @param proposal * The Proposal to add to the parent. * @param parent * The parent element for this child element. * @param dateFormat * The IVOA DateFormat. */ protected void addProposalElement(Proposal proposal, Element parent, DateFormat dateFormat) { if (proposal == null) { return; } Element element = getCaom2Element("proposal"); addElement("id", proposal.getID(), element); addElement("pi", proposal.pi, element); addElement("project", proposal.project, element); addElement("title", proposal.title, element); if (docVersion < 23) { addStringListElement("keywords", proposal.getKeywords(), element); } else { addKeywordsElement(proposal.getKeywords(), element); } parent.addContent(element); }