/** * This will invoke the <code>ContentHandler.processingInstruction</code> callback when a * processing instruction is encountered. * * @param pi <code>ProcessingInstruction</code> containing target and data. */ private void processingInstruction(ProcessingInstruction pi) throws JDOMException { if (pi != null) { String target = pi.getTarget(); String data = pi.getData(); try { contentHandler.processingInstruction(target, data); } catch (SAXException se) { throw new JDOMException("Exception in processingInstruction", se); } } }
public void processingInstruction(String target, String data) { // simplify logic???? into two cases in and not in DTD // ditto for comment() method and superclass if (!inDTD) flushText(); else if (!inInternalSubset()) return; ProcessingInstruction result = ProcessingInstruction.build(target, data); if (!inDTD) { if (inProlog) { parent.fastInsertChild(result, position); position++; } else { parent.fastInsertChild(result, parent.getChildCount()); } } else { internalDTDSubset.append(" "); internalDTDSubset.append(result.toXML()); internalDTDSubset.append("\n"); } }
private boolean shallowEquals(NodeInfo n1, Node n2) { if (n1 == n2) return true; if (n1 == null || n2 == null) return false; int type1 = n1.getNodeKind(); if (type1 == Node.CDATA_SECTION_NODE) type1 = Node.TEXT_NODE; else if (type1 == NodeType.NAMESPACE) type1 = Node.ATTRIBUTE_NODE; int type2 = n2.getNodeType(); if (type2 == Node.CDATA_SECTION_NODE) type2 = Node.TEXT_NODE; if (type1 != type2) return false; switch (type1) { case Node.PROCESSING_INSTRUCTION_NODE: ProcessingInstruction pi2 = (ProcessingInstruction) n2; String target1 = n1.getDisplayName(); String target2 = pi2.getTarget(); if (!target1.equals(target2)) return false; String data1 = n1.getStringValue(); String data2 = pi2.getData(); if (!data1.equals(data2)) return false; break; case Node.COMMENT_NODE: Comment comment2 = (Comment) n2; data1 = n1.getStringValue(); data2 = comment2.getData(); if (!data1.equals(data2)) return false; break; case Node.ELEMENT_NODE: Element element2 = (Element) n2; String namespaceURI1 = n1.getURI(); if (namespaceURI1 == null) namespaceURI1 = ""; String namespaceURI2 = element2.getNamespaceURI(); if (namespaceURI2 == null) namespaceURI2 = ""; if (!namespaceURI1.equals(namespaceURI2)) return false; String localName1 = n1.getLocalPart(); String localName2 = element2.getLocalName(); if (!localName1.equals(localName2)) return false; NodeInfoSequence attrs1 = new NodeInfoSequence(n1, Axis.ATTRIBUTE); NamedNodeMap attrs2 = element2.getAttributes(); BitSet bitSet = new BitSet(); NodeInfo attr1; while ((attr1 = attrs1.findNext()) != null) { if (isNamespaceDeclaration(attr1)) continue; namespaceURI1 = attr1.getURI(); if (namespaceURI1 == null) namespaceURI1 = ""; localName1 = attr1.getLocalPart(); String value1 = attr1.getStringValue(); int found = -1; for (int i = 0; i < attrs2.getLength(); i++) { Attr attr2 = (Attr) attrs2.item(i); namespaceURI2 = attr2.getNamespaceURI(); if (namespaceURI2 == null) namespaceURI2 = ""; localName2 = attr2.getLocalName(); if (namespaceURI1.equals(namespaceURI2) && localName1.equals(localName2)) { String value2 = attr2.getNodeValue(); if (!value1.equals(value2)) return false; found = i; break; } } if (found == -1) return false; else bitSet.set(found); } for (int i = 0; i < attrs2.getLength(); i++) { if (!bitSet.get(i)) { Attr attr2 = (Attr) attrs2.item(i); if (!DOMUtil.isNamespaceDeclaration(attr2)) return false; } } break; case Node.ATTRIBUTE_NODE: Attr attr2 = (Attr) n2; namespaceURI1 = isNamespaceDeclaration(n1) ? Namespaces.URI_XMLNS : n1.getURI(); if (namespaceURI1 == null) namespaceURI1 = ""; namespaceURI2 = attr2.getNamespaceURI(); if (namespaceURI2 == null) namespaceURI2 = ""; if (!namespaceURI1.equals(namespaceURI2)) return false; localName1 = n1.getLocalPart(); localName2 = attr2.getLocalName(); if (!localName1.equals(localName2)) return false; String value1 = n1.getStringValue(); String value2 = attr2.getNodeValue(); if (!value1.equals(value2)) return false; break; case Node.TEXT_NODE: value1 = n1.getStringValue(); value2 = n2.getNodeValue(); if (!value1.equals(value2)) return false; } return true; }
/** * Sets a parameter for the fragment. The object set as parameter value must not be changed during * all the execution, otherwise the result won't be as expected. That is, if this object has a * method that changes its content, this method must not be called by the Formatter during the * service() method. Otherwise, all the rendering performed by the fragmentValue tag will use the * *last* version of the object, the one existing after the invocation of service method, which is * probably not expected. * * <p>Example, of a iterating formatter: <code> * StringBuffer sb = new StringBuffer();<br> * for( int i= 0; i<10; i++){<br> * sb.delete(0,sb.length())<br> * sb.append( i );<br> * setAttribute("index",sb);<br> * renderFragment("output");<br> * }<br> * * </code> will generate an output like : 10 10 10 10 10 10 10 10 10 10 while the expected output * is: 0 1 2 3 4 5 6 7 8 9 * * <p>So, use objects and don't change them. This is usually easy to accomplish, by using * different instances, in the example above, replace sb.delete(0,sb.length()) with sb = new * StringBuffer(); * * @param name Name of the parameter. * @param value It's value. Must not be changed during all the execution. */ protected void setAttribute(String name, double value) { if (log.isDebugEnabled()) log.debug("Setting of attribute " + name + " scheduled."); tag.addProcessingInstruction( ProcessingInstruction.getSetParameterInstruction(name, new Double(value))); }
protected void setAttributeInterpreter(FormaterTagDynamicAttributesInterpreter interpreter) { tag.addProcessingInstruction( ProcessingInstruction.getAddAttributesInterpreterInstruction(interpreter)); }
protected void writeToOut(String text) { if (log.isDebugEnabled()) log.debug("Writting '" + text + "' to output, scheduled."); tag.addProcessingInstruction(ProcessingInstruction.getWriteToOutInstruction(text)); }
protected void includePage(String pageName) { if (log.isDebugEnabled()) log.debug("Including of page " + pageName + " scheduled."); tag.addProcessingInstruction(ProcessingInstruction.getIncludePageInstruction(pageName)); }
/** * Orders the processing of fragment with given name. * * @param fragmentName Name of the fragment to be rendered. */ protected void renderFragment(String fragmentName) { if (log.isDebugEnabled()) log.debug("Rendering of fragment " + fragmentName + " scheduled."); tag.addProcessingInstruction(ProcessingInstruction.getRenderFragmentInstruction(fragmentName)); }