List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:org.cpsolver.instructor.model.InstructorSchedulingModel.java
License:Open Source License
/** * Store the problem (together with its solution) in an XML format * @param assignment current assignment//from www . j a v a2 s. c om * @return XML document with the problem */ public Document save(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment) { DecimalFormat sDF7 = new DecimalFormat("0000000"); boolean saveInitial = getProperties().getPropertyBoolean("Xml.SaveInitial", false); boolean saveBest = getProperties().getPropertyBoolean("Xml.SaveBest", false); boolean saveSolution = getProperties().getPropertyBoolean("Xml.SaveSolution", true); Document document = DocumentHelper.createDocument(); if (assignment != null && assignment.nrAssignedVariables() > 0) { StringBuffer comments = new StringBuffer("Solution Info:\n"); Map<String, String> solutionInfo = (getProperties().getPropertyBoolean("Xml.ExtendedInfo", true) ? getExtendedInfo(assignment) : getInfo(assignment)); for (String key : new TreeSet<String>(solutionInfo.keySet())) { String value = solutionInfo.get(key); comments.append(" " + key + ": " + value + "\n"); } document.addComment(comments.toString()); } Element root = document.addElement("instructor-schedule"); root.addAttribute("version", "1.0"); root.addAttribute("created", String.valueOf(new Date())); Element typesEl = root.addElement("attributes"); for (Attribute.Type type : getAttributeTypes()) { Element typeEl = typesEl.addElement("type"); if (type.getTypeId() != null) typeEl.addAttribute("id", String.valueOf(type.getTypeId())); typeEl.addAttribute("name", type.getTypeName()); typeEl.addAttribute("conjunctive", type.isConjunctive() ? "true" : "false"); typeEl.addAttribute("required", type.isRequired() ? "true" : "false"); Set<Attribute> attributes = new HashSet<Attribute>(); for (TeachingRequest request : getRequests()) { for (Preference<Attribute> pref : request.getAttributePreferences()) { Attribute attribute = pref.getTarget(); if (type.equals(attribute.getType()) && attributes.add(attribute)) { Element attributeEl = typeEl.addElement("attribute"); if (attribute.getAttributeId() != null) attributeEl.addAttribute("id", String.valueOf(attribute.getAttributeId())); attributeEl.addAttribute("name", attribute.getAttributeName()); } } for (Instructor instructor : getInstructors()) { for (Attribute attribute : instructor.getAttributes()) { if (type.equals(attribute.getType()) && attributes.add(attribute)) { Element attributeEl = typeEl.addElement("attribute"); if (attribute.getAttributeId() != null) attributeEl.addAttribute("id", String.valueOf(attribute.getAttributeId())); attributeEl.addAttribute("name", attribute.getAttributeName()); } } } } } Element requestsEl = root.addElement("teaching-requests"); for (TeachingRequest request : getRequests()) { Element requestEl = requestsEl.addElement("request"); requestEl.addAttribute("id", String.valueOf(request.getRequestId())); if (request.getNrInstructors() != 1) requestEl.addAttribute("nrInstructors", String.valueOf(request.getNrInstructors())); Course course = request.getCourse(); Element courseEl = requestEl.addElement("course"); if (course.getCourseId() != null) courseEl.addAttribute("id", String.valueOf(course.getCourseId())); if (course.getCourseName() != null) courseEl.addAttribute("name", String.valueOf(course.getCourseName())); for (Section section : request.getSections()) { Element sectionEl = requestEl.addElement("section"); sectionEl.addAttribute("id", String.valueOf(section.getSectionId())); if (section.getExternalId() != null && !section.getExternalId().isEmpty()) sectionEl.addAttribute("externalId", section.getExternalId()); if (section.getSectionType() != null && !section.getSectionType().isEmpty()) sectionEl.addAttribute("type", section.getSectionType()); if (section.getSectionName() != null && !section.getSectionName().isEmpty()) sectionEl.addAttribute("name", section.getSectionName()); if (section.hasTime()) { TimeLocation tl = section.getTime(); Element timeEl = sectionEl.addElement("time"); timeEl.addAttribute("days", sDF7.format(Long.parseLong(Integer.toBinaryString(tl.getDayCode())))); timeEl.addAttribute("start", String.valueOf(tl.getStartSlot())); timeEl.addAttribute("length", String.valueOf(tl.getLength())); if (tl.getBreakTime() != 0) timeEl.addAttribute("breakTime", String.valueOf(tl.getBreakTime())); if (tl.getTimePatternId() != null) timeEl.addAttribute("pattern", tl.getTimePatternId().toString()); if (tl.getDatePatternId() != null) timeEl.addAttribute("datePattern", tl.getDatePatternId().toString()); if (tl.getDatePatternName() != null && !tl.getDatePatternName().isEmpty()) timeEl.addAttribute("datePatternName", tl.getDatePatternName()); if (tl.getWeekCode() != null) timeEl.addAttribute("dates", bitset2string(tl.getWeekCode())); timeEl.setText(tl.getLongName(false)); } if (section.hasRoom()) sectionEl.addAttribute("room", section.getRoom()); if (section.isAllowOverlap()) sectionEl.addAttribute("canOverlap", "true"); if (section.isCommon()) sectionEl.addAttribute("common", "true"); } requestEl.addAttribute("load", sDoubleFormat.format(request.getLoad())); requestEl.addAttribute("sameCourse", Constants.preferenceLevel2preference(request.getSameCoursePreference())); requestEl.addAttribute("sameCommon", Constants.preferenceLevel2preference(request.getSameCommonPreference())); for (Preference<Attribute> pref : request.getAttributePreferences()) { Element attributeEl = requestEl.addElement("attribute"); if (pref.getTarget().getAttributeId() != null) attributeEl.addAttribute("id", String.valueOf(pref.getTarget().getAttributeId())); attributeEl.addAttribute("name", pref.getTarget().getAttributeName()); attributeEl.addAttribute("type", pref.getTarget().getType().getTypeName()); attributeEl.addAttribute("preference", (pref.isRequired() ? "R" : pref.isProhibited() ? "P" : String.valueOf(pref.getPreference()))); } for (Preference<Instructor> pref : request.getInstructorPreferences()) { Element instructorEl = requestEl.addElement("instructor"); instructorEl.addAttribute("id", String.valueOf(pref.getTarget().getInstructorId())); if (pref.getTarget().hasExternalId()) instructorEl.addAttribute("externalId", pref.getTarget().getExternalId()); if (pref.getTarget().hasName()) instructorEl.addAttribute("name", pref.getTarget().getName()); instructorEl.addAttribute("preference", (pref.isRequired() ? "R" : pref.isProhibited() ? "P" : String.valueOf(pref.getPreference()))); } if (saveBest) for (TeachingRequest.Variable variable : request.getVariables()) { if (variable.getBestAssignment() != null) { Instructor instructor = variable.getBestAssignment().getInstructor(); Element instructorEl = requestEl.addElement("best-instructor"); instructorEl.addAttribute("id", String.valueOf(instructor.getInstructorId())); if (request.getNrInstructors() != 1) instructorEl.addAttribute("index", String.valueOf(variable.getInstructorIndex())); if (instructor.hasExternalId()) instructorEl.addAttribute("externalId", instructor.getExternalId()); if (instructor.hasName()) instructorEl.addAttribute("name", instructor.getName()); } } if (saveInitial) for (TeachingRequest.Variable variable : request.getVariables()) { if (variable.getInitialAssignment() != null) { Instructor instructor = variable.getInitialAssignment().getInstructor(); Element instructorEl = requestEl.addElement("initial-instructor"); instructorEl.addAttribute("id", String.valueOf(instructor.getInstructorId())); if (request.getNrInstructors() != 1) instructorEl.addAttribute("index", String.valueOf(variable.getInstructorIndex())); if (instructor.hasExternalId()) instructorEl.addAttribute("externalId", instructor.getExternalId()); if (instructor.hasName()) instructorEl.addAttribute("name", instructor.getName()); } } if (saveSolution) for (TeachingRequest.Variable variable : request.getVariables()) { TeachingAssignment ta = assignment.getValue(variable); if (ta != null) { Instructor instructor = ta.getInstructor(); Element instructorEl = requestEl.addElement("assigned-instructor"); instructorEl.addAttribute("id", String.valueOf(instructor.getInstructorId())); if (request.getNrInstructors() != 1) instructorEl.addAttribute("index", String.valueOf(variable.getInstructorIndex())); if (instructor.hasExternalId()) instructorEl.addAttribute("externalId", instructor.getExternalId()); if (instructor.hasName()) instructorEl.addAttribute("name", instructor.getName()); } } } Element instructorsEl = root.addElement("instructors"); for (Instructor instructor : getInstructors()) { Element instructorEl = instructorsEl.addElement("instructor"); instructorEl.addAttribute("id", String.valueOf(instructor.getInstructorId())); if (instructor.hasExternalId()) instructorEl.addAttribute("externalId", instructor.getExternalId()); if (instructor.hasName()) instructorEl.addAttribute("name", instructor.getName()); if (instructor.getPreference() != 0) instructorEl.addAttribute("preference", String.valueOf(instructor.getPreference())); if (instructor.getBackToBackPreference() != 0) instructorEl.addAttribute("btb", String.valueOf(instructor.getBackToBackPreference())); if (instructor.getSameDaysPreference() != 0) instructorEl.addAttribute("same-days", String.valueOf(instructor.getSameDaysPreference())); if (instructor.getSameRoomPreference() != 0) instructorEl.addAttribute("same-room", String.valueOf(instructor.getSameRoomPreference())); for (Attribute attribute : instructor.getAttributes()) { Element attributeEl = instructorEl.addElement("attribute"); if (attribute.getAttributeId() != null) attributeEl.addAttribute("id", String.valueOf(attribute.getAttributeId())); attributeEl.addAttribute("name", attribute.getAttributeName()); attributeEl.addAttribute("type", attribute.getType().getTypeName()); } instructorEl.addAttribute("maxLoad", sDoubleFormat.format(instructor.getMaxLoad())); for (Preference<TimeLocation> tp : instructor.getTimePreferences()) { Element timeEl = instructorEl.addElement("time"); TimeLocation tl = tp.getTarget(); timeEl.addAttribute("days", sDF7.format(Long.parseLong(Integer.toBinaryString(tl.getDayCode())))); timeEl.addAttribute("start", String.valueOf(tl.getStartSlot())); timeEl.addAttribute("length", String.valueOf(tl.getLength())); if (tl.getBreakTime() != 0) timeEl.addAttribute("breakTime", String.valueOf(tl.getBreakTime())); if (tl.getTimePatternId() != null) timeEl.addAttribute("pattern", tl.getTimePatternId().toString()); if (tl.getDatePatternId() != null) timeEl.addAttribute("datePattern", tl.getDatePatternId().toString()); if (tl.getDatePatternName() != null && !tl.getDatePatternName().isEmpty()) timeEl.addAttribute("datePatternName", tl.getDatePatternName()); if (tl.getWeekCode() != null) timeEl.addAttribute("dates", bitset2string(tl.getWeekCode())); timeEl.addAttribute("preference", tp.isProhibited() ? "P" : tp.isRequired() ? "R" : String.valueOf(tp.getPreference())); if (tp.getTarget() instanceof EnrolledClass) { Element classEl = timeEl.addElement("section"); Element courseEl = null; EnrolledClass ec = (EnrolledClass) tp.getTarget(); if (ec.getCourseId() != null || ec.getCourse() != null) { courseEl = timeEl.addElement("course"); if (ec.getCourseId() != null) courseEl.addAttribute("id", String.valueOf(ec.getCourseId())); if (ec.getCourse() != null) courseEl.addAttribute("name", ec.getCourse()); } if (ec.getClassId() != null) classEl.addAttribute("id", String.valueOf(ec.getClassId())); if (ec.getType() != null) classEl.addAttribute("type", ec.getType()); if (ec.getSection() != null) classEl.addAttribute("name", ec.getSection()); if (ec.getExternalId() != null) classEl.addAttribute("externalId", ec.getExternalId()); if (ec.getRoom() != null) classEl.addAttribute("room", ec.getRoom()); classEl.addAttribute("role", ec.isInstructor() ? "instructor" : "student"); } else { timeEl.setText(tl.getLongName(false)); } } for (Preference<Course> cp : instructor.getCoursePreferences()) { Element courseEl = instructorEl.addElement("course"); Course course = cp.getTarget(); if (course.getCourseId() != null) courseEl.addAttribute("id", String.valueOf(course.getCourseId())); if (course.getCourseName() != null) courseEl.addAttribute("name", String.valueOf(course.getCourseName())); courseEl.addAttribute("preference", cp.isProhibited() ? "P" : cp.isRequired() ? "R" : String.valueOf(cp.getPreference())); } } Element constraintsEl = root.addElement("constraints"); for (Constraint<TeachingRequest.Variable, TeachingAssignment> c : constraints()) { if (c instanceof SameInstructorConstraint) { SameInstructorConstraint si = (SameInstructorConstraint) c; Element sameInstEl = constraintsEl.addElement("same-instructor"); if (si.getConstraintId() != null) sameInstEl.addAttribute("id", String.valueOf(si.getConstraintId())); if (si.getName() != null) sameInstEl.addAttribute("name", si.getName()); sameInstEl.addAttribute("preference", Constants.preferenceLevel2preference(si.getPreference())); for (TeachingRequest.Variable request : c.variables()) { Element assignmentEl = sameInstEl.addElement("request"); assignmentEl.addAttribute("id", String.valueOf(request.getRequest().getRequestId())); if (request.getRequest().getNrInstructors() != 1) assignmentEl.addAttribute("index", String.valueOf(request.getInstructorIndex())); } } else if (c instanceof SameLinkConstraint) { SameLinkConstraint si = (SameLinkConstraint) c; Element sameInstEl = constraintsEl.addElement("same-link"); if (si.getConstraintId() != null) sameInstEl.addAttribute("id", String.valueOf(si.getConstraintId())); if (si.getName() != null) sameInstEl.addAttribute("name", si.getName()); sameInstEl.addAttribute("preference", Constants.preferenceLevel2preference(si.getPreference())); for (TeachingRequest.Variable request : c.variables()) { Element assignmentEl = sameInstEl.addElement("request"); assignmentEl.addAttribute("id", String.valueOf(request.getRequest().getRequestId())); if (request.getRequest().getNrInstructors() != 1) assignmentEl.addAttribute("index", String.valueOf(request.getInstructorIndex())); } } } return document; }
From source file:org.cpsolver.studentsct.StudentRequestXml.java
License:Open Source License
public static Document exportModel(Assignment<Request, Enrollment> assignment, StudentSectioningModel model) { Document document = DocumentHelper.createDocument(); Element requestElement = document.addElement("request"); requestElement.addAttribute("campus", model.getProperties().getProperty("Data.Initiative")); requestElement.addAttribute("year", model.getProperties().getProperty("Data.Year")); requestElement.addAttribute("term", model.getProperties().getProperty("Data.Term")); for (Student student : model.getStudents()) { Element studentElement = requestElement.addElement("student"); studentElement.addAttribute("key", String.valueOf(student.getId())); Element courseRequestsElement = studentElement.addElement("updateCourseRequests"); courseRequestsElement.addAttribute("commit", "true"); Collections.sort(student.getRequests(), new Comparator<Request>() { @Override// w ww .j a v a 2 s.c om public int compare(Request r1, Request r2) { if (r1.isAlternative() != r2.isAlternative()) { return (r1.isAlternative() ? 1 : -1); } return Double.compare(r1.getPriority(), r2.getPriority()); } }); boolean hasSchedule = false; for (Request request : student.getRequests()) { if (assignment.getValue(request) != null) hasSchedule = true; if (request instanceof FreeTimeRequest) { FreeTimeRequest ftReq = (FreeTimeRequest) request; Element ftReqElement = courseRequestsElement.addElement("freeTime"); requestElement.addAttribute("days", ftReq.getTime().getDayHeader()); int startSlot = ftReq.getTime().getStartSlot(); int startTime = startSlot * Constants.SLOT_LENGTH_MIN + Constants.FIRST_SLOT_TIME_MIN; ftReqElement.addAttribute("startTime", s2zDF.format(startTime / 60) + s2zDF.format(startTime % 60)); int endTime = startTime + ftReq.getTime().getLength() * Constants.SLOT_LENGTH_MIN - ftReq.getTime().getBreakTime(); ftReqElement.addAttribute("endTime", s2zDF.format(endTime / 60) + s2zDF.format(endTime % 60)); ftReqElement.addAttribute("length", String.valueOf(ftReq.getTime().getLength() * Constants.SLOT_LENGTH_MIN)); } else { CourseRequest crReq = (CourseRequest) request; Element crReqElement = courseRequestsElement.addElement("courseOffering"); Course course = crReq.getCourses().get(0); crReqElement.addAttribute("subjectArea", course.getSubjectArea()); crReqElement.addAttribute("courseNumber", course.getCourseNumber()); crReqElement.addAttribute("waitlist", crReq.isWaitlist() ? "true" : "false"); crReqElement.addAttribute("alternative", crReq.isAlternative() ? "true" : "false"); for (int i = 1; i < crReq.getCourses().size(); i++) { Course altCourse = crReq.getCourses().get(i); Element altCourseElement = crReqElement.addElement("alternative"); altCourseElement.addAttribute("subjectArea", altCourse.getSubjectArea()); altCourseElement.addAttribute("courseNumber", altCourse.getCourseNumber()); } } } if (hasSchedule) { Element requestScheduleElement = studentElement.addElement("requestSchedule"); requestScheduleElement.addAttribute("type", "commit"); for (Request request : student.getRequests()) { if (request instanceof CourseRequest) { CourseRequest crReq = (CourseRequest) request; Enrollment enrollment = assignment.getValue(crReq); if (enrollment == null) continue; Element crReqElement = requestScheduleElement.addElement("courseOffering"); Course course = enrollment.getCourse(); crReqElement.addAttribute("subjectArea", course.getSubjectArea()); crReqElement.addAttribute("courseNumber", course.getCourseNumber()); for (Section section : enrollment.getSections()) { Element classEl = crReqElement.addElement("class"); classEl.addAttribute("id", section.getSubpart().getInstructionalType()); classEl.addAttribute("assignmentId", String.valueOf(section.getId())); } } } } } return document; }
From source file:org.cpsolver.studentsct.StudentSectioningXMLSaver.java
License:Open Source License
/** * Save an XML file//w w w . j a v a2 s . c o m * * @param outFile * output file * @throws Exception thrown when the save fails */ public void save(File outFile) throws Exception { if (outFile == null) { outFile = new File(iOutputFolder, "solution.xml"); } else if (outFile.getParentFile() != null) { outFile.getParentFile().mkdirs(); } sLogger.debug("Writting XML data to:" + outFile); Document document = DocumentHelper.createDocument(); document.addComment("Student Sectioning"); populate(document); FileOutputStream fos = null; try { fos = new FileOutputStream(outFile); (new XMLWriter(fos, OutputFormat.createPrettyPrint())).write(document); fos.flush(); fos.close(); fos = null; } finally { try { if (fos != null) fos.close(); } catch (IOException e) { } } if (iConvertIds) IdConvertor.getInstance().save(); }
From source file:org.cpsolver.studentsct.StudentSectioningXMLSaver.java
License:Open Source License
public Document saveDocument() { Document document = DocumentHelper.createDocument(); document.addComment("Student Sectioning"); populate(document);// ww w. j a va 2 s. c om return document; }
From source file:org.craftercms.core.xml.mergers.impl.DescriptorMergerImpl.java
License:Open Source License
@Override public Document merge(List<Document> descriptorsToMerge) throws XmlMergeException { Document merged = DocumentHelper.createDocument(); if (CollectionUtils.isNotEmpty(descriptorsToMerge)) { Element mergedRoot = descriptorsToMerge.get(0).getRootElement().createCopy(); for (Iterator<Document> i = descriptorsToMerge.listIterator(1); i.hasNext();) { Element descriptorRoot = i.next().getRootElement().createCopy(); mergedRoot = initialMergeCue.merge(mergedRoot, descriptorRoot, initialMergeCueParams); }//from www . j a v a 2 s . c o m merged.add(mergedRoot); } return merged; }
From source file:org.craftercms.cstudio.alfresco.script.ModelServiceScript.java
License:Open Source License
/** * create an XML document given the model data * /*from ww w .j av a 2 s. c o m*/ * @param modelData * @param elementName * child element name * @return modelData in XML */ protected Document createXMLDocument(List<ModelDataTO> modelData, String elementName) { Document document = DocumentHelper.createDocument(); Element root = document.addElement(CStudioXmlConstants.DOCUMENT_MODEL_DATA); if (modelData != null) { for (ModelDataTO model : modelData) { String type = model.getType(); String localName = (type.contains(":")) ? type.substring(type.indexOf(":") + 1, type.length()) : type; String childName = (StringUtils.isEmpty(elementName)) ? localName : elementName; Element childElement = root.addElement(childName); childElement.addAttribute(CStudioXmlConstants.DOCUMENT_ATTR_NAME, type); childElement.addAttribute(CStudioXmlConstants.DOCUMENT_ATTR_ID, String.valueOf(model.getId())); childElement.addAttribute(CStudioXmlConstants.DOCUMENT_ATTR_LABEL, model.getLabel()); childElement.addAttribute(CStudioXmlConstants.DOCUMENT_ATTR_DESCRIPTION, model.getDescription()); childElement.addAttribute(CStudioXmlConstants.DOCUMENT_ATTR_VALUE, String.valueOf(model.getValue())); if (model.getChildren() != null) { addChildElements(childElement, model.getChildren(), elementName); } } } return document; }
From source file:org.craftercms.cstudio.alfresco.transform.TaxonomyRendition.java
License:Open Source License
/** * Construct XML //from ww w. ja v a 2 s. c o m * * @param nodeRef * @return */ protected Document retreiveXml(NodeRef nodeRef) throws ServiceException { // Retreive values from NodeRef PersistenceManagerService persistenceManagerService = getServicesManager() .getService(PersistenceManagerService.class); NamespaceService namespaceService = getServicesManager().getService(NamespaceService.class); QName nodeQType = persistenceManagerService.getType(nodeRef); String type_value = namespaceService.getPrefixedTypeName(nodeQType); String name_value = (String) persistenceManagerService.getProperty(nodeRef, ContentModel.PROP_NAME); Long id_value = (Long) persistenceManagerService.getProperty(nodeRef, CStudioContentModel.PROP_IDENTIFIABLE_ID); String description_value = (String) persistenceManagerService.getProperty(nodeRef, CStudioContentModel.PROP_IDENTIFIABLE_DESCRIPTION); Long order_value = (Long) persistenceManagerService.getProperty(nodeRef, CStudioContentModel.PROP_IDENTIFIABLE_ORDER); Boolean disabled_value = (Boolean) persistenceManagerService.getProperty(nodeRef, CStudioContentModel.PROP_IDENTIFIABLE_DELETED); Boolean is_live_value = (Boolean) persistenceManagerService.getProperty(nodeRef, CStudioContentModel.PROP_IDENTIFIABLE_CURRENT); Object iconPath_value = persistenceManagerService.getProperty(nodeRef, CStudioContentModel.PROP_IDENTIFIABLE_ICON_PATH); // Create Document Document document = DocumentHelper.createDocument(); Element category = document.addElement(CStudioXmlConstants.DOCUMENT_CATEGORY); Element type = category.addElement(CStudioXmlConstants.DOCUMENT_CATEGORY_TYPE); type.setText(type_value != null ? type_value.toString() : ""); Element name = category.addElement(CStudioXmlConstants.DOCUMENT_CATEGORY_NAME); name.setText(name_value != null ? name_value.toString() : ""); Element id = category.addElement(CStudioXmlConstants.DOCUMENT_CATEGORY_ID); id.setText(id_value != null ? id_value.toString() : ""); Element description = category.addElement(CStudioXmlConstants.DOCUMENT_CATEGORY_DESCRIPTION); description.setText(description_value != null ? description_value.toString() : ""); Element order = category.addElement(CStudioXmlConstants.DOCUMENT_CATEGORY_ORDER); order.setText(order_value != null ? order_value.toString() : ""); if (iconPath_value != null) { Element iconPath = category.addElement(CStudioXmlConstants.DOCUMENT_CATEGORY_ICON_PATH); iconPath.setText((String) iconPath_value); } Element is_live = category.addElement(CStudioXmlConstants.DOCUMENT_CATEGORY_IS_LIVE); if (is_live_value != null && is_live_value.equals(true)) { is_live.setText("true"); } else { is_live.setText("false"); } Element disabled = category.addElement(CStudioXmlConstants.DOCUMENT_CATEGORY_DISABLED); if (disabled_value != null && disabled_value.equals(true)) { disabled.setText("true"); } else { disabled.setText("false"); } Element createdbyElement = category.addElement(CStudioXmlConstants.DOCUMENT_ELM_CREATED_BY); createdbyElement.setText(getPropertyValue(nodeRef, ContentModel.PROP_CREATOR)); Element modifiedbyElement = category.addElement(CStudioXmlConstants.DOCUMENT_ELM_MODIFIED_BY); modifiedbyElement.setText(getPropertyValue(nodeRef, ContentModel.PROP_MODIFIER)); Element parent = category.addElement(CStudioXmlConstants.DOCUMENT_CATEGORY_PARENT); Long parent_id_value = null; return document; }
From source file:org.craftercms.cstudio.impl.repository.alfresco.AlfrescoContentRepository.java
License:Open Source License
@Override public InputStream getMetadataStream(String site, String path) { PersistenceManagerService persistenceManagerService = _servicesManager .getService(PersistenceManagerService.class); NodeRef nodeRef = persistenceManagerService .getNodeRef(SITE_REPO_ROOT_PATTERN.replaceAll(SITE_REPLACEMENT_PATTERN, site), path); Map<QName, Serializable> contentProperties = persistenceManagerService.getProperties(nodeRef); Document metadataDoc = DocumentHelper.createDocument(); Element root = metadataDoc.addElement("metadata"); for (Map.Entry<QName, Serializable> property : contentProperties.entrySet()) { Element elem = root.addElement(property.getKey().getLocalName()); elem.addText(String.valueOf(property.getValue())); }// w w w .j a v a 2 s . c o m return IOUtils.toInputStream(metadataDoc.asXML()); }
From source file:org.dentaku.gentaku.cartridge.event.WerkflowTag.java
License:Apache License
Document generateDocument(Object modelElement) throws JellyTagException { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("processes", "werkflow:basic").addNamespace("j", "jelly:core") .addNamespace("jelly", "werkflow:jelly").addNamespace("java", "werkflow:java") .addNamespace("python", "werkflow:python").addNamespace("ognl", "werkflow:ognl"); Element process = root.addElement("process"); ActivityGraph ag = null;//from w ww .j a va2 s . co m try { ag = (ActivityGraph) findOneItem(((Namespace) modelElement), ActivityGraph.class); } catch (GenerationException e) { throw new JellyTagException(e); } Element seq = process.addElement("sequence"); Pseudostate startState = findInitialState(((CompositeState) ag.getTop()).getSubvertex()); if (startState != null) { Collection subvertex = ((CompositeState) ag.getTop()).getSubvertex(); GraphProcessor gp = new GraphProcessor(); JMIUMLIterator nav = new JMIUMLIterator(); try { gp.validate(subvertex, nav); } catch (GraphException e) { throw new JellyTagException(e); } Collection topological = gp.getTopological(); for (Iterator it = topological.iterator(); it.hasNext();) { StateVertex vertex = (StateVertex) it.next(); if (vertex instanceof SimpleState) { String vertexClass = ((ModelElementImpl) modelElement).getFullyQualifiedName(); seq.addElement("java:action").setText(vertexClass + "Workflow.getInstance()." + ((SimpleState) vertex).getEntry().getName() + "();"); } } } return doc; }
From source file:org.dentaku.gentaku.tools.cgen.plugin.GenGenPlugin.java
License:Apache License
public void start() { System.out.println("Running " + getClass().getName()); Collection metadata = mp.getJMIMetadata(); for (Iterator it = metadata.iterator(); it.hasNext();) { Object o = (Object) it.next(); if (o instanceof ModelElementImpl && ((ModelElementImpl) o).getStereotypeNames().contains("GenGenPackage")) { ModelElementImpl pkg = (ModelElementImpl) o; try { // get the two documents out of the model Document mappingDoc = DocumentHelper.parseText( (String) pkg.getTaggedValue("gengen.mapping").getDataValue().iterator().next()); final Document xsdDoc = DocumentHelper .parseText((String) pkg.getTaggedValue("gengen.XSD").getDataValue().iterator().next()); Collection generators = mappingDoc.selectNodes("/mapping/generator"); final Map generatorMap = new HashMap(); for (Iterator getIterator = generators.iterator(); getIterator.hasNext();) { Element element = (Element) getIterator.next(); try { Generator g = (Generator) Class.forName(element.attributeValue("canonicalName")) .newInstance(); generatorMap.put(element.attributeValue("name"), g); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); }/*from w w w. j a v a2 s. co m*/ } // annotate XSD with mapping document mappingDoc.accept(new VisitorSupport() { public void visit(Element node) { String path = node.attributeValue("path"); if (path != null) { LocalDefaultElement xsdVisit = (LocalDefaultElement) Util.selectSingleNode(xsdDoc, path); xsdVisit.setAnnotation((LocalDefaultElement) node); } String key = node.attributeValue("ref"); if (node.getName().equals("generator") && key != null) { if (generatorMap.keySet().contains(key)) { ((LocalDefaultElement) node).setGenerator((Generator) generatorMap.get(key)); } else { throw new RuntimeException( "generator key '" + key + "' not created or not found"); } } } }); // create a new output document Document outputDocument = DocumentHelper.createDocument(); // find element root of mapping document Element rootElementCandidate = (Element) Util.selectSingleNode(mappingDoc, "/mapping/element[@location='root']"); if (rootElementCandidate == null) { throw new RuntimeException("could not find root element of XSD"); } String rootPath = rootElementCandidate.attributeValue("path"); LocalDefaultElement rootElement = (LocalDefaultElement) Util.selectSingleNode(xsdDoc, rootPath); // get the model root (there can be only one...) ModelImpl m = Utils.getModelRoot(mp.getModel()); // pregenerate for (Iterator genIterator = generatorMap.values().iterator(); genIterator.hasNext();) { Generator generator = (Generator) genIterator.next(); generator.preProcessModel(m); } // create a visitor and visit the document PluginOutputVisitor visitor = new PluginOutputVisitor(xsdDoc, mp.getModel()); rootElement.accept(visitor, outputDocument, null, null); // postegenerate for (Iterator genIterator = generatorMap.values().iterator(); genIterator.hasNext();) { Generator generator = (Generator) genIterator.next(); generator.postProcessModel(m); } // generate the output document File outputFile; Writer destination; if (getDestdir() != null) { String dirPath = getDestdir(); File dir = new File(dirPath); dir.mkdirs(); outputFile = new File(dir, getDestinationfilename()); destination = new FileWriter(outputFile); } else { outputFile = File.createTempFile("GenGen", ".xml"); outputFile.deleteOnExit(); destination = new OutputStreamWriter(System.out); } if (outputDocument.getRootElement() != null) { generateOutput(outputFile, outputDocument, xsdDoc, destination, generatorMap); } else { System.out.println("WARNING: no output generated, do you have root tags defined?"); } } catch (DocumentException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new RuntimeException(e); } catch (RepositoryException e) { throw new RuntimeException(e); } catch (GenerationException e) { throw new RuntimeException(e); } } } }