List of usage examples for org.dom4j Element elementIterator
Iterator<Element> elementIterator();
From source file:cz.muni.stanse.utils.xmlpatterns.XMLAlgo.java
License:GNU General Public License
/** * Check if two elements are (recursively) equal * * TODO: remove and use equality tester from dom4j pkg * * @param e1 first element/*from ww w.j av a 2 s . co m*/ * @param e2 second element */ public static boolean equalElements(final Element e1, final Element e2) { if (!e1.getName().equals(e2.getName())) return false; if (!e1.getText().equals(e2.getText())) return false; for (final Object attrObj : e1.attributes()) { final Attribute attr = (Attribute) attrObj; if (!attr.getName().equals("bl") && !attr.getName().equals("bc") && !attr.getValue().equals(e2.attributeValue(attr.getName()))) return false; } final Iterator i = e1.elementIterator(); final Iterator j = e2.elementIterator(); while (i.hasNext() && j.hasNext()) if (!equalElements((Element) i.next(), (Element) j.next())) return false; if (i.hasNext() || j.hasNext()) return false; return true; }
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 ww w . ja v a 2 s . co m*/ 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 a v a 2s. c o m 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.muni.stanse.utils.xmlpatterns.XMLPattern.java
License:GNU General Public License
private static boolean onNested(final Element XMLpivot, final Element XMLelement, final XMLPatternVariablesAssignment varsAssignment) { if (matchingElements((Element) XMLpivot.elementIterator().next(), XMLelement, varsAssignment)) return true; for (final Iterator<Element> j = XMLelement.elementIterator(); j.hasNext();) if (matchingElements(XMLpivot, j.next(), varsAssignment)) return true; return false; }
From source file:darks.orm.core.config.CacheConfiguration.java
License:Apache License
public void readCacheConfig(Element element) { if (element == null) return;/*from www . j a v a2 s . c om*/ for (Iterator<Element> it = element.elementIterator(); it.hasNext();) { try { Element el = it.next(); String name = el.getName().trim(); if ("AppCache".equalsIgnoreCase(name)) { readAppCacheConfig(el); } else if ("ThreadCache".equalsIgnoreCase(name)) { readThreadCacheConfig(el); } else if ("EHCache".equalsIgnoreCase(name)) { readEHCacheConfig(el); } } catch (Exception e) { } } }
From source file:darks.orm.core.config.sqlmap.DDLConfigReader.java
License:Apache License
/** * DDL/*from www. java2 s . com*/ * * @param element */ public void reader(Element element) { // DDL for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { try { Attribute at = it.next(); String name = at.getName().trim(); String value = at.getValue().trim(); if ("schema".equalsIgnoreCase(name)) { sqlMapConfig.setSchema(value); } else if ("catalog".equalsIgnoreCase(name)) { sqlMapConfig.setCatalog(value); } } catch (Exception e) { e.printStackTrace(); } } // DDL for (Iterator<Element> it = element.elementIterator(); it.hasNext();) { try { Element el = it.next(); String name = el.getName().trim(); if ("create".equalsIgnoreCase(name)) { readCreate(el); } else if ("alter".equalsIgnoreCase(name)) { readAlter(el); } } catch (Exception e) { e.printStackTrace(); } } }
From source file:darks.orm.core.config.sqlmap.DMLConfigReader.java
License:Apache License
/** * Read sqlmap DML xml element//ww w . j a va 2 s . co m * * @param element Xml element */ public void reader(Element element) { String namesp = element.attributeValue("namespace"); if (namesp == null) namesp = ""; try { for (Iterator<Element> it = element.elementIterator(); it.hasNext();) { Element el = it.next(); String name = el.getName().trim(); if ("Query".equalsIgnoreCase(name)) { readQuery(el, namesp); } else if ("Update".equalsIgnoreCase(name)) { readUpdate(el, namesp); } else if ("tag".equalsIgnoreCase(name)) { readTag(el, namesp); } } } catch (Exception e) { throw new ConfigException(e.getMessage(), e); } }
From source file:darks.orm.core.config.sqlmap.SqlMapConfiguration.java
License:Apache License
/** * Load sqlmap config file by path// w w w . j a v a2s . co m * * @param sqlMapCfg sqlmap config file path * @throws DocumentException */ public void loadSqlMap(String sqlMapCfg) throws DocumentException { if (!sqlMapCfg.startsWith("/")) sqlMapCfg = "/" + sqlMapCfg; InputStream cfgIns = getClass().getResourceAsStream(sqlMapCfg); if (cfgIns == null) { log.error("[SQLMAP]'" + sqlMapCfg + "' configuration file does not exists."); return; } else { log.debug("[SQLMAP]Load '" + sqlMapCfg + "' sqlmap configuration file"); } Document doc = XmlHelper.getXMLDocument(DTD_PUBLIC_ID, CONFIG_DTD_PATH, cfgIns); if (doc == null) { throw new ConfigException("Fail to parse sqlmap config file. Cause invalid config file."); } Element root = doc.getRootElement(); for (Iterator<Element> it = root.elementIterator(); it.hasNext();) { try { Element el = it.next(); String name = el.getName().trim(); if ("DDL".equalsIgnoreCase(name)) { ddlReader.reader(el); } else if ("DML".equalsIgnoreCase(name)) { dmlReader.reader(el); } } catch (Exception e) { e.printStackTrace(); } } }
From source file:de.jwic.base.JWicRuntime.java
License:Apache License
/** * Read the setup document.//from w ww . j a v a 2 s .c o m * @param document */ private void readDocument(Document document) { Element root = document.getRootElement(); for (Iterator<?> it = root.elementIterator(); it.hasNext();) { Element node = (Element) it.next(); String nodeName = node.getName(); // setup a velocity-engine if (nodeName.equals("velocity-engine")) { String veId = node.attribute("id").getValue(); Properties prop = null; for (Iterator<?> pi = node.elementIterator(); pi.hasNext();) { Element node2 = (Element) pi.next(); if (node2.getName().equals("properties")) { prop = XMLTool.getProperties(node2); } } // replace ${rootPath} with real path ConfigurationTool.insertRootPath(prop); VelocityEngine engine = new VelocityEngine(); try { engine.init(prop); } catch (Exception e) { String msg = "Can not instanciate velocity engine '" + veId + "'"; log.error(msg, e); throw new RuntimeException(msg + e, e); } velocityEngines.put(veId, engine); } else if (nodeName.equals("session-swap-time")) { sessionStoreTime = Integer.parseInt(node.getText()); } else if (nodeName.equals("session-storage-path")) { setSavePath(ConfigurationTool.insertRootPath(node.getText())); } else if (nodeName.equals("renderer")) { String id = node.attribute("id").getValue(); String type = node.attribute("type").getValue(); String classname = node.attribute("classname").getValue(); IControlRenderer renderer; try { renderer = (IControlRenderer) Class.forName(classname).newInstance(); } catch (Exception e) { String msg = "Can not instanciate renderer '" + id + "'"; log.error(msg, e); throw new RuntimeException(msg + e, e); } if (type.equals("velocity")) { Element nEngine = node.element("engine"); if (nEngine != null) { String engineId = nEngine.getText(); if (renderer instanceof BaseVelocityRenderer) { BaseVelocityRenderer vr = (BaseVelocityRenderer) renderer; VelocityEngine engine = velocityEngines.get(engineId); if (engine == null) { throw new RuntimeException("Specified velocity engine not found: " + engineId); } vr.setVelocityEngine(engine); } else { throw new RuntimeException("renderer " + id + " is specified as type 'velocity' but is not instance of BaseVelocityRenderer"); } } } renderers.put(id, renderer); } } }
From source file:de.jwic.base.XmlApplicationSetup.java
License:Apache License
/** * Read the document content./*from w w w . ja v a2 s. c o m*/ * @param document */ private void readDocument(Document document) { Element root = document.getRootElement(); for (Iterator<?> it = root.elementIterator(); it.hasNext();) { Element node = (Element) it.next(); String nodeName = node.getName(); if (nodeName.equals(NODE_NAME)) { name = node.getText(); } else if (nodeName.equals(NODE_CLASS)) { appClassName = node.getText(); } else if (nodeName.equals(NODE_ROOTCONTROL)) { rootControlName = node.attribute(ATTR_NAME).getValue(); rootControlClass = node.attribute(ATTR_CLASSNAME).getValue(); } else if (nodeName.equals(NODE_SERIALIZABLE)) { String s = node.getText(); serializable = "true".equals(s) | "1".equals(s) | "on".equals(s); } else if (nodeName.equals(NODE_SINGLESESSION)) { String s = node.getText(); singleSession = "true".equals(s) | "1".equals(s) | "on".equals(s); } else if (nodeName.equals(NODE_REQUIREAUTH)) { String s = node.getText(); requireAuth = "true".equals(s) | "1".equals(s) | "on".equals(s); } else if (nodeName.equals(NODE_USEAJAX)) { String s = node.getText(); useAjaxRendering = "true".equals(s) | "1".equals(s) | "on".equals(s); } else if (nodeName.equals(NODE_PROPERTY)) { if (properties == null) { properties = new HashMap<String, String>(); } properties.put(node.attribute(ATTR_NAME).getValue(), node.getText()); } } }