org.w3c.dom.* org.apache.cocoon.components.source.SourceUtil org.apache.cocoon.xml.dom.DOMStreamer org.apache.excalibur.xml.dom.DOMParser org.apache.excalibur.source.Source >= 0) { tagColor = CUSTOM_ELEMENT_COLOR; } result = factory.createElement("font"); result.setAttribute("color", tagColor); result.appendChild(factory.createTextNode(tagName)); fragment.appendChild(result); NamedNodeMap attributes = element.getAttributes(); int attributeCount = attributes.getLength(); for (int i = 0; i < attributeCount; i++) { Attr attribute = (Attr) attributes.item(i); result = factory.createElement("font"); result.setAttribute("color", ATTR_NAME_COLOR); result.appendChild( factory.createTextNode(" " + attribute.getName() + "=") ); fragment.appendChild(result); result = factory.createElement("font"); result.setAttribute("color", ATTR_VALUE_COLOR); result.appendChild( factory.createTextNode("\"" + attribute.getValue() + "\"") ); fragment.appendChild(result); } NodeList nodeList = element.getChildNodes(); int childCount = nodeList.getLength(); result = factory.createElement("font"); result.setAttribute("color", DELIMITER_COLOR); result.appendChild( factory.createTextNode((childCount == 0 ? "/" : "") + ">") ); fragment.appendChild(result); if (tagName.startsWith("xsp:")) { textColor = XSP_TEXT_COLOR; } else { textColor = TEXT_COLOR; } result = factory.createElement("font"); result.setAttribute("color", textColor); for (int i = 0; i < childCount; i++) { result.appendChild( doColorize(nodeList.item(i), factory, level + 1, textColor) ); } fragment.appendChild(result); if (childCount > 0) { result = factory.createElement("font"); result.setAttribute("color", DELIMITER_COLOR); result.appendChild(factory.createTextNode("")); fragment.appendChild(result); } break; } case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: { NodeList nodeList = node.getChildNodes(); int childCount = nodeList.getLength(); for (int i = 0; i < childCount; i++) { fragment.appendChild( doColorize(nodeList.item(i), factory, level + 1, textColor) ); } break; } case Node.COMMENT_NODE: result = factory.createElement("font"); result.setAttribute("color", COMMENT_COLOR); result.appendChild( factory.createTextNode( "" ) ); fragment.appendChild(result); break; case Node.PROCESSING_INSTRUCTION_NODE: ProcessingInstruction pi = (ProcessingInstruction) node; result = factory.createElement("font"); result.setAttribute("color", DELIMITER_COLOR); result.appendChild(factory.createTextNode("\n")); fragment.appendChild(result); break; case Node.ENTITY_REFERENCE_NODE: result = factory.createElement("font"); result.setAttribute("color", ENTITY_REF_COLOR); result.appendChild( factory.createTextNode("<" + node.getNodeValue() + ";") ); fragment.appendChild(result); break; case Node.TEXT_NODE: fragment.appendChild(factory.createTextNode(node.getNodeValue())); break; default: break; } return fragment; } ]]> Source Code String filename = request.getParameter("filename"); if (filename != null) {

filename

DOMParser parser = null; Source source = null; try { parser = (DOMParser)manager.lookup(DOMParser.ROLE); Document outputDocument = parser.createDocument(); source = super.resolver.resolveURI("context://" + filename); Document sourceDocument = parser.parseDocument(SourceUtil.getInputSource(source)); this.colorize(sourceDocument, outputDocument); } catch (SAXException e){ getLogger().debug("SAXException in colorize", e); throw e; } catch (org.w3c.dom.DOMException e){ getLogger().debug("DOMException in colorize", e); throw e; } catch (Exception e) { getLogger().error("Could not include page", e);

Could not include page: e

} finally { this.manager.release((Component) parser); if (source != null) { super.resolver.release(source); source = null; } } } else {

Need filename or url parameters to work

}