<[EMAIL PROTECTED]> writes: > Can someone tell me how the documentation for the Struts taglibs > (http://jakarta.apache.org/struts/struts-html.html) is currently > generated? I first assumed that this doc was generated from the .tld > files via XSLT or some other method. Nearly correct, but the source documents are not the *.tld files, but the corresponding *.xml files found in $STRUTS/doc (e.g. struts-html.xml). Hence, if you like to extend a taglib it is recommended that you adapt those XML docs and use $STRUTS/doc/stylesheets/tld.xsl to generate the taglib descriptors and $STRUTS/doc/stylesheets/struts.xsl to generate the documentation. Or even better you could use the attached Java class to merge your extensions into the original Struts tags documents for making update of Struts less painful. You could use an ant task like <!-- Generate combined taglib docs --> <target name="gen.xtaglib.docs" depends="compile.ext"> <mkdir dir="${build.work.taglibs}"/> <java classname="org.strutsx.util.build.MergeStrutsTaglibDoc"> <arg line="${src.doc}/struts/struts-html.xml ${src.doc.taglibs}/strutsx-html.xml ${build.work.taglibs}/strutsx-html-full.xml"/> <classpath> <pathelement location="${build.classes}"/> <pathelement location="${lib}/xerces.jar"/> </classpath> </java> </target> to include the merge into your build process. cu.... -- ...roland huss consol.de
package org.strutsx.util.build; import java.io.*; import org.apache.xerces.parsers.DOMParser; import org.w3c.dom.*; import org.xml.sax.*; public class MergeStrutsTaglibDoc { private static DOMParser parser = new org.apache.xerces.parsers.DOMParser(); public static void main(String args[]) { try { if (args.length != 3) { System.err.println("Usage: java ...MergeStrutsTaglibDoc " + "<orig-struts-taglib-doc> <strutsx-extension-taglib-doc> " + "<dest-file>"); System.exit(1); } try { parser.setFeature( "http://xml.org/sax/features/validation", true); } catch (SAXException e) { System.out.println("error in setting up parser feature"); } // Parse source & ext file Document struts_orig = parse(args[0]); Document struts_ext = parse(args[1]); String output = args[2]; // Merge (add special tags for extensions) NodeList elements = struts_ext.getElementsByTagName("tag"); for (int i=0;i<elements.getLength();i++) { Element el = (Element) elements.item(i); String name = extractName(el); // Extract from source all attributes NodeList src_attrs = getSourceTagAttrs(struts_orig,name); for (int j=0;j<src_attrs.getLength();j++) { el.appendChild(struts_ext.importNode(src_attrs.item(j),true)); } } // Write resulting XML-File FileWriter out_file = new FileWriter(output); print(new PrintWriter(out_file),struts_ext); } catch (Exception exp) { System.out.println("Got Exception: " + exp); exp.printStackTrace(); } } private static Document parse(String file) throws SAXException,IOException { // Using xerces.... parser.parse(file); return parser.getDocument(); } private static String extractName(Element el) { return (el.getElementsByTagName("name")).item(0).getFirstChild().getNodeValue(); } private static NodeList getSourceTagAttrs(Document doc,String name) { NodeList elements = doc.getElementsByTagName("tag"); for (int i=0;i<elements.getLength();i++) { Element el = (Element) elements.item(i); if (name.equalsIgnoreCase(extractName(el))) { return el.getElementsByTagName("attribute"); } } return null; } private static void print(PrintWriter out,Node node) { int type = node.getNodeType(); boolean canonical = true; switch ( type ) { // print document case Node.DOCUMENT_NODE: { out.println("<?xml version=\"1.0\"?>"); NodeList children = node.getChildNodes(); for ( int iChild = 0; iChild < children.getLength(); iChild++ ) { print(out,children.item(iChild)); } out.flush(); break; } // print element with attributes case Node.ELEMENT_NODE: { out.print('<'); out.print(node.getNodeName()); NamedNodeMap attrs = node.getAttributes(); for ( int i = 0; i < attrs.getLength(); i++ ) { Node attr = attrs.item(i); out.print(' '); out.print(attr.getNodeName()); out.print("=\""); out.print(normalize(attr.getNodeValue())); out.print('"'); } out.print('>'); NodeList children = node.getChildNodes(); if ( children != null ) { int len = children.getLength(); for ( int i = 0; i < len; i++ ) { print(out,children.item(i)); } } break; } // handle entity reference nodes case Node.ENTITY_REFERENCE_NODE: { if ( canonical ) { NodeList children = node.getChildNodes(); if ( children != null ) { int len = children.getLength(); for ( int i = 0; i < len; i++ ) { print(out,children.item(i)); } } } else { out.print('&'); out.print(node.getNodeName()); out.print(';'); } break; } // print cdata sections case Node.CDATA_SECTION_NODE: { if ( canonical ) { out.print(normalize(node.getNodeValue())); } else { out.print("<![CDATA["); out.print(node.getNodeValue()); out.print("]]>"); } break; } // print text case Node.TEXT_NODE: { out.print(normalize(node.getNodeValue())); break; } // print processing instruction case Node.PROCESSING_INSTRUCTION_NODE: { out.print("<?"); out.print(node.getNodeName()); String data = node.getNodeValue(); if ( data != null && data.length() > 0 ) { out.print(' '); out.print(data); } out.println("?>"); break; } } if ( type == Node.ELEMENT_NODE ) { out.print("</"); out.print(node.getNodeName()); out.print('>'); } out.print("\n"); out.flush(); } /** Normalizes the given string. */ private static String normalize(String s) { StringBuffer str = new StringBuffer(); int len = (s != null) ? s.length() : 0; for ( int i = 0; i < len; i++ ) { char ch = s.charAt(i); switch ( ch ) { case '<': { str.append("<"); break; } case '>': { str.append(">"); break; } case '&': { str.append("&"); break; } case '"': { str.append("""); break; } case '\'': { str.append("'"); break; } default: { str.append(ch); } } } return(str.toString()); } // normalize(String):String }