Search in sources :

Example 11 with Document

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);
    }
}
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 12 with Document

use of org.dom4j.Document in project tdi-studio-se by Talend.

the class JobJavaScriptsManager method updateMavenBuildFileContent.

protected void updateMavenBuildFileContent(File mavenBuildFile, Map<String, String> mavenPropertiesMap, boolean addDependencies, boolean updateModules) throws DocumentException, IOException {
    SAXReader saxReader = new SAXReader();
    Document pomDocument = saxReader.read(mavenBuildFile);
    setMavenBuildScriptProperties(pomDocument, mavenPropertiesMap);
    if (updateModules) {
        setMavenBuildScriptModules(pomDocument);
    }
    if (addDependencies) {
        setMavenDependencyElements(pomDocument);
    }
    saveXmlDocoment(pomDocument, mavenBuildFile);
}
Also used : SAXReader(org.dom4j.io.SAXReader) Document(org.dom4j.Document)

Example 13 with Document

use of org.dom4j.Document in project cubrid-manager by CUBRID.

the class SqlMapCondition method getIncludedStatement.

public String getIncludedStatement() {
    if (this.includedStatement == null) {
        if (this.statement == null) {
            throw new NullPointerException("The statement field couldn't be a null.");
        }
        SAXReader reader = new SAXReader(false);
        Document document = null;
        try {
            InputSource source = new InputSource(new StringReader(this.statement));
            document = reader.read(source);
        } catch (DocumentException e) {
            ExceptionUtils.printRootCauseStackTrace(e);
            throw new IllegalArgumentException("fail to parse condition", e);
        }
        // include 처리용 statement 저장
        Element copiedElement = document.getRootElement().createCopy();
        copiedElement.clearContent();
        copiedElement.setText(this.modifiedStatement);
        this.includedStatement = copiedElement.asXML();
    }
    return includedStatement;
}
Also used : InputSource(org.xml.sax.InputSource) SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) StringReader(java.io.StringReader) Document(org.dom4j.Document)

Example 14 with Document

use of org.dom4j.Document in project cubrid-manager by CUBRID.

the class Parser method parse.

public void parse(SqlMapFile sqlMapFile) throws Exception {
    Document document;
    if (StringUtils.isEmpty(sqlMapFile.getFileContent())) {
        sqlMapFile.setErrorMessage(Messages.sqlmapEmptyContent);
        throw new Exception(Messages.sqlmapEmptyContent);
    }
    // create a XML document with SQLMap document.
    try {
        document = createDocument(sqlMapFile.getFileContent());
    } catch (Exception e) {
        sqlMapFile.setErrorMessage(Messages.sqlmapInvalidFormat);
        throw new Exception(Messages.sqlmapInvalidFormat, e);
    }
    // determine whether iBatis(sqlMap) or MyBatis(mapper) from the document header.
    if (!isMapperXML(document)) {
        sqlMapFile.setErrorMessage(Messages.sqlmapNoMybatisFormat);
        throw new Exception(Messages.sqlmapNoMybatisFormat);
    }
    // generate a namespace
    String namespace = SqlMapParserUtil.getAttribute(document.getRootElement(), "namespace");
    sqlMapFile.setNamespace(namespace);
    logger.debug("namespace:" + namespace);
    // parse sqlmap document
    try {
        loopNode(document, sqlMapFile);
    } catch (Exception e) {
        sqlMapFile.setErrorMessage(Messages.sqlmapNoMybatisFormat);
        throw new Exception(Messages.sqlmapNoMybatisFormat, e);
    }
    // replace <include refid=""></include> by referred sql through the refid
    for (SqlMapQuery query : sqlMapFile.getSqlMapQueryList()) {
        // find Include condition in queries
        for (SqlMapCondition condition : query.getConditionList()) {
            mergeInclude(sqlMapFile, query, condition);
        }
    }
}
Also used : SqlMapQuery(com.nhn.dbtool.query.parser.sqlmap.model.SqlMapQuery) Document(org.dom4j.Document) DocumentException(org.dom4j.DocumentException) SqlMapCondition(com.nhn.dbtool.query.parser.sqlmap.model.SqlMapCondition)

Example 15 with Document

use of org.dom4j.Document in project Openfire by igniterealtime.

the class Xep227Exporter method importUsers.

/* (non-Javadoc)
   * @see org.jivesoftware.openfire.plugin.InExporter#importUsers(java.io.InputStream, java.lang.String, boolean)
   */
@Override
public List<String> importUsers(InputStream inputStream, String previousDomain, boolean isUserProviderReadOnly) {
    Log.debug("importUsers");
    DOMReader xmlReader = new DOMReader();
    Document doc = xmlReader.read(new UserSchemaValidator(inputStream).validateAndParse());
    return importUsers(doc, previousDomain, isUserProviderReadOnly);
}
Also used : DOMReader(org.dom4j.io.DOMReader) Document(org.dom4j.Document)

Aggregations

Document (org.dom4j.Document)891 Element (org.dom4j.Element)492 SAXReader (org.dom4j.io.SAXReader)252 File (java.io.File)135 IOException (java.io.IOException)135 StringReader (java.io.StringReader)111 ArrayList (java.util.ArrayList)110 List (java.util.List)107 Test (org.junit.Test)101 DocumentException (org.dom4j.DocumentException)93 HashMap (java.util.HashMap)90 InputStream (java.io.InputStream)82 Node (org.dom4j.Node)80 Test (org.junit.jupiter.api.Test)80 XMLWriter (org.dom4j.io.XMLWriter)53 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)48 FileInputStream (java.io.FileInputStream)45 Map (java.util.Map)41 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)40 XMLParser (org.olat.core.util.xml.XMLParser)40