List of usage examples for org.dom4j Namespace hasContent
public boolean hasContent()
From source file:com.webslingerz.jpt.PageTemplateImpl.java
License:Open Source License
AttributesImpl getAttributes(Element element, Expressions expressions) throws PageTemplateException { AttributesImpl attributes = new AttributesImpl(); for (Iterator i = element.attributeIterator(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); Namespace namespace = attribute.getNamespace(); Namespace elementNamespace = element.getNamespace(); if (!namespace.hasContent() && elementNamespace.hasContent()) namespace = elementNamespace; // String prefix = namespace.getPrefix(); // System.err.println( "attribute: name=" + attribute.getName() + // "\t" + // "qualified name=" + attribute.getQualifiedName() + "\t" + // "ns prefix=" + namespace.getPrefix() + "\t" + // "ns uri=" + namespace.getURI() ); // String qualifiedName = attribute.getName(); // String name = qualifiedName; // if ( qualifiedName.startsWith( prefix + ":" ) ) { // name = qualifiedName.substring( prefix.length() + 1 ); // }//from www . j a v a2 s . c o m String name = attribute.getName(); // Handle JPT attributes // if ( prefix.equals( talNamespacePrefix ) ) { if (TAL_NAMESPACE_URI.equals(namespace.getURI()) || (!strict && TAL_NAMESPACE_PREFIX.equals(namespace.getPrefix()))) { // tal:define if (name.equals("define")) { expressions.define = attribute.getValue(); } // tal:condition else if (name.equals("condition")) { expressions.condition = attribute.getValue(); } // tal:repeat else if (name.equals("repeat")) { expressions.repeat = attribute.getValue(); } // tal:content else if (name.equals("content")) { expressions.content = attribute.getValue(); } // tal:replace else if (name.equals("replace")) { if (expressions.omitTag == null) { expressions.omitTag = ""; } expressions.content = attribute.getValue(); } // tal:attributes else if (name.equals("attributes")) { expressions.attributes = attribute.getValue(); } // tal:omit-tag else if (name.equals("omit-tag")) { expressions.omitTag = attribute.getValue(); } // error else { throw new PageTemplateException("unknown tal attribute: " + name); } } // else if ( prefix.equals( metalNamespacePrefix ) ) else if (METAL_NAMESPACE_URI.equals(namespace.getURI()) || (!strict && METAL_NAMESPACE_PREFIX.equals(namespace.getPrefix()))) { // metal:use-macro if (name.equals("use-macro")) { expressions.useMacro = attribute.getValue(); } // metal:define-slot else if (name.equals("define-slot")) { expressions.defineSlot = attribute.getValue(); } // metal:define-macro else if (name.equals("define-macro")) { //System.out.println("Defining macro: " + attribute.getValue()); Element el = element.createCopy(); el.remove(attribute); macros.put(attribute.getValue(), new MacroImpl(el)); expressions.macro = true; } // metal:fill-slot else if (name.equals("fill-slot")) { // these are ignored here, as they don't affect processing // of current template, but are called from other templates } // error else { throw new PageTemplateException("unknown metal attribute: " + name); } } // Pass on all other attributes else { String nsURI = namespace.getURI(); // String qualifiedName = namespace.getPrefix() + ":" + name; attributes.addAttribute(nsURI, name, attribute.getQualifiedName(), "CDATA", attribute.getValue()); if (nsURI != "" && namespace != elementNamespace) { String prefix = namespace.getPrefix(); String qName = "xmlns:" + prefix; if (attributes.getIndex(qName) == -1) { // add xmlns for this attribute attributes.addAttribute("", prefix, qName, "CDATA", nsURI); } } // attributes.addAttribute( getNamespaceURIFromPrefix(prefix), // name, qualifiedName, "CDATA", attribute.getValue() ); } } return attributes; }