List of usage examples for org.dom4j Attribute getNamespacePrefix
String getNamespacePrefix();
String
is returned. From source file:org.withinsea.izayoi.cortile.core.compile.dom.DOMCompiler.java
License:Mozilla Public License
@SuppressWarnings("unchecked") protected void compile(Node node) throws CortileException { CompileContext ctx = CompileContext.get(); if (node instanceof Text) { Text text = (Text) node; for (TextGrammar tg : textGrammars) { if (isDetached(text)) return; if (tg.acceptText(text)) { tg.processText(text);//from ww w.jav a 2s . com } } } else if (node instanceof Comment) { Comment comment = (Comment) node; for (CommentGrammar cg : commentGrammars) { if (isDetached(comment)) return; if (cg.acceptComment(comment)) { cg.processComment(comment); } } } else if (node instanceof Branch) { ctx.openScope(); inScope: { if (node instanceof Element) { Element element = (Element) node; for (ElementGrammar eg : elementGrammars) { if (isDetached(element)) break inScope; if (eg.acceptElement(element)) { eg.processElement(element); } } for (Map.Entry<Integer, Map<String, List<AttrGrammar>>> entry : attrGrammars.entrySet()) { Map<String, List<AttrGrammar>> ags = entry.getValue(); List<Attribute> attrs = new ArrayList<Attribute>((List<Attribute>) element.attributes()); for (Attribute attr : attrs) { if (isDetached(element)) break inScope; if (isDetached(attr)) continue; Set<AttrGrammar> nsAgs = new LinkedHashSet<AttrGrammar>(); { nsAgs.addAll(ags.get("*")); nsAgs.addAll(ags.get(attr.getNamespacePrefix())); } for (AttrGrammar ag : nsAgs) { if (isDetached(element)) break inScope; if (isDetached(attr)) break; if (ag.acceptAttr(attr)) { ag.processAttr(attr); } } } } } Branch branch = (Branch) node; List<Node> cnodes = new ArrayList<Node>((List<Node>) branch.content()); for (Node cnode : cnodes) { if (isDetached(branch)) break inScope; if (isDetached(cnode)) continue; compile(cnode); } } ctx.closeScope(); } }
From source file:org.withinsea.izayoi.cortile.template.html.grammar.attr.core.ByContent.java
License:Mozilla Public License
@Override @SuppressWarnings("unchecked") @Priority(Priority.HIGHEST)/*from ww w . j av a 2s. co m*/ public void processAttr(Attribute attr) throws CortileException { Element elem = attr.getParent(); String prefix = attr.getNamespacePrefix(); List<Attribute> attrs = new ArrayList<Attribute>((List<Attribute>) elem.attributes()); try { Element scope = elem; for (int i = attrs.indexOf(attr); i < attrs.size(); i++) { Attribute iAttr = attrs.get(i); String iAttrname = iAttr.getName(); if (iAttr.getNamespacePrefix().equals(prefix) && iAttrname.matches("^\\w+\\-content.*")) { Element contentScope = new DefaultElement(HTMLConstants.ANONYMOUS_TAG_NAME); DOMUtils.surroundInsideBy(scope, contentScope); iAttr.detach(); contentScope .add(new SurroundableAttr(new QName(iAttrname.replaceFirst("^(\\w+)\\-content", "$1"), iAttr.getQName().getNamespace()), iAttr.getValue())); for (int j = i + 1; j < attrs.size(); j++) { Attribute jAttr = attrs.get(j); jAttr.detach(); contentScope.add(jAttr); } scope = contentScope; } } } catch (Exception e) { throw new CortileException(e); } }