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);
}
}
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);
}
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;
}
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);
}
}
}
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);
}
Aggregations