use of org.dom4j.Attribute in project hibernate-orm by hibernate.
the class MetadataTools method prefixNamesInPropertyElement.
@SuppressWarnings({ "unchecked" })
public static void prefixNamesInPropertyElement(Element element, String prefix, ColumnNameIterator columnNameIterator, boolean changeToKey, boolean insertable) {
final Iterator<Element> properties = element.elementIterator();
while (properties.hasNext()) {
final Element property = properties.next();
if ("property".equals(property.getName()) || "many-to-one".equals(property.getName())) {
final Attribute nameAttr = property.attribute("name");
if (nameAttr != null) {
nameAttr.setText(prefix + nameAttr.getText());
}
changeNamesInColumnElement(property, columnNameIterator);
if (changeToKey) {
property.setName("key-" + property.getName());
// making references to the main schema.
if (property.getName().equals("key-many-to-one")) {
final Attribute foreignKey = property.attribute("foreign-key");
if (foreignKey == null) {
property.addAttribute("foreign-key", "none");
} else {
foreignKey.setValue("none");
}
}
}
if ("property".equals(property.getName())) {
final Attribute insert = property.attribute("insert");
insert.setText(Boolean.toString(insertable));
}
}
}
}
use of org.dom4j.Attribute in project xresloader by xresloader.
the class DataDstXml method writeData.
private void writeData(Element sb, Object data, String wrapper_name) {
// null
if (null == data) {
return;
}
// 枚举值已被转为Java Long,会在这里执行
if (data instanceof Number) {
sb.addText(data.toString());
return;
}
// 布尔
if (data instanceof Boolean) {
sb.addText(((Boolean) data) ? "true" : "false");
return;
}
// 字符串&二进制
if (data instanceof String) {
sb.addText(data.toString());
return;
}
// 列表
if (data instanceof List) {
List<Object> ls = (List<Object>) data;
int index = 0;
for (Object obj : ls) {
Element list_ele = DocumentHelper.createElement(wrapper_name);
Attribute index_attr = DocumentHelper.createAttribute(list_ele, "for", String.valueOf(index));
list_ele.add(index_attr);
writeData(list_ele, obj, wrapper_name);
sb.add(list_ele);
++index;
}
return;
}
// Hashmap
if (data instanceof Map) {
Map<String, Object> mp = (Map<String, Object>) data;
for (Map.Entry<String, Object> item : mp.entrySet()) {
// 数据会多一层,这里去除
if (item.getValue() instanceof List) {
writeData(sb, item.getValue(), item.getKey());
} else {
Element xml_item = DocumentHelper.createElement(item.getKey());
writeData(xml_item, item.getValue(), item.getKey());
sb.add(xml_item);
}
}
return;
}
ProgramOptions.getLoger().error("%s not support.", data.toString());
}
use of org.dom4j.Attribute in project openolat by klemens.
the class TextMarkerManagerImpl method loadTextMarkerList.
/**
* @see org.olat.core.gui.control.generic.textmarker.TextMarkerManager#loadTextMarkerList(org.olat.core.util.vfs.VFSLeaf)
*/
public List<TextMarker> loadTextMarkerList(VFSLeaf textMarkerFile) {
if (textMarkerFile == null) {
// filename not defined at all
return new ArrayList<TextMarker>();
}
XMLParser parser = new XMLParser();
InputStream stream = textMarkerFile.getInputStream();
if (stream == null) {
// e.g. file was removed
return new ArrayList<TextMarker>();
}
Document doc = parser.parse(stream, false);
Element root = doc.getRootElement();
if (root == null) {
// file was empty;
return new ArrayList<TextMarker>();
}
// Do version check. Not needed now, for future lazy migration code...
Attribute versionAttribute = root.attribute(XML_VERSION_ATTRIBUTE);
int version = (versionAttribute == null ? 1 : Integer.parseInt(versionAttribute.getStringValue()));
if (version != VERSION) {
// complain about version conflict or solve it
throw new OLATRuntimeException("Could not load glossary entries due to version conflict. Loaded version was::" + version, null);
}
// parse text marker objects and put them into a list
List markersElements = root.elements("textMarker");
List<TextMarker> markers = new ArrayList<TextMarker>();
Iterator iter = markersElements.iterator();
while (iter.hasNext()) {
Element textMarkerElement = (Element) iter.next();
TextMarker textMarker = new TextMarker(textMarkerElement);
markers.add(textMarker);
}
try {
stream.close();
} catch (IOException e) {
throw new OLATRuntimeException(this.getClass(), "Error while closing text marker file stream", e);
}
return markers;
}
use of org.dom4j.Attribute in project openolat by klemens.
the class ScormCPFileResource method validateImsManifest.
public static boolean validateImsManifest(Document doc) {
try {
// do not throw exception already here, as it might be only a generic zip file
if (doc == null)
return false;
String adluri = null;
String seqencingUri = null;
String simpleSeqencingUri = null;
// get all organization elements. need to set namespace
Element rootElement = doc.getRootElement();
String nsuri = rootElement.getNamespace().getURI();
// look for the adl cp namespace that differs a scorm package from a normal cp package
Namespace nsADL = rootElement.getNamespaceForPrefix("adlcp");
if (nsADL != null)
adluri = nsADL.getURI();
Namespace nsADLSeq = rootElement.getNamespaceForPrefix("adlseq");
if (nsADLSeq != null)
seqencingUri = nsADLSeq.getURI();
Namespace nsADLSS = rootElement.getNamespaceForPrefix("imsss");
if (nsADLSS != null)
simpleSeqencingUri = nsADLSS.getURI();
// we can only support scorm 1.2 so far.
if (adluri != null && !((adluri.indexOf("adlcp_rootv1p2") != -1) || (adluri.indexOf("adlcp_rootv1p3") != -1))) {
// we dont have have scorm 1.2 or 1.3 namespace so it can't be a scorm package
return false;
}
Map<String, Object> nsuris = new HashMap<>(5);
nsuris.put("ns", nsuri);
// we might have a scorm 2004 which we do not yet support
if (seqencingUri != null)
nsuris.put("adlseq", seqencingUri);
if (simpleSeqencingUri != null)
nsuris.put("imsss", simpleSeqencingUri);
// Check for organization element. Must provide at least one... title gets extracted from either
// the (optional) <title> element or the mandatory identifier attribute.
// This makes sure, at least a root node gets created in CPManifestTreeModel.
XPath meta = rootElement.createXPath("//ns:organization");
meta.setNamespaceURIs(nsuris);
// TODO: accept several organizations?
Element orgaEl = (Element) meta.selectSingleNode(rootElement);
if (orgaEl == null) {
return false;
}
// Check for at least one <item> element referencing a <resource> of adlcp:scormtype="sco" or "asset",
// which will serve as an entry point.
XPath resourcesXPath = rootElement.createXPath("//ns:resources");
resourcesXPath.setNamespaceURIs(nsuris);
Element elResources = (Element) resourcesXPath.selectSingleNode(rootElement);
if (elResources == null) {
return false;
}
XPath itemsXPath = rootElement.createXPath("//ns:item");
itemsXPath.setNamespaceURIs(nsuris);
List items = itemsXPath.selectNodes(rootElement);
if (items.size() == 0) {
// no <item> element.
return false;
}
// check for scorm 2004 simple sequencing stuff which we do not yet support
if (seqencingUri != null) {
XPath seqencingXPath = rootElement.createXPath("//ns:imsss");
List sequences = seqencingXPath.selectNodes(rootElement);
if (sequences.size() > 0) {
// seqencing elements found -> scorm 2004
return false;
}
}
Set<String> set = new HashSet<String>();
for (Iterator iter = items.iterator(); iter.hasNext(); ) {
Element item = (Element) iter.next();
String identifier = item.attributeValue("identifier");
// check if identifiers are unique, reject if not so
if (!set.add(identifier)) {
// TODO:create special error message for non unique ids
return false;
}
}
for (Iterator iter = items.iterator(); iter.hasNext(); ) {
Element item = (Element) iter.next();
String identifierref = item.attributeValue("identifierref");
if (identifierref == null)
continue;
XPath resourceXPath = rootElement.createXPath("//ns:resource[@identifier='" + identifierref + "']");
resourceXPath.setNamespaceURIs(nsuris);
Element elResource = (Element) resourceXPath.selectSingleNode(elResources);
if (elResource == null) {
return false;
}
// check for scorm attribute
Attribute scormAttr = elResource.attribute("scormtype");
// some packages have attribute written like "scormType"
Attribute scormAttrUpper = elResource.attribute("scormType");
if (scormAttr == null && scormAttrUpper == null) {
return false;
}
String attr = "";
if (scormAttr != null)
attr = scormAttr.getStringValue();
if (scormAttrUpper != null)
attr = scormAttrUpper.getStringValue();
if (attr == null) {
return false;
}
if (elResource.attributeValue("href") != null && (attr.equalsIgnoreCase("sco") || attr.equalsIgnoreCase("asset"))) {
// success.
return true;
}
}
return false;
} catch (Exception e) {
log.warn("Not a valid SCORM package", e);
return false;
}
}
use of org.dom4j.Attribute in project openolat by klemens.
the class AssessmentParser method parse.
/**
* @see org.olat.ims.qti.editor.beecom.IParser#parse(org.dom4j.Element)
*/
public Object parse(Element element) {
// assert element.getName().equalsIgnoreCase("assessment");
Assessment assessment = new Assessment();
// attributes
Attribute attr = element.attribute("ident");
if (attr != null)
assessment.setIdent(attr.getValue());
attr = element.attribute("title");
if (attr != null)
assessment.setTitle(attr.getValue());
// elements
// DURATION
QTIObject duration = (QTIObject) parserManager.parse(element.element("duration"));
assessment.setDuration(duration);
// ASSESSMENTCONTROL
List assessmentcontrolsXML = element.elements("assessmentcontrol");
List assessmentcontrols = new ArrayList();
for (Iterator i = assessmentcontrolsXML.iterator(); i.hasNext(); ) {
assessmentcontrols.add(parserManager.parse((Element) i.next()));
assessment.setInheritControls(true);
}
if (assessmentcontrols.size() == 0) {
assessmentcontrols.add(new Control());
assessment.setInheritControls(false);
}
assessment.setAssessmentcontrols(assessmentcontrols);
// OUTCOMES PROCESSING
OutcomesProcessing outcomesProcessing = (OutcomesProcessing) parserManager.parse(element.element("outcomes_processing"));
if (outcomesProcessing != null)
assessment.setOutcomes_processing(outcomesProcessing);
// SELECTION ORDERING
SelectionOrdering selectionOrdering = (SelectionOrdering) parserManager.parse(element.element("selection_ordering"));
if (selectionOrdering != null) {
assessment.setSelection_ordering(selectionOrdering);
} else {
assessment.setSelection_ordering(new SelectionOrdering());
}
// SECTIONS
List sectionsXML = element.elements("section");
List sections = new ArrayList();
for (Iterator i = sectionsXML.iterator(); i.hasNext(); ) {
sections.add(parserManager.parse((Element) i.next()));
}
assessment.setSections(sections);
// ITEMS
List itemsXML = element.elements("item");
List items = new ArrayList();
for (Iterator i = itemsXML.iterator(); i.hasNext(); ) {
items.add(parserManager.parse((Element) i.next()));
}
assessment.setItems(items);
// OBJECTIVES
Element mattext = (Element) element.selectSingleNode("./objectives/material/mattext");
if (mattext != null)
assessment.setObjectives(mattext.getTextTrim());
// METADATA
Metadata metadata = (Metadata) parserManager.parse(element.element("qtimetadata"));
if (metadata != null)
assessment.setMetadata(metadata);
return assessment;
}
Aggregations