use of org.dom4j.Element in project tdi-studio-se by Talend.
the class HTMLDocGenerator method getComponentListInfo.
/**
* DOC tang Comment method "getComponentListInfo".
*
* @param inputJobElement
* @param allComponentsList
* @param componentNameListElement
* @param screenshotOffset
*/
protected void getComponentListInfo(Element inputJobElement, List<INode> allComponentsList, Element componentNameListElement, Point screenshotOffset) {
int x = 0, y = 0, width = 0, height = 0;
for (INode node : allComponentsList) {
x = node.getPosX() + screenshotOffset.x;
y = node.getPosY() + screenshotOffset.y;
Image icon = CoreImageProvider.getComponentIcon(node.getComponent(), ICON_SIZE.ICON_32);
if (icon != null) {
ImageData imageData = icon.getImageData();
if (imageData != null) {
width = imageData.width;
height = imageData.height;
}
}
if (componentNameListElement == null) {
//$NON-NLS-1$
componentNameListElement = inputJobElement.addElement("componentList");
}
Element componentItemElement = null;
//$NON-NLS-1$
componentItemElement = componentNameListElement.addElement("componentItem");
//$NON-NLS-1$
componentItemElement.addAttribute("name", node.getUniqueName());
//$NON-NLS-1$
componentItemElement.addAttribute("link", node.getUniqueName());
//$NON-NLS-1$
componentItemElement.addAttribute("type", node.getComponent().getName());
//$NON-NLS-1$ //$NON-NLS-2$
componentItemElement.addAttribute("leftTopX", x + "");
//$NON-NLS-1$ //$NON-NLS-2$
componentItemElement.addAttribute("leftTopY", y + "");
//$NON-NLS-1$ //$NON-NLS-2$
componentItemElement.addAttribute("rightBottomX", x + width + "");
//$NON-NLS-1$ //$NON-NLS-2$
componentItemElement.addAttribute("rightBottomY", y + height + "");
}
}
use of org.dom4j.Element 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);
}
}
use of org.dom4j.Element in project cpsolver by UniTime.
the class StudentSectioningXMLLoader method loadStudents.
/**
* Load students
* @param studentsEl students element
* @param offeringTable offering table
* @param courseTable course table
*/
protected void loadStudents(Element studentsEl, Map<Long, Offering> offeringTable, Map<Long, Course> courseTable) {
List<Enrollment> bestEnrollments = new ArrayList<Enrollment>();
List<Enrollment> currentEnrollments = new ArrayList<Enrollment>();
for (Iterator<?> i = studentsEl.elementIterator("student"); i.hasNext(); ) {
Element studentEl = (Element) i.next();
Student student = loadStudent(studentEl, offeringTable);
if (iStudentFilter != null && !iStudentFilter.accept(student))
continue;
for (Iterator<?> j = studentEl.elementIterator(); j.hasNext(); ) {
Element requestEl = (Element) j.next();
Request request = loadRequest(requestEl, student, offeringTable, courseTable);
if (request == null)
continue;
Element initialEl = requestEl.element("initial");
if (iLoadInitial && initialEl != null) {
Enrollment enrollment = loadEnrollment(initialEl, request);
if (enrollment != null)
request.setInitialAssignment(enrollment);
}
Element currentEl = requestEl.element("current");
if (iLoadCurrent && currentEl != null) {
Enrollment enrollment = loadEnrollment(currentEl, request);
if (enrollment != null)
currentEnrollments.add(enrollment);
}
Element bestEl = requestEl.element("best");
if (iLoadBest && bestEl != null) {
Enrollment enrollment = loadEnrollment(bestEl, request);
if (enrollment != null)
bestEnrollments.add(enrollment);
}
}
getModel().addStudent(student);
}
if (!bestEnrollments.isEmpty()) {
// Enrollments with a reservation must go first
for (Enrollment enrollment : bestEnrollments) {
if (enrollment.getReservation() == null)
continue;
if (!enrollment.getStudent().isAvailable(enrollment)) {
sLogger.warn("Enrollment " + enrollment + " is conflicting: student not available.");
continue;
}
Map<Constraint<Request, Enrollment>, Set<Enrollment>> conflicts = getModel().conflictConstraints(getAssignment(), enrollment);
if (conflicts.isEmpty())
getAssignment().assign(0, enrollment);
else
sLogger.warn("Enrollment " + enrollment + " conflicts with " + conflicts);
}
for (Enrollment enrollment : bestEnrollments) {
if (enrollment.getReservation() != null)
continue;
if (!enrollment.getStudent().isAvailable(enrollment)) {
sLogger.warn("Enrollment " + enrollment + " is conflicting: student not available.");
continue;
}
Map<Constraint<Request, Enrollment>, Set<Enrollment>> conflicts = getModel().conflictConstraints(getAssignment(), enrollment);
if (conflicts.isEmpty())
getAssignment().assign(0, enrollment);
else
sLogger.warn("Enrollment " + enrollment + " conflicts with " + conflicts);
}
getModel().saveBest(getAssignment());
}
if (!currentEnrollments.isEmpty()) {
for (Request request : getModel().variables()) getAssignment().unassign(0, request);
// Enrollments with a reservation must go first
for (Enrollment enrollment : currentEnrollments) {
if (enrollment.getReservation() == null)
continue;
if (!enrollment.getStudent().isAvailable(enrollment)) {
sLogger.warn("Enrollment " + enrollment + " is conflicting: student not available.");
continue;
}
Map<Constraint<Request, Enrollment>, Set<Enrollment>> conflicts = getModel().conflictConstraints(getAssignment(), enrollment);
if (conflicts.isEmpty())
getAssignment().assign(0, enrollment);
else
sLogger.warn("Enrollment " + enrollment + " conflicts with " + conflicts);
}
for (Enrollment enrollment : currentEnrollments) {
if (enrollment.getReservation() != null)
continue;
if (!enrollment.getStudent().isAvailable(enrollment)) {
sLogger.warn("Enrollment " + enrollment + " is conflicting: student not available.");
continue;
}
Map<Constraint<Request, Enrollment>, Set<Enrollment>> conflicts = getModel().conflictConstraints(getAssignment(), enrollment);
if (conflicts.isEmpty())
getAssignment().assign(0, enrollment);
else
sLogger.warn("Enrollment " + enrollment + " conflicts with " + conflicts);
}
}
}
use of org.dom4j.Element in project tdi-studio-se by Talend.
the class JobJavaScriptsManager method addMavenDependencyElements.
protected void addMavenDependencyElements(Document pomDocument, Set<ModuleNeeded> neededModules, String libFolder) {
Element rootElement = pomDocument.getRootElement();
Element parentEle = rootElement.element(IMavenProperties.ELE_DEPENDENCIES);
if (parentEle == null) {
parentEle = rootElement.addElement(IMavenProperties.ELE_DEPENDENCIES);
}
removeComments(parentEle);
List<ModuleNeeded> modelesList = new ArrayList<ModuleNeeded>();
modelesList.addAll(neededModules);
Collections.sort(modelesList, new Comparator<ModuleNeeded>() {
@Override
public int compare(ModuleNeeded m1, ModuleNeeded m2) {
return m1.getModuleName().compareToIgnoreCase(m2.getModuleName());
}
});
for (ModuleNeeded module : modelesList) {
addMavenDependencyElement(parentEle, module.getModuleName(), libFolder);
}
}
use of org.dom4j.Element in project tdi-studio-se by Talend.
the class DbMapComponentDocumentation method generateXMLInfo.
/**
* Generates all information which for XML file.
*/
private void generateXMLInfo() {
document = DocumentHelper.createDocument();
//$NON-NLS-1$
Element externalNodeElement = document.addElement("externalNode");
generateMessages(externalNodeElement);
//$NON-NLS-1$
externalNodeElement.addAttribute("name", HTMLDocUtils.checkString(this.componentName));
//$NON-NLS-1$
externalNodeElement.addAttribute("preview", HTMLDocUtils.checkString(this.previewPicPath));
List<ExternalDbMapTable> inputTables = externalData.getInputTables();
List<ExternalDbMapTable> outputTables = externalData.getOutputTables();
List<ExternalDbMapTable> varTables = externalData.getVarsTables();
handleMapperTablesInfo(inputTables, externalNodeElement, IHTMLDocConstants.MAPPER_TABLE_INPUT);
handleMapperTablesInfo(outputTables, externalNodeElement, IHTMLDocConstants.MAPPER_TABLE_OUPUT);
handleMapperTablesInfo(varTables, externalNodeElement, IHTMLDocConstants.MAPPER_TABLE_VAR);
}
Aggregations