use of org.dom4j.Attribute in project jbosstools-hibernate by jbosstools.
the class OpenMappingUtils method tableInFile.
/**
* Check has this particular table correspondence in the file.
* @param consoleConfig
* @param file
* @param table
* @return
*/
@SuppressWarnings("unchecked")
public static boolean tableInFile(ConsoleConfiguration consoleConfig, IFile file, ITable table) {
EntityResolver entityResolver = consoleConfig.getConfiguration().getEntityResolver();
Document doc = getDocument(file.getLocation().toFile(), entityResolver);
Iterator<Element> classes = getElements(doc, HIBERNATE_TAG_CLASS);
boolean res = false;
while (classes.hasNext()) {
Element element = classes.next();
Attribute tableAttr = element.attribute(HIBERNATE_TAG_TABLE);
if (tableAttr != null) {
Attribute catalogAttr = element.attribute(HIBERNATE_TAG_CATALOG);
if (catalogAttr == null) {
catalogAttr = doc.getRootElement().attribute(HIBERNATE_TAG_CATALOG);
}
Attribute schemaAttr = element.attribute(HIBERNATE_TAG_SCHEMA);
if (schemaAttr == null) {
schemaAttr = doc.getRootElement().attribute(HIBERNATE_TAG_SCHEMA);
}
String catalog = catalogAttr != null ? catalogAttr.getValue() : null;
String schema = schemaAttr != null ? schemaAttr.getValue() : null;
String name = tableAttr.getValue();
if (getTableName(catalog, schema, name).equals(getTableName(table))) {
res = true;
break;
}
}
Attribute classNameAttr = element.attribute(HIBERNATE_TAG_NAME);
if (classNameAttr == null) {
classNameAttr = element.attribute(HIBERNATE_TAG_ENTITY_NAME);
}
if (classNameAttr != null) {
String physicalTableName = consoleConfig.getConfiguration().getNamingStrategy().classToTableName(classNameAttr.getValue());
if (table.getName().equals(physicalTableName)) {
res = true;
break;
}
}
}
if (!res && getElements(doc, HIBERNATE_TAG_TABLE, table.getName()).hasNext()) {
res = true;
}
if (!res) {
classes = getElements(doc, EJB_TAG_ENTITY);
while (classes.hasNext() && !res) {
Element element = classes.next();
Iterator<Element> itTables = element.elements(HIBERNATE_TAG_TABLE).iterator();
while (itTables.hasNext()) {
element = itTables.next();
Attribute tableAttr = element.attribute(HIBERNATE_TAG_NAME);
if (tableAttr != null) {
Attribute catalogAttr = element.attribute(HIBERNATE_TAG_CATALOG);
if (catalogAttr == null) {
catalogAttr = doc.getRootElement().attribute(HIBERNATE_TAG_CATALOG);
}
Attribute schemaAttr = element.attribute(HIBERNATE_TAG_SCHEMA);
if (schemaAttr == null) {
schemaAttr = doc.getRootElement().attribute(HIBERNATE_TAG_SCHEMA);
}
String catalog = catalogAttr != null ? catalogAttr.getValue() : null;
String schema = schemaAttr != null ? schemaAttr.getValue() : null;
String name = tableAttr.getValue();
if (getTableName(catalog, schema, name).equals(getTableName(table))) {
res = true;
break;
}
}
}
}
}
return res;
}
use of org.dom4j.Attribute in project EssayJoke by qiyei2015.
the class Dom4jHelper method readeNode.
/**
* 递归调用,即可解析xml
* @param root
*/
private static void readeNode(Element root, String prefix) {
if (root == null) {
return;
}
LogManager.i(TAG, prefix + "name:" + root.getName());
// 获取所有的属性
List<Attribute> attrs = root.attributes();
if (attrs != null && attrs.size() > 0) {
for (Attribute attribute : attrs) {
LogManager.i(TAG, "attribute name:" + attribute.getName() + " value:" + attribute.getValue());
}
}
prefix += "\t";
List<Element> childNodes = root.elements();
for (Element element : childNodes) {
readeNode(element, prefix);
}
}
use of org.dom4j.Attribute in project OpenOLAT by OpenOLAT.
the class QTIImportProcessor method getMaterials.
@SuppressWarnings("unchecked")
protected List<String> getMaterials(Element el) {
List<String> materialPath = new ArrayList<String>();
// mattext
List<Element> mattextList = el.selectNodes(".//mattext");
for (Element mat : mattextList) {
Attribute texttypeAttr = mat.attribute("texttype");
if (texttypeAttr != null) {
String texttype = texttypeAttr.getValue();
if ("text/html".equals(texttype)) {
String content = mat.getStringValue();
findMaterialInMatText(content, materialPath);
}
}
}
// matimage uri
List<Element> matList = new ArrayList<Element>();
matList.addAll(el.selectNodes(".//matimage"));
matList.addAll(el.selectNodes(".//mataudio"));
matList.addAll(el.selectNodes(".//matvideo"));
for (Element mat : matList) {
Attribute uriAttr = mat.attribute("uri");
String uri = uriAttr.getValue();
materialPath.add(uri);
}
return materialPath;
}
use of org.dom4j.Attribute in project OpenOLAT by OpenOLAT.
the class IQ12EditForm method update.
/**
* Update the module configuration from the qti file: read min/max/cut values
* @param res
*/
protected void update(OLATResource res) {
FileResourceManager frm = FileResourceManager.getInstance();
File unzippedRoot = frm.unzipFileResource(res);
// with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if no longer needed.
VFSContainer vfsUnzippedRoot = new LocalFolderImpl(unzippedRoot);
VFSItem vfsQTI = vfsUnzippedRoot.resolve("qti.xml");
if (vfsQTI == null) {
throw new AssertException("qti file did not exist even it should be guaranteed by repositor check-in ");
}
// ensures that InputStream is closed in every case.
Document doc = QTIHelper.getDocument((LocalFileImpl) vfsQTI);
if (doc == null) {
// error reading qti file (existence check was made before)
throw new AssertException("qti file could not be read " + ((LocalFileImpl) vfsQTI).getBasefile().getAbsolutePath());
}
// Extract min, max and cut value
Float minValue = null, maxValue = null, cutValue = null;
Element decvar = (Element) doc.selectSingleNode("questestinterop/assessment/outcomes_processing/outcomes/decvar");
if (decvar != null) {
Attribute minval = decvar.attribute("minvalue");
if (minval != null) {
String mv = minval.getValue();
try {
minValue = new Float(Float.parseFloat(mv));
} catch (NumberFormatException e1) {
// if not correct in qti file -> ignore
}
}
Attribute maxval = decvar.attribute("maxvalue");
if (maxval != null) {
String mv = maxval.getValue();
try {
maxValue = new Float(Float.parseFloat(mv));
} catch (NumberFormatException e1) {
// if not correct in qti file -> ignore
}
}
Attribute cutval = decvar.attribute("cutvalue");
if (cutval != null) {
String cv = cutval.getValue();
try {
cutValue = new Float(Float.parseFloat(cv));
} catch (NumberFormatException e1) {
// if not correct in qti file -> ignore
}
}
}
// Put values to module configuration
minScoreEl.setValue(minValue == null ? "" : AssessmentHelper.getRoundedScore(minValue));
minScoreEl.setVisible(minValue != null);
maxScoreEl.setValue(maxValue == null ? "" : AssessmentHelper.getRoundedScore(maxValue));
maxScoreEl.setVisible(maxValue != null);
cutValueEl.setValue(cutValue == null ? "" : AssessmentHelper.getRoundedScore(cutValue));
cutValueEl.setVisible(cutValue != null);
}
use of org.dom4j.Attribute in project OpenOLAT by OpenOLAT.
the class ItemParser method parse.
/**
* @see org.olat.ims.qti.editor.beecom.parser.IParser#parse(org.dom4j.Element)
*/
public Object parse(Element element) {
// assert element.getName().equalsIgnoreCase("item");
Item item = new Item();
Attribute tmp = element.attribute("ident");
if (tmp != null)
item.setIdent(tmp.getValue());
else
item.setIdent("" + CodeHelper.getRAMUniqueID());
tmp = element.attribute("title");
if (tmp != null)
item.setTitle(tmp.getValue());
tmp = element.attribute("label");
if (tmp != null)
item.setLabel(tmp.getValue());
tmp = element.attribute("maxattempts");
if (tmp != null) {
try {
item.setMaxattempts(Integer.parseInt(tmp.getValue()));
} catch (NumberFormatException nfe) {
item.setMaxattempts(0);
}
}
// if editor can't handle type of item, just keep raw XML
if (!(item.getIdent().startsWith(ITEM_PREFIX_SCQ) || item.getIdent().startsWith(ITEM_PREFIX_MCQ) || item.getIdent().startsWith(ITEM_PREFIX_FIB) || item.getIdent().startsWith(ITEM_PREFIX_ESSAY) || item.getIdent().startsWith(ITEM_PREFIX_KPRIM))) {
item.setRawXML(new QTIXMLWrapper(element));
return item;
}
// for render_fib that contains rows attribute and convert them to essay
if (item.getIdent().startsWith(ITEM_PREFIX_FIB) && element.selectNodes(".//render_fib[@rows]").size() > 0) {
item.setIdent(item.getIdent().replaceFirst("FIB", "ESSAY"));
}
// DURATION
Duration duration = (Duration) parserManager.parse(element.element("duration"));
item.setDuration(duration);
// CONTROLS
List itemcontrolsXML = element.elements("itemcontrol");
List itemcontrols = new ArrayList();
for (Iterator i = itemcontrolsXML.iterator(); i.hasNext(); ) {
itemcontrols.add(parserManager.parse((Element) i.next()));
}
if (itemcontrols.size() == 0) {
itemcontrols.add(new Control());
}
item.setItemcontrols(itemcontrols);
// OBJECTIVES
Element mattext = (Element) element.selectSingleNode("./objectives/material/mattext");
if (mattext != null)
item.setObjectives(mattext.getTextTrim());
// QUESTIONS
if (item.getIdent().startsWith(ITEM_PREFIX_SCQ))
item.setQuestion(ChoiceQuestion.getInstance(element));
else if (item.getIdent().startsWith(ITEM_PREFIX_MCQ))
item.setQuestion(ChoiceQuestion.getInstance(element));
else if (item.getIdent().startsWith(ITEM_PREFIX_FIB))
item.setQuestion(FIBQuestion.getInstance(element));
else if (item.getIdent().startsWith(ITEM_PREFIX_ESSAY))
item.setQuestion(EssayQuestion.getInstance(element));
else if (item.getIdent().startsWith(ITEM_PREFIX_KPRIM))
item.setQuestion(ChoiceQuestion.getInstance(element));
// FEEDBACKS
List feedbacksXML = element.elements("itemfeedback");
List feedbacks = new ArrayList();
item.setItemfeedbacks(feedbacks);
Question question = item.getQuestion();
for (Iterator i = feedbacksXML.iterator(); i.hasNext(); ) {
Element el_feedback = (Element) i.next();
if (el_feedback.element("solution") != null) {
// fetch solution
Element el_solution = el_feedback.element("solution");
question.setSolutionText(getMaterialAsString(el_solution));
} else if (el_feedback.element("hint") != null) {
// fetch hint
Element el_hint = el_feedback.element("hint");
question.setHintText(getMaterialAsString(el_hint));
} else {
QTIObject tmpObj = (QTIObject) parserManager.parse(el_feedback);
if (tmpObj != null)
feedbacks.add(tmpObj);
}
}
return item;
}
Aggregations