use of org.dom4j.Document in project tdi-studio-se by Talend.
the class HTMLDocGenerator method parseXml2HtmlPdf.
private List<URL> parseXml2HtmlPdf(String tempFolderPath, String jobName, String xslFilePath) throws Exception {
// clear the cache, maybe need improve it latter.
HTMLHandler.clearExternalNodeFileCache();
String htmlFilePath = tempFolderPath + File.separatorChar + jobName + IHTMLDocConstants.HTML_FILE_SUFFIX;
String xmlFilePath = tempFolderPath + File.separatorChar + jobName + IHTMLDocConstants.XML_FILE_SUFFIX;
HTMLHandler.generateHTMLFile(tempFolderPath, xslFilePath, xmlFilePath, htmlFilePath, this.externalNodeHTMLMap);
// for pdf
File originalXmlFile = new File(xmlFilePath);
if (originalXmlFile.exists()) {
//$NON-NLS-1$
String pdfXmlPath = tempFolderPath + File.separatorChar + "pdf_" + jobName + IHTMLDocConstants.XML_FILE_SUFFIX;
File pdfXmlFile = new File(pdfXmlPath);
if (pdfXmlFile.exists()) {
pdfXmlFile.delete();
}
FilesUtils.copyFile(originalXmlFile, pdfXmlFile);
SAXReader saxReader = new SAXReader();
Document document = saxReader.read(pdfXmlPath);
//$NON-NLS-1$
Attribute attri = (Attribute) document.selectNodes("/project/job/preview/@picture").get(0);
//$NON-NLS-1$
attri.setValue(IHTMLDocConstants.PICTUREFOLDERPATH + "pdf_" + jobName + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX);
//$NON-NLS-1$
List attributeList = document.selectNodes("/project/job/externalNodeComponents/component/@preview");
for (int i = 0; i < attributeList.size(); i++) {
Attribute at = (Attribute) attributeList.get(i);
//$NON-NLS-1$
String externalValue = at.getValue().substring(at.getValue().indexOf("/") + 1);
//$NON-NLS-1$
String value = IHTMLDocConstants.PICTUREFOLDERPATH + "pdf_" + externalValue;
at.setValue(value);
}
XMLHandler.generateXMLFile(tempFolderPath, pdfXmlPath, document);
HTMLHandler.clearExternalNodeFileCache();
//$NON-NLS-1$
String htmlPdfPath = tempFolderPath + File.separatorChar + "pdf_" + jobName + IHTMLDocConstants.HTML_FILE_SUFFIX;
HTMLHandler.generateHTMLFile(tempFolderPath, xslFilePath, pdfXmlPath, htmlPdfPath, this.externalNodeHTMLMap);
}
return getParsedUrl(tempFolderPath);
}
use of org.dom4j.Document in project tesb-studio-se by Talend.
the class AddSpringConfigurationPropertyMigrationTask method addIgnoreExchangeEventProperty.
private void addIgnoreExchangeEventProperty(CamelProcessItem item) throws PersistenceException, DocumentException {
String springContent = item.getSpringContent();
if (null != springContent && !springContent.isEmpty()) {
Document document = DocumentHelper.parseText(springContent);
QName qname = QName.get("bean", SPRING_BEANS_NAMESPACE);
List<Element> beans = document.getRootElement().elements(qname);
for (Element bean : beans) {
if ("jmxEventNotifier".equals(bean.attributeValue("id")) && "org.apache.camel.management.JmxNotificationEventNotifier".equals(bean.attributeValue("class"))) {
List<Element> properties = bean.elements(QName.get("property", SPRING_BEANS_NAMESPACE));
boolean hasIgnore = false;
for (Element property : properties) {
List<Attribute> propertyAttributes = property.attributes();
for (Attribute propertyAttribute : propertyAttributes) {
if (propertyAttribute.getValue().equals(IGNORE_EXCHANGE_EVENTS)) {
hasIgnore = true;
break;
}
}
}
if (!hasIgnore) {
DefaultElement ignoreExchangeElement = new DefaultElement("property", bean.getNamespace());
ignoreExchangeElement.add(DocumentHelper.createAttribute(ignoreExchangeElement, "name", IGNORE_EXCHANGE_EVENTS));
ignoreExchangeElement.add(DocumentHelper.createAttribute(ignoreExchangeElement, "value", "true"));
bean.add(ignoreExchangeElement);
item.setSpringContent(document.asXML());
saveItem(item);
}
break;
}
}
}
}
use of org.dom4j.Document in project cpsolver by UniTime.
the class GetInfo method getInfo.
public static void getInfo(File folder, List<Info> infos, String prefix) {
File infoFile = new File(folder, "info.xml");
if (infoFile.exists()) {
System.out.println("Reading " + infoFile + " ...");
try {
Document document = (new SAXReader()).read(infoFile);
HashMap<String, String> info = getInfo(document.getRootElement());
if (info != null && !info.isEmpty()) {
infos.add(new Info(prefix, info));
return;
}
} catch (Exception e) {
System.err.println("Error reading file " + infoFile + ", message: " + e.getMessage());
}
}
File solutionFile = new File(folder, "solution.xml");
if (solutionFile.exists()) {
/*
* File newOutputFile = new File(folder, "new-output.csv"); if
* (newOutputFile.exists()) {
* System.out.println("Reading "+newOutputFile+" ..."); try {
* HashMap info = getInfo(newOutputFile); if (info!=null &&
* !info.isEmpty()) { infos.addElement(new Object[]{prefix,info});
* return; } } catch (Exception e) {
* System.err.println("Error reading file "
* +infoFile+", message: "+e.getMessage()); } }
*/
System.out.println("Reading " + solutionFile + " ...");
try {
HashMap<String, String> info = getInfoOfASolution(solutionFile);
if (info != null && !info.isEmpty()) {
infos.add(new Info(prefix, info));
return;
}
} catch (Exception e) {
System.err.println("Error reading file " + infoFile + ", message: " + e.getMessage());
}
}
File outputFile = new File(folder, "output.csv");
if (outputFile.exists()) {
System.out.println("Reading " + outputFile + " ...");
try {
HashMap<String, String> info = getInfo(outputFile);
if (info != null && !info.isEmpty()) {
infos.add(new Info(prefix, info));
return;
}
} catch (Exception e) {
System.err.println("Error reading file " + infoFile + ", message: " + e.getMessage());
}
}
}
use of org.dom4j.Document in project cpsolver by UniTime.
the class Test method loadLastLikeCourseDemandsXml.
/**
* Load last-like students from an XML file (the one that is used to load
* last like course demands table in the timetabling application)
* @param model problem model
* @param xml an XML file
*/
public static void loadLastLikeCourseDemandsXml(StudentSectioningModel model, File xml) {
try {
Document document = (new SAXReader()).read(xml);
Element root = document.getRootElement();
HashMap<Course, List<Request>> requests = new HashMap<Course, List<Request>>();
long reqId = 0;
for (Iterator<?> i = root.elementIterator("student"); i.hasNext(); ) {
Element studentEl = (Element) i.next();
Student student = new Student(Long.parseLong(studentEl.attributeValue("externalId")));
student.setDummy(true);
int priority = 0;
HashSet<Course> reqCourses = new HashSet<Course>();
for (Iterator<?> j = studentEl.elementIterator("studentCourse"); j.hasNext(); ) {
Element courseEl = (Element) j.next();
String subjectArea = courseEl.attributeValue("subject");
String courseNbr = courseEl.attributeValue("courseNumber");
Course course = null;
offerings: for (Offering offering : model.getOfferings()) {
for (Course c : offering.getCourses()) {
if (c.getSubjectArea().equals(subjectArea) && c.getCourseNumber().equals(courseNbr)) {
course = c;
break offerings;
}
}
}
if (course == null && courseNbr.charAt(courseNbr.length() - 1) >= 'A' && courseNbr.charAt(courseNbr.length() - 1) <= 'Z') {
String courseNbrNoSfx = courseNbr.substring(0, courseNbr.length() - 1);
offerings: for (Offering offering : model.getOfferings()) {
for (Course c : offering.getCourses()) {
if (c.getSubjectArea().equals(subjectArea) && c.getCourseNumber().equals(courseNbrNoSfx)) {
course = c;
break offerings;
}
}
}
}
if (course == null) {
sLog.warn("Course " + subjectArea + " " + courseNbr + " not found.");
} else {
if (!reqCourses.add(course)) {
sLog.warn("Course " + subjectArea + " " + courseNbr + " already requested.");
} else {
List<Course> courses = new ArrayList<Course>(1);
courses.add(course);
CourseRequest request = new CourseRequest(reqId++, priority++, false, student, courses, false, null);
List<Request> requestsThisCourse = requests.get(course);
if (requestsThisCourse == null) {
requestsThisCourse = new ArrayList<Request>();
requests.put(course, requestsThisCourse);
}
requestsThisCourse.add(request);
}
}
}
if (!student.getRequests().isEmpty())
model.addStudent(student);
}
for (Map.Entry<Course, List<Request>> entry : requests.entrySet()) {
Course course = entry.getKey();
List<Request> requestsThisCourse = entry.getValue();
double weight = getLastLikeStudentWeight(course, 0, requestsThisCourse.size());
for (Request request : requestsThisCourse) {
request.setWeight(weight);
}
}
} catch (Exception e) {
sLog.error(e.getMessage(), e);
}
}
use of org.dom4j.Document in project cpsolver by UniTime.
the class Test method loadStudentInfoXml.
/** Load student infos from a given XML file.
* @param model problem model
* @param xml an XML file
**/
public static void loadStudentInfoXml(StudentSectioningModel model, File xml) {
try {
sLog.info("Loading student infos from " + xml);
Document document = (new SAXReader()).read(xml);
Element root = document.getRootElement();
HashMap<Long, Student> studentTable = new HashMap<Long, Student>();
for (Student student : model.getStudents()) {
studentTable.put(new Long(student.getId()), student);
}
for (Iterator<?> i = root.elementIterator("student"); i.hasNext(); ) {
Element studentEl = (Element) i.next();
Student student = studentTable.get(Long.valueOf(studentEl.attributeValue("externalId")));
if (student == null) {
sLog.debug(" -- student " + studentEl.attributeValue("externalId") + " not found");
continue;
}
sLog.debug(" -- loading info for student " + student);
student.getAcademicAreaClasiffications().clear();
if (studentEl.element("studentAcadAreaClass") != null)
for (Iterator<?> j = studentEl.element("studentAcadAreaClass").elementIterator("acadAreaClass"); j.hasNext(); ) {
Element studentAcadAreaClassElement = (Element) j.next();
student.getAcademicAreaClasiffications().add(new AcademicAreaCode(studentAcadAreaClassElement.attributeValue("academicArea"), studentAcadAreaClassElement.attributeValue("academicClass")));
}
sLog.debug(" -- acad areas classifs " + student.getAcademicAreaClasiffications());
student.getMajors().clear();
if (studentEl.element("studentMajors") != null)
for (Iterator<?> j = studentEl.element("studentMajors").elementIterator("major"); j.hasNext(); ) {
Element studentMajorElement = (Element) j.next();
student.getMajors().add(new AcademicAreaCode(studentMajorElement.attributeValue("academicArea"), studentMajorElement.attributeValue("code")));
}
sLog.debug(" -- majors " + student.getMajors());
student.getMinors().clear();
if (studentEl.element("studentMinors") != null)
for (Iterator<?> j = studentEl.element("studentMinors").elementIterator("minor"); j.hasNext(); ) {
Element studentMinorElement = (Element) j.next();
student.getMinors().add(new AcademicAreaCode(studentMinorElement.attributeValue("academicArea", ""), studentMinorElement.attributeValue("code", "")));
}
sLog.debug(" -- minors " + student.getMinors());
}
} catch (Exception e) {
sLog.error(e.getMessage(), e);
}
}
Aggregations