Search in sources :

Example 91 with Element

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 + "");
    }
}
Also used : INode(org.talend.core.model.process.INode) ImageData(org.eclipse.swt.graphics.ImageData) Element(org.dom4j.Element) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.draw2d.geometry.Point)

Example 92 with Element

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);
    }
}
Also used : HashMap(java.util.HashMap) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) Iterator(java.util.Iterator) AcademicAreaCode(org.cpsolver.studentsct.model.AcademicAreaCode) Document(org.dom4j.Document) Student(org.cpsolver.studentsct.model.Student) IOException(java.io.IOException)

Example 93 with Element

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);
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) BitSet(java.util.BitSet) Constraint(org.cpsolver.ifs.model.Constraint) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment) Student(org.cpsolver.studentsct.model.Student)

Example 94 with Element

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);
    }
}
Also used : Element(org.dom4j.Element) ArrayList(java.util.ArrayList) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 95 with Element

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);
}
Also used : ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) Element(org.dom4j.Element)

Aggregations

Element (org.dom4j.Element)2207 Document (org.dom4j.Document)500 ArrayList (java.util.ArrayList)294 List (java.util.List)249 SAXReader (org.dom4j.io.SAXReader)196 Iterator (java.util.Iterator)163 IQ (org.xmpp.packet.IQ)142 HashMap (java.util.HashMap)135 IOException (java.io.IOException)114 File (java.io.File)101 Attribute (org.dom4j.Attribute)97 StringReader (java.io.StringReader)90 DefaultElement (org.dom4j.tree.DefaultElement)87 JID (org.xmpp.packet.JID)87 Test (org.junit.jupiter.api.Test)78 DocumentException (org.dom4j.DocumentException)74 QName (org.dom4j.QName)68 AnnotatedElement (java.lang.reflect.AnnotatedElement)64 Node (org.dom4j.Node)64 Test (org.junit.Test)64