List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:cz.fi.muni.xkremser.editor.server.newObject.MonographBuilder.java
License:Open Source License
private void updateDcDoc(Document dcDoc, String pid, String signature, String sysno, DigitalObjectModel model) { Element dcRootEl = dcDoc.getRootElement(); Attribute schemaLoc = dcRootEl.attribute("schemaLocation"); dcRootEl.remove(schemaLoc);/*from w ww. j a v a 2 s . co m*/ Namespace xsi = DocumentHelper.createNamespace("xsi2", FedoraNamespaces.SCHEMA_NAMESPACE_URI); dcRootEl.add(xsi); dcRootEl.addAttribute(new QName("schemaLocation", xsi), "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"); XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:identifier"); List<? extends Node> nodes = typeXpath.selectNodes(dcDoc); for (Node node : nodes) { node.detach(); } Element idUuid = dcRootEl.addElement("dc:identifier"); idUuid.addText(pid); for (Node node : nodes) { if (node.getText() != null && !"".equals(node.getText().trim()) && !node.getText().contains(Constants.FEDORA_UUID_PREFIX)) { Element temp = dcRootEl.addElement("dc:identifier"); temp.addText(node.getText()); } } if (signature != null) { Element idSignature = dcRootEl.addElement("dc:identifier"); idSignature.addText("signature:" + signature); } if (sysno != null) { Element idSysno = dcRootEl.addElement("dc:identifier"); idSysno.addText("sysno:" + sysno); } removeDcTypeElements(dcDoc); Element typeEl = dcRootEl.addElement("dc:type"); typeEl.addText("model:" + model.toString()); Element rightsEl = dcRootEl.addElement("dc:rights"); rightsEl.addText("policy:" + Policy.PUBLIC.toString().toLowerCase()); updateDcLanguages(dcDoc); }
From source file:cz.fi.muni.xkremser.editor.server.newObject.PeriodicalBuilder.java
License:Open Source License
private void updateDcDoc(Document dcDoc, String pid, String signature, String sysno, DigitalObjectModel model) { Element dcRootEl = dcDoc.getRootElement(); Attribute schemaLoc = dcRootEl.attribute("schemaLocation"); dcRootEl.remove(schemaLoc);//from w w w .jav a 2 s . c om Namespace xsi = DocumentHelper.createNamespace("xsi2", FedoraNamespaces.SCHEMA_NAMESPACE_URI); dcRootEl.add(xsi); dcRootEl.addAttribute(new QName("schemaLocation", xsi), "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"); XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:identifier"); List<? extends Node> nodes = typeXpath.selectNodes(dcDoc); for (Node node : nodes) { node.detach(); } Element idUuid = dcRootEl.addElement("dc:identifier"); idUuid.addText(pid); for (Node node : nodes) { if (node.getText() != null && !"".equals(node.getText().trim()) && !node.getText().contains(Constants.FEDORA_UUID_PREFIX)) { Element temp = dcRootEl.addElement("dc:identifier"); temp.addText(node.getText()); } } if (signature != null) { Element idSignature = dcRootEl.addElement("dc:identifier"); idSignature.addText("signature:" + signature); } if (sysno != null) { Element idSysno = dcRootEl.addElement("dc:identifier"); idSysno.addText("sysno:" + sysno); } removeDcTypeElements(dcDoc); Element typeEl = dcRootEl.addElement("dc:type"); typeEl.addText("model:" + model.getValue()); Element rightsEl = dcRootEl.addElement("dc:rights"); rightsEl.addText("policy:" + Policy.PUBLIC.toString().toLowerCase()); updateDcLanguages(dcDoc); }
From source file:cz.muni.stanse.automatonchecker.XMLAutomatonDefinition.java
License:GNU General Public License
XMLAutomatonDefinition(final Element XMLdefinition) throws XMLAutomatonSyntaxErrorException { Element desc = (Element) XMLdefinition.selectSingleNode("description"); automatonName = desc.attribute("name").getValue(); automatonDesc = desc.attribute("desc").getValue(); Element start = (Element) XMLdefinition.selectSingleNode("start"); startSymbol = start.attribute("state").getValue(); XMLpatterns = buildXMLPatterns(XMLdefinition); XMLtransitionRules = buildXMLTransitionRules(XMLdefinition); XMLerrorRules = buildXMLErrorRules(XMLdefinition); patternTransitionRulesDictionary = buildPatternTransitionRulesDictionary(XMLpatterns, XMLtransitionRules); patternErrorRulesDictionary = buildPatternErrorRulesDictionary(XMLpatterns, XMLerrorRules); }
From source file:cz.muni.stanse.automatonchecker.XMLErrorRule.java
License:GNU General Public License
XMLErrorRule(final org.dom4j.Element XMLelement) throws XMLAutomatonSyntaxErrorException { description = XMLelement.attribute("desc").getValue().replaceAll("[ \t]+", " "); errorLevel = Integer.decode(XMLelement.attributeValue("level")); entryMessage = XMLelement.attributeValue("entry").replaceAll("[ \t]+", " "); beginMessage = XMLelement.attributeValue("begin").replaceAll("[ \t]+", " "); propagMessage = XMLelement.attributeValue("propag").replaceAll("[ \t]+", " "); endMessage = XMLelement.attributeValue("end").replaceAll("[ \t]+", " "); final String byString = XMLelement.attributeValue("by"); final Triple<String, Vector<String>, Character> bySymbol = (byString.isEmpty()) ? new Triple<String, Vector<String>, Character>("", new Vector<String>(), '+') : XMLRuleStringParser.parseOneSymbolRuleString(byString); if (!byString.isEmpty()) checkVars(1, -1, bySymbol);/*from www .j a v a 2 s . co m*/ final String locationVarName = (byString.isEmpty()) ? "*" : bySymbol.getSecond().firstElement(); patternName = bySymbol.getFirst(); final LinkedList<Triple<String, Vector<String>, Character>> fromList = XMLRuleStringParser .parseRuleString(XMLelement.attributeValue("from")); checkList(fromList); checkVars(1, -1, fromList); excludedMatchFlags = buildMatchFlags(fromList, '-', locationVarName); includedMatchFlags = buildMatchFlags(fromList, '+', locationVarName); }
From source file:cz.muni.stanse.automatonchecker.XMLTransitionRule.java
License:GNU General Public License
XMLTransitionRule(final org.dom4j.Element XMLtransitionElement) throws XMLAutomatonSyntaxErrorException { final Triple<String, Vector<String>, Character> fromSymbol = XMLRuleStringParser .parseOneSymbolRuleString(XMLtransitionElement.attribute("from").getValue()); checkMode(fromSymbol.getThird());//ww w. j a v a 2s .c o m checkVars(1, -1, fromSymbol.getSecond().size()); inSymbol = fromSymbol.getFirst(); final String toText = XMLtransitionElement.attribute("to").getValue(); final Triple<String, Vector<String>, Character> toSymbol = (toText.isEmpty()) ? new Triple<String, Vector<String>, Character>(null, new Vector<String>(), '+') : XMLRuleStringParser.parseOneSymbolRuleString(toText); checkMode(toSymbol.getThird()); if (!toText.isEmpty()) checkVars(1, -1, toSymbol.getSecond().size()); outSymbol = toSymbol.getFirst(); final Triple<String, Vector<String>, Character> bySymbol = XMLRuleStringParser .parseOneSymbolRuleString(XMLtransitionElement.attribute("by").getValue()); assert (bySymbol.getSecond().size() < 2); checkMode(bySymbol.getThird()); checkVars(1, 1, bySymbol.getSecond().size()); matchFlags = buildMatchFlags(fromSymbol.getSecond(), bySymbol.getSecond().firstElement()); matchOutIndices = buildMatchOutIndices(fromSymbol.getSecond(), toSymbol.getSecond(), bySymbol.getSecond().firstElement()); patternName = bySymbol.getFirst(); }
From source file:cz.muni.stanse.utils.xmlpatterns.XMLPattern.java
License:GNU General Public License
private Pair<Boolean, XMLPatternVariablesAssignment> matchesNode(final CFGNode node, Element xmlPivot, AliasResolver aliasResolver) {//from w ww . j a v a 2 s . c om if (node.getNodeType() == null || !node.getNodeType().equals(xmlPivot.attributeValue("type"))) return Pair.make(false, null); XMLPatternVariablesAssignment varsAssignment = new XMLPatternVariablesAssignment(); Iterator<Element> i = xmlPivot.elementIterator(); Iterator<CFGNode.Operand> j = node.getOperands().iterator(); while (i.hasNext() && j.hasNext()) { Element elem = i.next(); if (elem.getName().equals("any")) return Pair.make(true, varsAssignment); CFGNode.Operand op = j.next(); if (elem.getName().equals("ignore")) continue; if (elem.getName().equals("var")) { if (elem.attribute("target") != null) { if (op.type == CFGNode.OperandType.varptr) { varsAssignment.put(elem.attribute("target").getValue(), new CFGNode.Operand(CFGNode.OperandType.varval, op.id)); } else { return Pair.make(false, null); } } else { varsAssignment.put(elem.attribute("name").getValue(), op); } continue; } if (op.type == CFGNode.OperandType.nodeval) { if (!elem.getName().equals("node")) return Pair.make(false, null); Pair<Boolean, XMLPatternVariablesAssignment> nested = matchesNode((CFGNode) op.id, elem, aliasResolver); if (!nested.getFirst()) return nested; varsAssignment.merge(nested.getSecond()); } else { if (!op.type.toString().equals(elem.getName())) return Pair.make(false, null); if (!aliasResolver.match(elem.getText(), op.id.toString())) return Pair.make(false, null); } } if (i.hasNext() || j.hasNext()) return Pair.make(false, null); return Pair.make(true, varsAssignment); }
From source file:cz.muni.stanse.utils.xmlpatterns.XMLPattern.java
License:GNU General Public License
private static boolean matchingElements(final Element XMLpivot, final Element XMLelement, final XMLPatternVariablesAssignment varsAssignment) { if (XMLpivot.getName().equals("nested")) { final String elementName = XMLelement.getName(); for (final Iterator<Attribute> j = XMLpivot.attributeIterator(); j.hasNext();) if (elementName.equals(j.next().getValue())) return false; return onNested(XMLpivot, XMLelement, varsAssignment); }/*from ww w . j ava 2 s. com*/ if (XMLpivot.getName().equals("ignore")) return true; if (XMLpivot.getName().equals("var")) { if (!satisfyVarConstraints(XMLelement.getName(), XMLpivot.attribute("match"), XMLpivot.attribute("except"))) return false; varsAssignment.put(XMLpivot.attribute("name").getValue(), XMLelement); return true; } if (!XMLpivot.getName().equals(XMLelement.getName())) return false; if (!matchingAttributes(XMLpivot.attributes(), XMLelement)) return false; if (XMLpivot.isTextOnly() != XMLelement.isTextOnly()) return false; if (XMLpivot.isTextOnly() && !XMLpivot.getText().equals(XMLelement.getText())) return false; final Iterator<Element> i = XMLpivot.elementIterator(); final Iterator<Element> j = XMLelement.elementIterator(); while (i.hasNext() && j.hasNext()) { final Element pivotNext = i.next(); if (pivotNext.getName().equals("any")) return true; if (!matchingElements(pivotNext, j.next(), varsAssignment)) return false; } if (i.hasNext() || j.hasNext()) return false; return true; }
From source file:cz.mzk.editor.server.metadataDownloader.OAIPMHClientImpl.java
License:Open Source License
/** * @param document//from w ww .j a va 2s .c om */ private boolean checkAndReplace(Document doc, boolean onlyReplace) { boolean available = true; Element hrefNode = (Element) doc .selectSingleNode("/xsl:stylesheet/*[ends-with(@href,\'MARC21slimUtils.xsl\')]"); if (hrefNode != null) { Attribute hrefAttr = hrefNode.attribute("href"); if (onlyReplace || !(available = ServerUtils.checkAvailability(hrefAttr.getStringValue(), null, null))) { hrefAttr.setText(config.getEditorHome() + MARC_UTILS); } } return available; }
From source file:cz.mzk.editor.server.newObject.MonographBuilder.java
License:Open Source License
@SuppressWarnings("unchecked") private void updateDcDoc(Document dcDoc, String pid, String signature, String sysno, DigitalObjectModel model) { Element dcRootEl = dcDoc.getRootElement(); Attribute schemaLoc = dcRootEl.attribute("schemaLocation"); dcRootEl.remove(schemaLoc);//from w w w.ja v a2s.c om Namespace xsi = DocumentHelper.createNamespace("xsi2", FedoraNamespaces.SCHEMA_NAMESPACE_URI); dcRootEl.add(xsi); dcRootEl.addAttribute(new QName("schemaLocation", xsi), "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"); XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:identifier"); List<? extends Node> nodes = typeXpath.selectNodes(dcDoc); for (Node node : nodes) { node.detach(); } Element idUuid = dcRootEl.addElement("dc:identifier"); idUuid.addText(pid); for (Node node : nodes) { if (node.getText() != null && !"".equals(node.getText().trim()) && !node.getText().contains(Constants.FEDORA_UUID_PREFIX)) { Element temp = dcRootEl.addElement("dc:identifier"); temp.addText(node.getText()); } } if (signature != null) { Element idSignature = dcRootEl.addElement("dc:identifier"); idSignature.addText("signature:" + signature); } if (sysno != null) { Element idSysno = dcRootEl.addElement("dc:identifier"); idSysno.addText("sysno:" + sysno); } removeDcTypeElements(dcDoc); Element typeEl = dcRootEl.addElement("dc:type"); typeEl.addText("model:" + model.getValue()); Element rightsEl = dcRootEl.addElement("dc:rights"); rightsEl.addText("policy:" + getPolicy().toString().toLowerCase()); updateDcLanguages(dcDoc); }
From source file:darks.orm.core.config.sqlmap.DMLConfigReader.java
License:Apache License
/** * Read and parse aspect XMLs file/*from w w w . jav a2 s.co m*/ * * @param element Aspect tags * @return Aspect data */ private AspectData parseAspectXml(Element element) { Element aspectEl = element.element("aspect"); if (aspectEl == null) return null; AspectData aspectData = new AspectData(); boolean isNext = false; Element jythonEl = aspectEl.element("jython"); if (jythonEl != null) { aspectData.setAspectType(AspectType.JYTHON); Attribute attr = jythonEl.attribute("className"); if (attr == null) return null; aspectData.setClassName(attr.getValue().trim()); String text = jythonEl.getText(); if (text == null || "".equals(text.trim())) { String before = jythonEl.elementText("before"); String after = jythonEl.elementText("after"); if (before == null || "".equals(before.trim())) { if (after == null || "".equals(after.trim())) return null; } text = PythonBuilder.buildBody(aspectData.getClassName(), before, after); } aspectData.setContent(text); isNext = true; } Element pyfileEl = aspectEl.element("pyfile"); if (pyfileEl != null && isNext == false) { aspectData.setAspectType(AspectType.PYFILE); Attribute attr = pyfileEl.attribute("className"); if (attr == null) return null; aspectData.setClassName(attr.getValue().trim()); aspectData.setContent(pyfileEl.getTextTrim()); isNext = true; } Element javaClassEl = aspectEl.element("javaClass"); if (javaClassEl != null && isNext == false) { aspectData.setAspectType(AspectType.JAVACLASS); aspectData.setClassName(javaClassEl.getTextTrim()); isNext = true; } Element jsEl = aspectEl.element("javascript"); if (jsEl != null && isNext == false) { aspectData.setAspectType(AspectType.JAVASCRIPT); aspectData.setContent(jsEl.getTextTrim()); isNext = true; } Element jsfileEl = aspectEl.element("jsfile"); if (jsfileEl != null && isNext == false) { aspectData.setAspectType(AspectType.JSFILE); aspectData.setContent(jsfileEl.getTextTrim()); isNext = true; } if (isNext) { return aspectData; } return null; }