List of usage examples for org.dom4j Element add
void add(Namespace namespace);
Namespace
to this element. From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.ScheduledCalendarXmlSerializer.java
License:BSD License
@Override public Element createElement(ScheduledCalendar scheduledCalendar) { if (scheduledCalendar == null) { throw new StudyCalendarSystemException("scheduledCalendar is required"); }//from www. j av a2 s .co m Element elt = SCHEDULED_CALENDAR.create(); if (scheduledCalendar.getGridId() != null) SCHEDULED_CALENDAR_ID.addTo(elt, scheduledCalendar.getGridId()); if (scheduledCalendar.getAssignment() != null) SCHEDULED_CALENDAR_ASSIGNMENT_ID.addTo(elt, scheduledCalendar.getAssignment().getGridId()); for (ScheduledStudySegment segment : scheduledCalendar.getScheduledStudySegments()) { elt.add(segmentSerialzier.createElement(segment)); } return elt; }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.ScheduledStudySegmentXmlSerializer.java
License:BSD License
@Override public Element createElement(ScheduledStudySegment segment) { Element elt = SCHEDULED_STUDY_SEGMENT.create(); SCHEDULED_STUDY_SEGMENT_ID.addTo(elt, segment.getGridId()); SCHEDULED_STUDY_SEGMENT_START_DATE.addTo(elt, segment.getStartDate()); SCHEDULED_STUDY_SEGMENT_START_DAY.addTo(elt, segment.getStartDay()); XsdAttribute.SCHEDULED_STUDY_SEGMENT_STUDY_SEGMENT_ID.addTo(elt, segment.getStudySegment().getGridId()); for (ScheduledActivity activity : segment.getActivities()) { elt.add(scheduledActivitySerializer.createElement(activity)); }//from w w w .j a v a 2 s . c o m return elt; }
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()); }/* www . ja v a 2 s. c om*/ 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()); }// w w w. jav a 2s . c om 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.StudySubjectAssignmentXmlSerializer.java
License:BSD License
@Override public Element createElement(StudySubjectAssignment assignment, boolean inCollection) { Element elt = SUBJECT_ASSIGNMENT.create(); ASSIGNMENT_STUDY_NAME.addTo(elt, assignment.getStudySite().getStudy().getName()); ASSIGNMENT_SITE_NAME.addTo(elt, assignment.getStudySite().getSite().getName()); ASSIGNMENT_START_DATE.addTo(elt, assignment.getStartDate()); ASSIGNMENT_END_DATE.addTo(elt, assignment.getEndDate()); ASSIGNMENT_SUBJECT_COORD.addTo(elt, assignment.getStudySubjectCalendarManager().getName()); ASSIGNMENT_CURRENT_AMENDMENT.addTo(elt, assignment.getCurrentAmendment().getNaturalKey()); ASSIGNMENT_ID.addTo(elt, assignment.getGridId()); if (!subjectCentric) { elt.add(subjectXmlSerializer.createElement(assignment.getSubject())); }/* w w w .j a v a2 s.c om*/ if (subjectCentric || includeScheduledCalendar) { elt.add(scheduledCalendarXmlSerializer.createElement(assignment.getScheduledCalendar())); } 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 w w w . j ava 2 s . 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.northwestern.bioinformatics.studycalendar.xml.writers.SubjectXmlSerializer.java
License:BSD License
@Override public Element createElement(Subject subject) { Element elt = SUBJECT.create(); SUBJECT_FIRST_NAME.addTo(elt, subject.getFirstName()); SUBJECT_LAST_NAME.addTo(elt, subject.getLastName()); SUBJECT_PERSON_ID.addTo(elt, subject.getPersonId()); SUBJECT_BIRTH_DATE.addTo(elt, subject.getDateOfBirth()); SUBJECT_GENDER.addTo(elt, subject.getGender().getCode()); for (SubjectProperty property : subject.getProperties()) { Element child = SUBJECT_PROPERTY.create(); PROPERTY_NAME.addTo(child, property.getName()); PROPERTY_VALUE.addTo(child, property.getValue()); elt.add(child); }//from w w w . j a v a2 s . c o m return elt; }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.UserRoleMembershipsXmlSerializer.java
License:BSD License
@Override protected Element createElement(SuiteRoleMembership userRoleMembership, boolean inCollection) { Element userRoleElement = rootElement().create(); XsdAttribute.USER_ROLE_NAME.addTo(userRoleElement, userRoleMembership.getRole().getDisplayName()); if (userRoleMembership.hasSiteScope()) { Element roleSites = XsdElement.ROLE_SITES.create(); if (userRoleMembership.isAllSites()) { XsdAttribute.ALL.addTo(roleSites, true); } else {/*from w w w.java2s . c o m*/ XsdAttribute.ALL.addTo(roleSites, false); for (String siteIdentifier : userRoleMembership.getSiteIdentifiers()) { Element site = XsdElement.SITE.create(); XsdAttribute.SITE_ASSIGNED_IDENTIFIER.addTo(site, siteIdentifier); roleSites.add(site); } } userRoleElement.add(roleSites); } if (userRoleMembership.hasStudyScope()) { Element roleStudies = XsdElement.ROLE_STUDIES.create(); if (userRoleMembership.isAllStudies()) { XsdAttribute.ALL.addTo(roleStudies, true); } else { XsdAttribute.ALL.addTo(roleStudies, false); for (String studyIdentifier : userRoleMembership.getStudyIdentifiers()) { Element study = XsdElement.STUDY.create(); XsdAttribute.STUDY_ASSIGNED_IDENTIFIER.addTo(study, studyIdentifier); roleStudies.add(study); } } userRoleElement.add(roleStudies); } return userRoleElement; }
From source file:edu.scripps.fl.pubchem.xml.PubChemXMLDoc.java
License:Apache License
public void organizeXMLDoc(Document doc) { Element parent = (Element) doc.selectSingleNode(rootString); String[] nodesOrder = { name, description, protocol, comment, xref, results, revision, target, activityOutcome, dr, grantNumber, projectCategory, isPanel, panelInfo, categorizedComment }; for (String nodeString : nodesOrder) { Node node = parent.selectSingleNode(nodeString); if (node != null) { Node clone = (Node) node.clone(); node.detach();//from w w w.j a v a2 s. c om parent.add(clone); } } parent = (Element) doc.selectSingleNode(dbTracking); String[] secondNodesOrder = { "PC-DBTracking_name", "PC-DBTracking_source-id", "PC-DBTracking_date" }; for (String nodeString : secondNodesOrder) { Node node = parent.selectSingleNode(nodeString); if (node != null) { Node clone = (Node) node.clone(); node.detach(); parent.add(clone); } } }
From source file:edu.ucsd.library.dams.api.DAMSAPIServlet.java
public String objectBatch(List<String> objids, TripleStore ts, TripleStore es) throws Exception { ArrayList<String> docs = new ArrayList<String>(); ArrayList<String> errors = new ArrayList<String>(); // retrieve rdf/xml for each record for (int i = 0; i < objids.size(); i++) { try {/*ww w . j a va 2s .c o m*/ Identifier id = createID(objids.get(i), null, null); if (ts.exists(id)) { DAMSObject obj = new DAMSObject(ts, es, objids.get(i), nsmap); docs.add(obj.getRDFXML(true)); } else if (es != null && es.exists(id)) { DAMSObject obj = new DAMSObject(es, null, objids.get(i), nsmap); docs.add(obj.getRDFXML(true)); } else { errors.add(objids.get(i) + ": not found"); } } catch (Exception ex) { errors.add(objids.get(i) + ": " + ex.toString()); } } // combine xml documents String xml = null; if (docs.size() == 1) { xml = docs.get(0); } else if (docs.size() > 1) { try { Document doc = DocumentHelper.parseText(docs.get(0)); Element rdf = doc.getRootElement(); for (int i = 1; i < docs.size(); i++) { Document doc2 = DocumentHelper.parseText(docs.get(i)); Iterator it = doc2.getRootElement().elementIterator(); if (it.hasNext()) { Element e = (Element) it.next(); rdf.add(e.detach()); } } xml = doc.asXML(); } catch (Exception ex) { errors.add("Error combining records into a batch: " + ex.toString()); } } // check errors if (errors.size() > 0) { String msg = errors.get(0); for (int i = 1; i < errors.size(); i++) { msg += "; " + errors.get(i); } throw new Exception(msg); } return xml; }