List of usage examples for org.dom4j Document addDocType
Document addDocType(String name, String publicId, String systemId);
From source file:org.nuclos.client.datasource.querybuilder.QueryBuilderEditor.java
License:Open Source License
/** * @return/*from w w w. j a v a 2 s. c om*/ * @throws NuclosBusinessException */ public String getXML(DatasourceEntityOptions eOptions) throws CommonBusinessException { String result = ""; try { final Document doc = DocumentHelper.createDocument(); doc.addDocType(QueryBuilderConstants.DOCTYPE, null, QueryBuilderConstants.SYSTEMID); Element root = doc.addElement(QueryBuilderConstants.DOCTYPE); Element header = root.addElement(QueryBuilderConstants.TAG_HEADER); Element tables = root.addElement(QueryBuilderConstants.TAG_TABLES); Element connectors = root.addElement(QueryBuilderConstants.TAG_CONNECTORS); Element columns = root.addElement(QueryBuilderConstants.TAG_COLUMNS); Element parameters = root.addElement(QueryBuilderConstants.TAG_PARAMETERS); Element sql = root.addElement(QueryBuilderConstants.TAG_SQL); serializeHeader(header); serializeTables(tables); serializeConnectors(connectors); serializeColumns(columns); serializeParameters(parameters); if (eOptions != null) { Element entityoptions = root.addElement(QueryBuilderConstants.TAG_ENTITYOPTIONS); entityoptions.addAttribute("dynamic", eOptions.isDynamic() ? "yes" : "no"); } final boolean bModelUsed = parent.isModelUsed(); sql.addAttribute("isModelUsed", bModelUsed ? "true" : "false"); if (!bModelUsed) { sql.addCDATA(StringUtils.emptyIfNull(parent.getSql())); } final OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); //format.setEncoding("ISO-8859-1"); final StringWriter sw = new StringWriter(); final XMLWriter xmlw = new XMLWriter(sw, format); xmlw.write(doc); xmlw.close(); result = sw.toString(); } catch (IOException ex) { throw new NuclosFatalException(ex); } return result; }
From source file:org.olat.ims.qti.qpool.ItemFileResourceValidator.java
License:Apache License
private boolean validateXml(InputStream in) { boolean valid = false; Document doc = readDocument(in); if (doc != null) { DocumentType docType = doc.getDocType(); if (docType == null) { doc.addDocType("questestinterop", null, "ims_qtiasiv1p2p1.dtd"); }/*from w w w .j a v a 2 s . c o m*/ valid = validateDocument(doc); } return valid; }
From source file:org.olat.ims.qti.qpool.QTIExportProcessor.java
License:Apache License
private Element createSectionBasedAssessment(String title) { DocumentFactory df = DocumentFactory.getInstance(); Document doc = df.createDocument(); doc.addDocType(QTIConstants.XML_DOCUMENT_ROOT, null, QTIConstants.XML_DOCUMENT_DTD); /*/*from ww w .ja va2s . co m*/ <questestinterop> <assessment ident="frentix_9_87230240084930" title="SR Test"> */ Element questestinterop = doc.addElement(QTIConstants.XML_DOCUMENT_ROOT); Element assessment = questestinterop.addElement("assessment"); assessment.addAttribute("ident", CodeHelper.getGlobalForeverUniqueID()); assessment.addAttribute("title", title); //metadata /* <qtimetadata> <qtimetadatafield> <fieldlabel>qmd_assessmenttype</fieldlabel> <fieldentry>Assessment</fieldentry> </qtimetadatafield> </qtimetadata> */ Element qtimetadata = assessment.addElement("qtimetadata"); addMetadataField("qmd_assessmenttype", "Assessment", qtimetadata); //section /* <section ident="frentix_9_87230240084931" title="Section"> <selection_ordering> <selection/> <order order_type="Sequential"/> </selection_ordering> */ Element section = assessment.addElement("section"); section.addAttribute("ident", CodeHelper.getGlobalForeverUniqueID()); section.addAttribute("title", "Section"); Element selectionOrdering = section.addElement("selection_ordering"); selectionOrdering.addElement("selection"); Element order = selectionOrdering.addElement("order"); order.addAttribute("order_type", "Sequential"); return section; }
From source file:org.pentaho.jfreereport.wizard.utility.report.ReportGenerationUtility.java
License:Open Source License
/** * From the report description in the <param>reportSpec</param> parameter, create * a JFree Report report definition in XML format, and return the XML via * the <param>outputStream</param> parameter. * //from w w w .j av a 2s . c om * @param reportSpec * @param outputStream * @param encoding * @param pageWidth * @param pageHeight * @param createTotalColumn * @param totalColumnName * @param totalColumnWidth * @param spacerWidth */ public static void createJFreeReportXML(ReportSpec reportSpec, OutputStream outputStream, String encoding, int pageWidth, int pageHeight, boolean createTotalColumn, String totalColumnName, int totalColumnWidth, int spacerWidth) { Field fields[] = reportSpec.getField(); Field details[] = ReportSpecUtility.getDetails(fields); Field groups[] = ReportSpecUtility.getGroups(fields); List spaceFields = setupSpaceFields(fields); try { boolean expressionExists = ReportSpecUtility.doesExpressionExist(fields); setupDetailFieldWidths(reportSpec, details); int itemRowHeight = ReportSpecUtility.getRowHeight(reportSpec, details); // dom4j Document document = DOMDocumentFactory.getInstance().createDocument(); document.addDocType("report", "-//JFreeReport//DTD report definition//EN//simple/version 0.8.5", //$NON-NLS-1$//$NON-NLS-2$ "http://jfreereport.sourceforge.net/report-085.dtd"); //$NON-NLS-1$ org.dom4j.Element reportNode = document.addElement("report"); //$NON-NLS-1$ Element configuration = reportNode.addElement(CONFIGURATION_ELEMENT_NAME); if (null != encoding) { document.setXMLEncoding(encoding); addEncoding(configuration, encoding); } // reportNode.addAttribute("xmlns", "http://jfreereport.sourceforge.net/namespaces/reports/legacy/simple"); // add parser-config to generated report addParserConfig(reportSpec, reportNode); // set report name reportNode.addAttribute(NAME_ATTRIBUTE_NAME, StringEscapeUtils.escapeXml(reportSpec.getReportName())); // set orientation reportNode.addAttribute("orientation", reportSpec.getOrientation()); //$NON-NLS-1$ // set page-format or page width/height setPageFormat(reportSpec, reportNode, pageWidth, pageHeight); // set margins setMargins(reportSpec, reportNode); if (reportSpec.getIncludeSrc() != null && !"".equalsIgnoreCase(reportSpec.getIncludeSrc())) { //$NON-NLS-1$ org.dom4j.Element includeElement = reportNode.addElement("include"); //$NON-NLS-1$ includeElement.addAttribute("src", "file://" + reportSpec.getIncludeSrc().replace('\\', '/')); //$NON-NLS-1$ //$NON-NLS-2$ } // set watermark setWatermark(reportSpec, reportNode); Element groupsNode = reportNode.addElement("groups"); //$NON-NLS-1$ Element itemsNode = reportNode.addElement("items"); //$NON-NLS-1$ Element functionNode = reportNode.addElement("functions"); //$NON-NLS-1$ if (reportSpec.getChart() != null && reportSpec.getUseChart()) { Element reportHeaderElement = reportNode.addElement("reportheader"); //$NON-NLS-1$ addChartElement(reportSpec, null, functionNode, reportHeaderElement, 0); } setItemsFont(reportSpec, itemsNode); // create banding rectangle if banding is turned on createRowBanding(reportSpec, details, itemsNode, functionNode, itemRowHeight); // programatically create details section processDetailsSection(reportSpec, details, groups, itemsNode, functionNode, itemRowHeight); // programatically create groups section processGroupsSection(reportSpec, details, groups, groupsNode, functionNode, itemRowHeight, expressionExists, spacerWidth); // spit out report xml definition OutputFormat format = OutputFormat.createPrettyPrint(); if (null != encoding) { format.setEncoding(encoding); // TODO sbarkull, not sure this is necessary } XMLWriter writer = new XMLWriter(outputStream, format); writer.write(document); writer.close(); // put _SPACE_ fields back in place as they were for (int i = 0; i < spaceFields.size(); i++) { Field f = (Field) spaceFields.get(i); f.setName("_SPACE_" + (i + 1)); //$NON-NLS-1$ f.setDisplayName("_SPACE_" + (i + 1)); //$NON-NLS-1$ } } catch (Exception e) { getLogger().error(e.getMessage(), e); } }
From source file:org.thingml.testing.reportbuilder.ReportBuilder.java
License:Apache License
public void saveToHTML(String path) throws IOException { Document document = DocumentHelper.createDocument(); document.addDocType("html", null, null); Element html = document.addElement("html"); Element head = html.addElement("head"); Element body = html.addElement("body"); buildHead(html, head);/*w ww .j a v a2 s . c om*/ buildDocument(head, body); addModal(body); OutputFormat format = OutputFormat.createPrettyPrint(); format.setExpandEmptyElements(true); FileWriter file = new FileWriter(path); HTMLWriter writer = new HTMLWriter(file, format); writer.write(document); writer.close(); }
From source file:org.unitime.timetable.dataexchange.CourseOfferingExport.java
License:Open Source License
public void saveXml(Document document, Session session, Properties parameters) throws Exception { try {/*w ww .j av a2s . c o m*/ beginTransaction(); iExportAssignments = "true".equals(parameters.getProperty("tmtbl.export.timetable", "true")); boolean examsOnly = "true".equals(parameters.getProperty("tmtbl.export.exam")); Element root = document.addElement(examsOnly ? "exams" : "offerings"); root.addAttribute("campus", session.getAcademicInitiative()); root.addAttribute("year", session.getAcademicYear()); root.addAttribute("term", session.getAcademicTerm()); root.addAttribute("dateFormat", sDateFormat.toPattern()); root.addAttribute("timeFormat", sTimeFormat.toPattern()); root.addAttribute("created", new Date().toString()); if (examsOnly) root.addAttribute("type", parameters.getProperty("tmtbl.export.exam.type", "all")); document.addDocType(examsOnly ? "exams" : "offerings", "-//UniTime//DTD University Course Timetabling/EN", "http://www.unitime.org/interface/CourseOfferingExport.dtd"); if (examsOnly) { if ("all".equals(parameters.getProperty("tmtbl.export.exam.type", "all")) || "final".equals(parameters.getProperty("tmtbl.export.exam.type", "all"))) { for (Iterator i = new TreeSet(Exam.findAllFinal(session.getUniqueId())).iterator(); i .hasNext();) { Exam exam = (Exam) i.next(); exportExam(root, null, exam, session); } } if ("all".equals(parameters.getProperty("tmtbl.export.exam.type", "all")) || "midterm".equals(parameters.getProperty("tmtbl.export.exam.type", "all"))) { for (Iterator i = new TreeSet(Exam.findAllMidterm(session.getUniqueId())).iterator(); i .hasNext();) { Exam exam = (Exam) i.next(); exportExam(root, null, exam, session); } } } else { info("Loading offerings..."); List offerings = getHibSession() .createQuery("select distinct io from InstructionalOffering io " + "inner join fetch io.courseOfferings as co inner join fetch co.subjectArea sa " + "left join fetch io.instrOfferingConfigs as ioc " + "left join fetch ioc.schedulingSubparts as ss " + "left join fetch ss.classes as c " + "where " + "io.session.uniqueId=:sessionId " + "order by sa.subjectAreaAbbreviation, co.courseNbr") .setLong("sessionId", session.getUniqueId().longValue()).setFetchSize(1000).list(); if (!"none".equals(parameters.getProperty("tmtbl.export.exam.type", "all"))) { info("Loading exams..."); List allExams = getHibSession() .createQuery("select x from Exam x left join fetch x.owners o " + "where x.session.uniqueId=:sessionId" + ("midterm".equals(parameters.getProperty("tmtbl.export.exam.type", "all")) ? " and x.examType.type=" + ExamType.sExamTypeMidterm : "") + ("final".equals(parameters.getProperty("tmtbl.export.exam.type", "all")) ? " and x.examType.type=" + ExamType.sExamTypeFinal : "")) .setLong("sessionId", session.getUniqueId().longValue()).setFetchSize(1000).list(); iExams = new Hashtable(); info("Checking exams..."); for (Iterator i = allExams.iterator(); i.hasNext();) { Exam exam = (Exam) i.next(); for (Iterator j = exam.getOwners().iterator(); j.hasNext();) { ExamOwner owner = (ExamOwner) j.next(); Long offeringId = owner.getCourse().getInstructionalOffering().getUniqueId(); TreeSet<Exam> exams = iExams.get(offeringId); if (exams == null) { exams = new TreeSet(); iExams.put(offeringId, exams); } exams.add(exam); } } } info("Exporting " + offerings.size() + " offerings ..."); for (Iterator i = offerings.iterator(); i.hasNext();) { InstructionalOffering io = (InstructionalOffering) i.next(); exportInstructionalOffering(root, io, session); } } commitTransaction(); } catch (Exception e) { fatal("Exception: " + e.getMessage(), e); rollbackTransaction(); } }
From source file:org.unitime.timetable.dataexchange.CourseTimetableExport.java
License:Open Source License
public void saveXml(Document document, Session session, Properties parameters) throws Exception { try {//from w w w . jav a 2 s. c om beginTransaction(); document.addDocType("timetable", "-//UniTime//DTD University Course Timetabling/EN", "http://www.unitime.org/interface/CourseTimetable.dtd"); Element root = document.addElement("timetable"); root.addAttribute("campus", session.getAcademicInitiative()); root.addAttribute("year", session.getAcademicYear()); root.addAttribute("term", session.getAcademicTerm()); root.addAttribute("action", "update"); root.addAttribute("dateFormat", sDateFormat.toPattern()); root.addAttribute("timeFormat", sTimeFormat.toPattern()); root.addAttribute("created", new Date().toString()); List<CourseOffering> courses = (List<CourseOffering>) getHibSession() .createQuery("select c from CourseOffering as c where " + "c.subjectArea.session.uniqueId=:sessionId " + "order by c.subjectArea.subjectAreaAbbreviation, c.courseNbr") .setLong("sessionId", session.getUniqueId().longValue()).setFetchSize(1000).list(); for (CourseOffering course : courses) { for (InstrOfferingConfig config : course.getInstructionalOffering().getInstrOfferingConfigs()) { for (SchedulingSubpart subpart : config.getSchedulingSubparts()) { if (subpart.getParentSubpart() != null) continue; for (Class_ clazz : subpart.getClasses()) { exportClass(root.addElement("class"), clazz, course, session); } } } } commitTransaction(); } catch (Exception e) { fatal("Exception: " + e.getMessage(), e); rollbackTransaction(); } }
From source file:org.unitime.timetable.dataexchange.CurriculaExport.java
License:Open Source License
public void saveXml(Document document, Session session, Properties parameters) throws Exception { try {//from ww w . ja v a 2 s . c o m beginTransaction(); List<Curriculum> curricula = getHibSession() .createQuery("select c from Curriculum c where c.academicArea.session.uniqueId = :sessionId") .setLong("sessionId", session.getUniqueId()).list(); boolean externalIds = "true" .equals(parameters.getProperty("tmtbl.export.curricula.externalIds", "true")); boolean minimalistic = "true" .equals(parameters.getProperty("tmtbl.export.curricula.minimalistic", "false")); Element root = document.addElement("curricula"); root.addAttribute("campus", session.getAcademicInitiative()); root.addAttribute("year", session.getAcademicYear()); root.addAttribute("term", session.getAcademicTerm()); root.addAttribute("created", new Date().toString()); document.addDocType("curricula", "-//UniTime//DTD University Course Timetabling/EN", "http://www.unitime.org/interface/Curricula_3_2.dtd"); if (curricula.isEmpty()) throw new Exception("No curricula defined for " + session.getLabel()); for (Curriculum curriculum : new TreeSet<Curriculum>(curricula)) { Element curriculumElement = root.addElement("curriculum"); Hashtable<Long, Integer> groupId = new Hashtable<Long, Integer>(); if (!minimalistic && curriculum.getAbbv() != null) curriculumElement.addAttribute("abbreviation", curriculum.getAbbv()); if (!minimalistic && curriculum.getName() != null) curriculumElement.addAttribute("name", curriculum.getName()); if (curriculum.getAcademicArea() != null) { Element acadAreaElement = curriculumElement.addElement("academicArea"); if (externalIds && curriculum.getAcademicArea().getExternalUniqueId() != null) { acadAreaElement.addAttribute("externalId", curriculum.getAcademicArea().getExternalUniqueId()); } acadAreaElement.addAttribute("abbreviation", curriculum.getAcademicArea().getAcademicAreaAbbreviation()); } if (!minimalistic && curriculum.getDepartment() != null) { Element departmentElement = curriculumElement.addElement("department"); if (externalIds && curriculum.getDepartment().getExternalUniqueId() != null) { departmentElement.addAttribute("externalId", curriculum.getDepartment().getExternalUniqueId()); } departmentElement.addAttribute("code", curriculum.getDepartment().getDeptCode()); } for (PosMajor major : (Collection<PosMajor>) curriculum.getMajors()) { Element majorElement = curriculumElement.addElement("major"); if (externalIds && major.getExternalUniqueId() != null) { majorElement.addAttribute("externalId", major.getExternalUniqueId()); } majorElement.addAttribute("code", major.getCode()); } for (CurriculumClassification clasf : new TreeSet<CurriculumClassification>( curriculum.getClassifications())) { Element clasfElement = curriculumElement.addElement("classification"); if (!minimalistic && clasf.getName() != null) { clasfElement.addAttribute("name", clasf.getName()); } if (clasf.getAcademicClassification() != null) { Element acadClasfElement = clasfElement.addElement("academicClassification"); if (externalIds && clasf.getAcademicClassification().getExternalUniqueId() != null) { acadClasfElement.addAttribute("externalId", clasf.getAcademicClassification().getExternalUniqueId()); } acadClasfElement.addAttribute("code", clasf.getAcademicClassification().getCode()); } if (clasf.getNrStudents() != null) clasfElement.addAttribute("enrollment", clasf.getNrStudents().toString()); for (CurriculumCourse course : new TreeSet<CurriculumCourse>(clasf.getCourses())) { Element courseElement = clasfElement.addElement("course"); if (externalIds && course.getCourse().getExternalUniqueId() != null) courseElement.addAttribute("externalId", course.getCourse().getExternalUniqueId()); courseElement.addAttribute("subject", course.getCourse().getSubjectArea().getSubjectAreaAbbreviation()); courseElement.addAttribute("courseNbr", course.getCourse().getCourseNbr()); if (!minimalistic || course.getPercShare() != 1.0f) courseElement.addAttribute("share", iShareDF.format(course.getPercShare())); for (CurriculumCourseGroup group : (Collection<CurriculumCourseGroup>) course.getGroups()) { Integer gid = groupId.get(group.getUniqueId()); if (gid == null) { gid = groupId.size() + 1; groupId.put(group.getUniqueId(), gid); } Element groupElement = courseElement.addElement("group"); groupElement.addAttribute("id", gid.toString()); if (!minimalistic && group.getName() != null) groupElement.addAttribute("name", group.getName()); if (!minimalistic || group.getType() != 0) groupElement.addAttribute("type", group.getType() == 1 ? "REQ" : "OPT"); } } } } commitTransaction(); } catch (Exception e) { fatal("Exception: " + e.getMessage(), e); rollbackTransaction(); } }
From source file:org.unitime.timetable.dataexchange.LastLikeCourseDemandExport.java
License:Open Source License
@Override public void saveXml(Document document, Session session, Properties parameters) throws Exception { try {//from w w w . j ava 2s .c o m beginTransaction(); Element root = document.addElement("lastLikeCourseDemand"); root.addAttribute("campus", session.getAcademicInitiative()); root.addAttribute("year", session.getAcademicYear()); root.addAttribute("term", session.getAcademicTerm()); root.addAttribute("created", new Date().toString()); document.addDocType("lastLikeCourseDemand", "-//UniTime//DTD University Course Timetabling/EN", "http://www.unitime.org/interface/StudentCourse.dtd"); String lastExternalId = null; Element studentEl = null; Map<String, CourseOffering> permId2course = new Hashtable<String, CourseOffering>(); for (CourseOffering course : (List<CourseOffering>) getHibSession() .createQuery("from CourseOffering co where co.subjectArea.session.uniqueId = :sessionId") .setLong("sessionId", session.getUniqueId()).list()) { if (course.getPermId() != null) permId2course.put(course.getPermId(), course); } for (LastLikeCourseDemand demand : (List<LastLikeCourseDemand>) getHibSession() .createQuery("from LastLikeCourseDemand d where d.subjectArea.session.uniqueId = :sessionId " + "order by d.student.externalUniqueId, d.priority, d.subjectArea.subjectAreaAbbreviation, d.courseNbr") .setLong("sessionId", session.getUniqueId()).list()) { if (!demand.getStudent().getExternalUniqueId().equals(lastExternalId)) { lastExternalId = demand.getStudent().getExternalUniqueId(); studentEl = root.addElement("student"); studentEl.addAttribute("externalId", lastExternalId); } Element demandEl = studentEl.addElement("studentCourse"); CourseOffering course = (demand.getCoursePermId() == null ? null : permId2course.get(demand.getCoursePermId())); if (course == null) { demandEl.addAttribute("subject", demand.getSubjectArea().getSubjectAreaAbbreviation()); demandEl.addAttribute("courseNumber", demand.getCourseNbr()); } else { demandEl.addAttribute("subject", course.getSubjectAreaAbbv()); demandEl.addAttribute("courseNumber", course.getCourseNbr()); } } commitTransaction(); } catch (Exception e) { fatal("Exception: " + e.getMessage(), e); rollbackTransaction(); } }
From source file:org.unitime.timetable.dataexchange.PermissionsExport.java
License:Open Source License
public void saveXml(Document document, Session session, Properties parameters) throws Exception { try {//from ww w . j a v a 2 s .c o m beginTransaction(); Element root = document.addElement("permissions"); root.addAttribute("created", new Date().toString()); document.addDocType("curricula", "-//UniTime//DTD University Course Timetabling/EN", "http://www.unitime.org/interface/Permissions.dtd"); for (Roles role : RolesDAO.getInstance().findAll(getHibSession(), Order.asc("abbv"))) { Element r = root.addElement("role"); r.addAttribute("reference", role.getReference()); r.addAttribute("name", role.getAbbv()); r.addAttribute("manager", role.isManager() ? "true" : "false"); r.addAttribute("enabled", role.isEnabled() ? "true" : "false"); r.addAttribute("instructor", role.isInstructor() ? "true" : "false"); for (Right right : Right.values()) { if (role.hasRight(right)) r.addElement("right").setText(right.name()); } } commitTransaction(); } catch (Exception e) { fatal("Exception: " + e.getMessage(), e); rollbackTransaction(); } }