cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r386834 - in /cocoon/whiteboard/sitemaptags2daisy: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/cocoon/ src/main/java/org/apache/cocoon/documentation/ src/main/java/org/apache/cocoon...
Date Sat, 18 Mar 2006 09:52:20 GMT
Author: bruno
Date: Sat Mar 18 01:52:16 2006
New Revision: 386834

URL: http://svn.apache.org/viewcvs?rev=386834&view=rev
Log:
Initial commit of a tool to sync sitemap component information from the source files to Daisy
documents.

Added:
    cocoon/whiteboard/sitemaptags2daisy/
    cocoon/whiteboard/sitemaptags2daisy/README.txt   (with props)
    cocoon/whiteboard/sitemaptags2daisy/pom.xml   (with props)
    cocoon/whiteboard/sitemaptags2daisy/src/
    cocoon/whiteboard/sitemaptags2daisy/src/main/
    cocoon/whiteboard/sitemaptags2daisy/src/main/java/
    cocoon/whiteboard/sitemaptags2daisy/src/main/java/org/
    cocoon/whiteboard/sitemaptags2daisy/src/main/java/org/apache/
    cocoon/whiteboard/sitemaptags2daisy/src/main/java/org/apache/cocoon/
    cocoon/whiteboard/sitemaptags2daisy/src/main/java/org/apache/cocoon/documentation/
    cocoon/whiteboard/sitemaptags2daisy/src/main/java/org/apache/cocoon/documentation/daisy/
    cocoon/whiteboard/sitemaptags2daisy/src/main/java/org/apache/cocoon/documentation/daisy/SitemapTagsToDaisy.java
  (with props)
    cocoon/whiteboard/sitemaptags2daisy/src/main/resources/
    cocoon/whiteboard/sitemaptags2daisy/src/main/resources/org/
    cocoon/whiteboard/sitemaptags2daisy/src/main/resources/org/apache/
    cocoon/whiteboard/sitemaptags2daisy/src/main/resources/org/apache/cocoon/
    cocoon/whiteboard/sitemaptags2daisy/src/main/resources/org/apache/cocoon/documentation/
    cocoon/whiteboard/sitemaptags2daisy/src/main/resources/org/apache/cocoon/documentation/daisy/
    cocoon/whiteboard/sitemaptags2daisy/src/main/resources/org/apache/cocoon/documentation/daisy/htmlcleaner.xml
  (with props)

Added: cocoon/whiteboard/sitemaptags2daisy/README.txt
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/sitemaptags2daisy/README.txt?rev=386834&view=auto
==============================================================================
--- cocoon/whiteboard/sitemaptags2daisy/README.txt (added)
+++ cocoon/whiteboard/sitemaptags2daisy/README.txt Sat Mar 18 01:52:16 2006
@@ -0,0 +1,59 @@
+What this is about
+==================
+
+To manage its documentation, Cocoon uses an instance of the Daisy CMS running at:
+http://cocoon.zones.apache.org/daisy/
+
+This directory contains a tool to sync information about sitemap components to
+Daisy documents.
+
+Since you normally never use sitemap components by their Java API, but rather
+just from the sitemap, it makes more sense to document these components in
+Daisy. This makes it easier to manage longer and better formatted documentation,
+and doesn't scare non-Java-developers away from Cocoon.
+
+The sync tool takes a few special javadoc-style annotations into account:
+
+@cocoon.sitemap.component.name
+   default name with which this component is declared in the sitemap
+
+@cocoon.sitemap.component.documentation.disabled
+   excludes the component from the documentation
+
+@cocoon.sitemap.component.documentation
+   A short (one-paragraph) description of the component.
+   Can contain HTML markup (preferably only inline tags).
+
+@cocoon.sitemap.component.documentation.caching
+   A comment about the caching of this component. The cacheability of the
+   component is figured out automatially by its implemented interfaces, but
+   this tag allows to provide a short comment on the chaching conditions.
+   This is mapped to a field in Daisy, thus should not contain HTML markup.
+
+The tool will not update documents unnecessarily, to avoid generating
+new document versions in Daisy each time it is run.
+
+Compiling
+=========
+
+Execute:
+
+mvn compile
+
+
+Running
+=======
+
+A script is automatically generated in the target directory to launch the tool.
+
+The tool will interactively ask the parameters it needs (Cocoon source tree location,
+Daisy host, Daisy username, Daisy password). You need to have the Administrator role
+in Daisy in order to run this.
+
+Linux, OS X, and similar:
+
+sh target/sitemaptags_to_daisy.sh
+
+Windows:   --- NOT TESTED YET, DON'T KNOW IF THIS WORKS ---
+
+target/sitemaptags_to_daisy.bat
\ No newline at end of file

Propchange: cocoon/whiteboard/sitemaptags2daisy/README.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/sitemaptags2daisy/pom.xml
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/sitemaptags2daisy/pom.xml?rev=386834&view=auto
==============================================================================
--- cocoon/whiteboard/sitemaptags2daisy/pom.xml (added)
+++ cocoon/whiteboard/sitemaptags2daisy/pom.xml Sat Mar 18 01:52:16 2006
@@ -0,0 +1,205 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.cocoon</groupId>
+  <artifactId>cocoon-documentation-sitemaptags2daisy</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <name>Cocoon: Documentation: tool to sync the sitemap component info to the Daisy
CMS</name>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <executions>
+          <execution>
+            <phase>compile</phase>
+            <configuration>
+              <!-- Generate a shell script and bat file to launch the tool. -->
+              <tasks>
+                <property name="runtimeClasspath" refid="maven.runtime.classpath"/>
+                <echo file="target/sitemaptags_to_daisy.sh">CLASSPATH="${runtimeClasspath}"
+export CLASSPATH
+java org.apache.cocoon.documentation.daisy.SitemapTagsToDaisy
+                </echo>
+                <echo file="target/sitemaptags_to_daisy.bat">set CLASSPATH="${runtimeClasspath}"
+java org.apache.cocoon.documentation.daisy.SitemapTagsToDaisy
+                </echo>
+              </tasks>
+            </configuration>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <repositories>
+    <repository>
+      <id>apache-maven2</id>
+      <name>Apache Maven2 Repository</name>
+      <url>http://cvs.apache.org/maven-snapshot-repository</url>
+    </repository>
+    <!-- The cocoondev repository contains the needed Daisy artifacts -->
+    <repository>
+      <id>cocoondev</id>
+      <name>Cocoondev Maven Repository</name>
+      <url>http://cocoondev.org/repository</url>
+      <layout>legacy</layout>
+    </repository>
+    <repository>
+      <id>apache-cvs</id>
+      <name>Apache CVS Repository</name>
+      <url>http://cvs.apache.org/repository</url>
+      <layout>legacy</layout>
+    </repository>
+    <repository>
+      <id>maven-snapshot</id>
+      <name>Maven snapshot Repository</name>
+      <url>http://snapshots.maven.codehaus.org/maven2/</url>
+    </repository>
+  </repositories>
+
+  <!-- Seemingly long list of dependencies, but most are runtime dependencies.
+       If/when Daisy is build using maven2 itself, transitive dependencies
+       will probably allow to clean up this list -->
+  <dependencies>
+    <dependency>
+      <groupId>daisy</groupId>
+      <artifactId>daisy-repository-api</artifactId>
+      <version>1.5-dev</version>
+    </dependency>
+    <dependency>
+      <groupId>daisy</groupId>
+      <artifactId>daisy-repository-xmlschema-bindings</artifactId>
+      <version>1.5-dev</version>
+    </dependency>
+    <dependency>
+      <groupId>daisy</groupId>
+      <artifactId>daisy-repository-client-impl</artifactId>
+      <version>1.5-dev</version>
+    </dependency>
+    <dependency>
+      <groupId>daisy</groupId>
+      <artifactId>daisy-repository-common-impl</artifactId>
+      <version>1.5-dev</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>daisy</groupId>
+      <artifactId>daisy-repository-spi</artifactId>
+      <version>1.5-dev</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>daisy</groupId>
+      <artifactId>daisy-jmsclient-api</artifactId>
+      <version>1.5-dev</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+      <version>3.1</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-httpclient</groupId>
+      <artifactId>commons-httpclient</artifactId>
+      <version>2.0.2</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.0.4</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>concurrent</groupId>
+      <artifactId>concurrent</artifactId>
+      <version>1.3.2</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>xmlbeans</groupId>
+      <artifactId>xbean</artifactId>
+      <version>2.1.0</version>
+    </dependency>
+    <dependency>
+      <groupId>stax</groupId>
+      <artifactId>stax-api</artifactId>
+      <version>1.0</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>daisy</groupId>
+      <artifactId>daisy-htmlcleaner</artifactId>
+      <version>1.5-dev</version>
+    </dependency>
+    <dependency>
+      <groupId>daisy</groupId>
+      <artifactId>daisy-util</artifactId>
+      <version>1.5-dev</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>qdox</groupId>
+      <artifactId>qdox</artifactId>
+      <version>1.5</version>
+    </dependency>
+    <dependency>
+      <groupId>nekohtml</groupId>
+      <artifactId>nekohtml</artifactId>
+      <version>0.9.5</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>nekodtd</groupId>
+      <artifactId>nekodtd</artifactId>
+      <version>0.1.11</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>xerces</groupId>
+      <artifactId>xercesImpl</artifactId>
+      <version>2.6.2</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>xerces</groupId>
+      <artifactId>xmlParserAPIs</artifactId>
+      <version>2.6.2</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>xerces</groupId>
+      <artifactId>xmlParserAPIs</artifactId>
+      <version>2.6.2</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>avalon-framework</groupId>
+      <artifactId>avalon-framework-api</artifactId>
+      <version>4.2.0</version>
+      <scope>runtime</scope>
+    </dependency>
+  </dependencies>
+</project>

Propchange: cocoon/whiteboard/sitemaptags2daisy/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/sitemaptags2daisy/src/main/java/org/apache/cocoon/documentation/daisy/SitemapTagsToDaisy.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/sitemaptags2daisy/src/main/java/org/apache/cocoon/documentation/daisy/SitemapTagsToDaisy.java?rev=386834&view=auto
==============================================================================
--- cocoon/whiteboard/sitemaptags2daisy/src/main/java/org/apache/cocoon/documentation/daisy/SitemapTagsToDaisy.java
(added)
+++ cocoon/whiteboard/sitemaptags2daisy/src/main/java/org/apache/cocoon/documentation/daisy/SitemapTagsToDaisy.java
Sat Mar 18 01:52:16 2006
@@ -0,0 +1,504 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.documentation.daisy;
+
+import com.thoughtworks.qdox.JavaDocBuilder;
+import com.thoughtworks.qdox.model.JavaClass;
+import com.thoughtworks.qdox.model.DocletTag;
+
+import java.io.*;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Locale;
+
+import org.outerj.daisy.htmlcleaner.HtmlCleanerFactory;
+import org.outerj.daisy.htmlcleaner.HtmlCleanerTemplate;
+import org.outerj.daisy.repository.Document;
+import org.outerj.daisy.repository.Repository;
+import org.outerj.daisy.repository.Credentials;
+import org.outerj.daisy.repository.RepositoryManager;
+import org.outerj.daisy.repository.query.QueryHelper;
+import org.outerj.daisy.repository.clientimpl.RemoteRepositoryManager;
+import org.xml.sax.InputSource;
+import org.outerx.daisy.x10.SearchResultDocument;
+
+/**
+ * A tool to sync the information about sitemap components from the Java
+ * sources to the Daisy documentation, supports custom annotations using
+ * cocoon.sitemap.* tags. See the README.txt for more details.
+ *
+ * <p>Reuses some ideas from the Ant SitemapTask in Cocoon 2.1.
+ */
+public class SitemapTagsToDaisy {
+    private static final String GENERATOR = "org.apache.cocoon.generation.Generator";
+    private static final String TRANSFORMER = "org.apache.cocoon.transformation.Transformer";
+    private static final String SERIALIZER = "org.apache.cocoon.serialization.Serializer";
+    private static final String READER = "org.apache.cocoon.reading.Reader";
+    private static final String MATCHER = "org.apache.cocoon.matching.Matcher";
+    private static final String SELECTOR = "org.apache.cocoon.selection.Selector";
+    private static final String ACTION = "org.apache.cocoon.acting.Action";
+    private static final String PIPELINE = "org.apache.cocoon.components.pipeline.ProcessingPipeline";
+
+    private static final String CACHEABLE = "org.apache.cocoon.caching.CacheableProcessingComponent";
+    private static final String DEPRECATED_CACHEABLE = "org.apache.cocoon.caching.Cacheable";
+
+    /** The name of the component in the sitemap (required) */
+    public static final String NAME_TAG   = "cocoon.sitemap.component.name";
+    /** If this tag is specified no documentation is generated (optional) */
+    public static final String NO_DOC_TAG = "cocoon.sitemap.component.documentation.disabled";
+    /** The documentation (optional) */
+    public static final String DOC_TAG    = "cocoon.sitemap.component.documentation";
+    /** Caching info (optional) */
+    public static final String CACHING_INFO_TAG = "cocoon.sitemap.component.documentation.caching";
+
+    private static final String DAISY_BLOCK_FIELD = "CocoonBlock";
+    private static final String DAISY_CLASSNAME_FIELD = "JavaClassName";
+    private static final String DAISY_COMPONENT_TYPE_FIELD = "CocoonComponentReference";
+    private static final String DAISY_CACHEABLE_FIELD = "SitemapComponentCacheabilityInfo";
+    private static final String DAISY_DEPRECATED_FIELD = "SitemapComponentDeprecationInfo";
+    private static final String DAISY_COMPONENT_NAME_FIELD = "SitemapComponentName";
+    private static final String DAISY_SHORTDESCR_PART = "SitemapComponentShortDescription";
+    private static final String DAISY_DOCTYPE = "SitemapComponent";
+
+    private HtmlCleanerTemplate htmlCleanerTemplate;
+    private Repository daisyRepository;
+    private String daisyCollection;
+    private boolean simulate;
+
+    public static void main(String[] args) throws Exception {
+        new SitemapTagsToDaisy().run();
+    }
+
+    public void run() throws Exception {
+        System.out.println();
+        System.out.println("===================================================================================");
+        System.out.println("This is the source annotations to Daisy documents sync tool for
sitemap components.");
+        System.out.println("===================================================================================");
+        System.out.println();
+
+        String rootPath = prompt("Enter the path to the Cocoon source directory:");
+        File rootDir = new File(rootPath);
+        File cocoonCoreDir = new File(rootDir, "cocoon-core");
+        if (!cocoonCoreDir.exists()) {
+            System.out.println("This is not a valid Cocoon source directory, did not find
the following path: " + cocoonCoreDir.getPath());
+            System.exit(1);
+        }
+        // Normalize path
+        rootPath = rootDir.toURL().getPath();
+
+        setupHtmlCleanerTemplate();
+
+        String daisyServer = prompt("Enter the address of the Daisy repository server, e.g.
http://cocoon.zones.apache.org:9263 :");
+        String daisyUser = prompt("Enter you Daisy user name (you need to have the Administrator
role): ");
+        String daisyPwd = prompt("Enter you Daisy password: ");
+        setupDaisyRepositoryClient(daisyServer, daisyUser, daisyPwd);
+
+        while (true) {
+            String simulateInput = prompt("Run in simulate mode (won't update documents in
Daisy) [yes/no] : ");
+            if (simulateInput.equals("yes") || simulateInput.equals("no")) {
+                simulate = simulateInput.equals("yes");
+                break;
+            } else {
+                System.out.println("Enter yes or no.");
+            }
+        }
+
+        daisyCollection = "documentation";
+
+        JavaDocBuilder javaDocBuilder = getJavaDocBuilder(rootPath);
+
+        JavaClass[] allClasses = javaDocBuilder.getClasses();
+        int newDocs = 0;
+        int updatedDocs = 0;
+        int unmodifiedDocs = 0;
+
+        try {
+            for (int i = 0; i < allClasses.length; i++) {
+                JavaClass currentClass = allClasses[i];
+                if (!currentClass.isAbstract() && !currentClass.isPrivate() &&
!currentClass.isProtected()
+                        &&!currentClass.isInterface() &&!currentClass.isInner())
{
+                    String componentType = getComponentTypeName(currentClass);
+                    if (componentType != null) {
+                        if (currentClass.getTagByName(NO_DOC_TAG) != null)
+                            continue;
+
+                        String blockName = determineBlock(rootPath, currentClass);
+                        if (blockName == null)
+                            continue;
+
+                        ComponentDocs docs = getComponentDocs(currentClass, componentType,
blockName);
+
+                        Document daisyDoc = getDaisyDoc(docs);
+                        if (daisyDoc == null) {
+                            System.out.println("Creating the document for " + currentClass.getFullyQualifiedName());
+                            createDocument(docs, currentClass.getName());
+                            newDocs++;
+                        } else {
+                            ComponentDocs oldDocs = getComponentDocs(daisyDoc);
+                            if (!docs.equals(oldDocs)) {
+                                System.out.println("Will update the document for " + currentClass.getFullyQualifiedName());
+                                updateDocument(daisyDoc, docs);
+                                updatedDocs++;
+                            } else {
+                                System.out.println("No update required for " + currentClass.getFullyQualifiedName());
+                                unmodifiedDocs++;
+                            }
+                        }
+                    }
+                }
+            }
+        } finally {
+            System.out.println("New documents: " + newDocs);
+            System.out.println("Updated documents: " + updatedDocs);
+            System.out.println("Unmodified documents: " + unmodifiedDocs);
+        }
+    }
+
+    private JavaDocBuilder getJavaDocBuilder(String rootPath) {
+        File rootFile = new File(rootPath);
+
+        System.out.println("Searching java directories in " + rootPath + " ...");
+        List javaDirs = new ArrayList(100);
+        collectJavaDirs(javaDirs, rootFile);
+        System.out.println("Found " + javaDirs.size() + " java directories.");
+
+        JavaDocBuilder javaDocBuilder = new JavaDocBuilder();
+        Iterator javaDirsIt = javaDirs.iterator();
+        while (javaDirsIt.hasNext()) {
+            File currentDir = (File)javaDirsIt.next();
+            System.out.println("Parsing sources in " + currentDir.getPath());
+            javaDocBuilder.addSourceTree(currentDir);
+        }
+        System.out.println("Done parsing sources.");
+
+        return javaDocBuilder;
+    }
+
+    private void collectJavaDirs(List javaDirs, File currentDir) {
+        File[] files = currentDir.listFiles();
+        for (int i = 0; i < files.length; i++) {
+            if (files[i].isDirectory()) {
+                if (files[i].getName().equals("java")) {
+                    javaDirs.add(files[i]);
+                } else {
+                    collectJavaDirs(javaDirs, files[i]);
+                }
+            }
+        }
+    }
+
+    private String getComponentTypeName(JavaClass javaClass) {
+        if (javaClass.isA(GENERATOR)) {
+            return "generator";
+        } else if (javaClass.isA(TRANSFORMER)) {
+            return "transformer";
+        } else if (javaClass.isA(READER)) {
+            return "reader";
+        } else if (javaClass.isA(SERIALIZER)) {
+            return "serializer";
+        } else if (javaClass.isA(ACTION)) {
+            return "action";
+        } else if (javaClass.isA(MATCHER)) {
+            return "matcher";
+        } else if (javaClass.isA(SELECTOR)) {
+            return "selector";
+        } else if (javaClass.isA(PIPELINE)) {
+            return "pipe";
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Extracts the block name from the directory name.
+     */
+    private String determineBlock(String rootPath, JavaClass javaClass) {
+        String path = javaClass.getSource().getURL().getPath();
+        if (!path.startsWith(rootPath))
+            return null;
+
+        String subPath = path.substring(rootPath.length());
+        if (subPath.startsWith("/"))
+            subPath = subPath.substring(1);
+        if (!subPath.startsWith("cocoon-"))
+            return null;
+
+        int slashPos = subPath.indexOf("/");
+        if (slashPos == -1) // very unlikely
+            return null;
+
+        String blockName = subPath.substring("cocoon-".length(), slashPos);
+        return blockName;
+    }
+
+    /**
+     * This class contains the information that is synced from the source file
+     * to a Daisy document.
+     */
+    static class ComponentDocs {
+        /** The name of the block in which this component occurs. */
+        String blockName;
+        /** Fully-qualified Java class name of the component. */
+        String className;
+        /** Component type: generator, transformer, etc. */
+        String componentType;
+        /** Short component name as used in the sitemamp. */
+        String componentName;
+        /** The short description of this component, as HTML. */
+        String documentation;
+        /** Information about the caceability of this component. */
+        String cacheInfo;
+        /** Deprecated info about this component.*/
+        String deprecated;
+
+        public boolean equals(Object obj) {
+            ComponentDocs other = (ComponentDocs)obj;
+            if (!safeComp(blockName, other.blockName))
+                return false;
+            if (!safeComp(className, other.className))
+                return false;
+            if (!safeComp(componentType, other.componentType))
+                return false;
+            if (!safeComp(componentName, other.componentName))
+                return false;
+            if (!safeComp(documentation, other.documentation))
+                return false;
+            if (!safeComp(cacheInfo, other.cacheInfo))
+                return false;
+            if (!safeComp(deprecated, other.deprecated))
+                return false;
+            return true;
+        }
+
+        private boolean safeComp(String value1, String value2) {
+            if (value1 == null && value2 == null)
+                return true;
+            if (value1 == null || value2 == null)
+                return false;
+            else
+                return value1.equals(value2);
+        }
+    }
+
+    /**
+     * Gets a {@link ComponentDocs} instance by extracting info from a Java source file.
+     */
+    private ComponentDocs getComponentDocs(JavaClass javaClass, String componentType, String
blockName) throws Exception {
+        ComponentDocs componentDocs = new ComponentDocs();
+        componentDocs.componentType = componentType;
+        componentDocs.className = javaClass.getFullyQualifiedName();
+        componentDocs.blockName = blockName;
+
+        DocletTag documentationTag = javaClass.getTagByName(DOC_TAG);
+        if (documentationTag != null) {
+            String documentation = documentationTag.getValue();
+            if (documentation != null) {
+                componentDocs.documentation = cleanupDocumentation(documentation);
+            }
+        }
+
+        // Sitemap component name
+        DocletTag nameTag = javaClass.getTagByName(NAME_TAG);
+        if (nameTag != null)
+            componentDocs.componentName = nameTag.getValue();
+
+        // Deprecated
+        DocletTag deprecatedTag = javaClass.getTagByName("deprecated");
+        if (deprecatedTag != null) {
+            if (deprecatedTag.getValue() != null) {
+                componentDocs.deprecated = limitLength("Yes: " + deprecatedTag.getValue());
+            } else {
+                componentDocs.deprecated = "Yes.";
+            }
+        }
+
+        // Caching
+        if (javaClass.isA(GENERATOR) || javaClass.isA(TRANSFORMER) || javaClass.isA(SERIALIZER)
|| javaClass.isA(READER)) {
+            String cacheInfo;
+            if (javaClass.isA(CACHEABLE)) {
+                cacheInfo = getTagValue(javaClass, CACHING_INFO_TAG, null);
+                if ( cacheInfo != null ) {
+                    cacheInfo = limitLength("Yes - " + cacheInfo);
+                } else {
+                    cacheInfo = "Yes";
+                }
+            } else if (javaClass.isA(DEPRECATED_CACHEABLE)) {
+                cacheInfo = getTagValue(javaClass, CACHING_INFO_TAG, null);
+                if ( cacheInfo != null ) {
+                    cacheInfo = limitLength("Yes (2.0 Caching) - " + cacheInfo);
+                } else {
+                    cacheInfo = "Yes (2.0 Caching)";
+                }
+            } else {
+                cacheInfo = "No";
+            }
+            componentDocs.cacheInfo = cacheInfo;
+        }
+
+        return componentDocs;
+    }
+
+    private String getTagValue(JavaClass javaClass, String tagName, String defaultValue)
{
+        final DocletTag tag = javaClass.getTagByName( tagName );
+        if (tag != null) {
+            return tag.getValue();
+        }
+        return defaultValue;
+    }
+
+    private String limitLength(String value) {
+        if (value.length() > 254)
+            return value.substring(0, 254);
+        else
+            return value;
+    }
+
+    private String cleanupDocumentation(String documentation) throws Exception {
+        // <code> tag is often used but not handled by Daisy, translate it to <tt>
+        documentation = documentation.replaceAll("<code>", "<tt>");
+        documentation = documentation.replaceAll("</code>", "</tt>");
+
+        // make it into a complete HTML doc
+        documentation = "<html><body>" + documentation + "</body></html>";
+
+        // pull it through a HTMLCleaner
+        return htmlCleanerTemplate.newHtmlCleaner().cleanToString(documentation);
+    }
+
+    private void setupHtmlCleanerTemplate() throws Exception {
+        InputStream is = null;
+        try {
+            is = getClass().getClassLoader().getResourceAsStream("org/apache/cocoon/documentation/daisy/htmlcleaner.xml");
+            htmlCleanerTemplate = new HtmlCleanerFactory().buildTemplate(new InputSource(is));
+        } finally {
+            if (is != null)
+                is.close();
+        }
+    }
+
+    private void setupDaisyRepositoryClient(String url, String username, String password)
throws Exception {
+        RepositoryManager repositoryManager = new RemoteRepositoryManager(url, new Credentials(username,
password));
+        this.daisyRepository = repositoryManager.getRepository(new Credentials(username,
password));
+    }
+
+    /**
+     * Gets the Daisy document for a certain component, based on a field containing
+     * the fully qualified class name. Returns null if there is no such document, throws
+     * an exception if there are multiple such documents.
+     */
+    private Document getDaisyDoc(ComponentDocs docs) throws Exception {
+        String query = "select id where documentType = " + QueryHelper.formatString(DAISY_DOCTYPE)
+                + " and InCollection(" + QueryHelper.formatString(daisyCollection)
+                + ") and $JavaClassName = " + QueryHelper.formatString(docs.className);
+        SearchResultDocument.SearchResult.Rows.Row[] rows = daisyRepository.getQueryManager().performQuery(query,
Locale.US).getSearchResult().getRows().getRowArray();
+        if (rows.length == 0) {
+            return null;
+        } else if (rows.length > 1) {
+            throw new Exception("There are multiple documents in Daisy for the class " +
docs.className + ". Please correct this first.");
+        } else {
+            return daisyRepository.getDocument(rows[0].getDocumentId(), rows[0].getBranchId(),
rows[0].getLanguageId(), true);
+        }
+    }
+
+    /**
+     * Gets a {@link ComponentDocs} instance from a Daisy document.
+     */
+    private ComponentDocs getComponentDocs(Document daisyDoc) throws Exception {
+        ComponentDocs docs = new ComponentDocs();
+
+        if (daisyDoc.hasField(DAISY_BLOCK_FIELD))
+            docs.blockName = (String)daisyDoc.getField(DAISY_BLOCK_FIELD).getValue();
+
+        if (daisyDoc.hasField(DAISY_CACHEABLE_FIELD))
+            docs.cacheInfo = (String)daisyDoc.getField(DAISY_CACHEABLE_FIELD).getValue();
+
+        if (daisyDoc.hasField(DAISY_CLASSNAME_FIELD))
+            docs.className = (String)daisyDoc.getField(DAISY_CLASSNAME_FIELD).getValue();
+
+        if (daisyDoc.hasField(DAISY_COMPONENT_NAME_FIELD))
+            docs.componentName = (String)daisyDoc.getField(DAISY_COMPONENT_NAME_FIELD).getValue();
+
+        if (daisyDoc.hasField(DAISY_COMPONENT_TYPE_FIELD))
+            docs.componentType = (String)daisyDoc.getField(DAISY_COMPONENT_TYPE_FIELD).getValue();
+
+        if (daisyDoc.hasField(DAISY_DEPRECATED_FIELD))
+            docs.deprecated = (String)daisyDoc.getField(DAISY_DEPRECATED_FIELD).getValue();
+
+        if (daisyDoc.hasPart(DAISY_SHORTDESCR_PART))
+            docs.documentation = new String(daisyDoc.getPart(DAISY_SHORTDESCR_PART).getData(),
"UTF-8");
+
+        return docs;
+    }
+
+    private void updateDocument(Document daisyDoc, ComponentDocs docs) throws Exception {
+        updateField(daisyDoc, DAISY_BLOCK_FIELD, docs.blockName);
+        updateField(daisyDoc, DAISY_CACHEABLE_FIELD, docs.cacheInfo);
+        updateField(daisyDoc, DAISY_CLASSNAME_FIELD, docs.className);
+        updateField(daisyDoc, DAISY_COMPONENT_NAME_FIELD, docs.componentName);
+        updateField(daisyDoc, DAISY_COMPONENT_TYPE_FIELD, docs.componentType);
+        updateField(daisyDoc, DAISY_DEPRECATED_FIELD, docs.deprecated);
+
+        if (docs.documentation != null) {
+            boolean setPart = false;
+            if (daisyDoc.hasPart(DAISY_SHORTDESCR_PART)) {
+                String oldDescr = new String(daisyDoc.getPart(DAISY_SHORTDESCR_PART).getData(),
"UTF-8");
+                // Note: for parts we need to check ourselves if the content has not changed
+                //  (in contrasts to fields, for which Daisy does the comparison itself)
+                if (!oldDescr.equals(docs.documentation)) {
+                    setPart = true;
+                }
+            } else {
+                setPart = true;
+            }
+            if (setPart)
+                daisyDoc.setPart(DAISY_SHORTDESCR_PART, "text/xml", docs.documentation.getBytes("UTF-8"));
+        } else if (daisyDoc.hasPart(DAISY_SHORTDESCR_PART)) {
+            daisyDoc.deletePart(DAISY_SHORTDESCR_PART);
+        }
+
+        if (!simulate)
+            daisyDoc.save();
+    }
+
+    private void createDocument(ComponentDocs docs, String name) throws Exception {
+        Document daisyDoc = daisyRepository.createDocument(name, DAISY_DOCTYPE);
+        daisyDoc.addToCollection(daisyRepository.getCollectionManager().getCollection(daisyCollection,
false));
+        updateDocument(daisyDoc, docs);
+    }
+
+    private void updateField(Document daisyDoc, String fieldName, String value) throws Exception
{
+        if (value != null)
+            daisyDoc.setField(fieldName, value);
+        else if (daisyDoc.hasField(fieldName))
+            daisyDoc.deleteField(fieldName);
+    }
+
+    public static String prompt(String message) throws Exception {
+        System.out.println(message);
+        System.out.flush();
+        String input = null;
+        while (input == null || input.trim().equals("")) {
+            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+            try {
+                input = in.readLine();
+            } catch (IOException e) {
+                throw new Exception("Error reading input from console.", e);
+            }
+        }
+        return input;
+    }
+}

Propchange: cocoon/whiteboard/sitemaptags2daisy/src/main/java/org/apache/cocoon/documentation/daisy/SitemapTagsToDaisy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/sitemaptags2daisy/src/main/resources/org/apache/cocoon/documentation/daisy/htmlcleaner.xml
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/sitemaptags2daisy/src/main/resources/org/apache/cocoon/documentation/daisy/htmlcleaner.xml?rev=386834&view=auto
==============================================================================
--- cocoon/whiteboard/sitemaptags2daisy/src/main/resources/org/apache/cocoon/documentation/daisy/htmlcleaner.xml
(added)
+++ cocoon/whiteboard/sitemaptags2daisy/src/main/resources/org/apache/cocoon/documentation/daisy/htmlcleaner.xml
Sat Mar 18 01:52:16 2006
@@ -0,0 +1,185 @@
+<!-- This is the default htmlcleaner.xml from the Daisy Wiki (1.5-almost-M1). -->
+<!--
+  Copyright 2004 Outerthought bvba and Schaubroeck nv
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<htmlcleaner>
+  <cleanup>
+    <!-- Span elements will only be retained if they have one of the classes listed belowed.
-->
+    <allowed-span-classes>
+      <class>indexentry</class>
+      <class>footnote</class>
+      <class>crossreference</class>
+    </allowed-span-classes>
+
+    <!-- Div elements will only be retained if they have one of the classes listed belowed.
-->
+    <allowed-div-classes>
+    </allowed-div-classes>
+
+    <!-- The class attribute of p elements will only be retained if they have one of the
classes listed belowed. -->
+    <allowed-para-classes>
+      <class>note</class>
+      <class>warn</class>
+      <class>fixme</class>
+    </allowed-para-classes>
+
+    <!-- The class attribute of pre elements will only be retained if they have one of
the classes listed belowed. -->
+    <allowed-pre-classes>
+      <class>query</class>
+      <class>include</class>
+      <class>query-and-include</class>
+    </allowed-pre-classes>
+
+    <img-alternate-src-attr name="title"/>
+
+    <!-- Lists the allowed elements and their allowed attributes.
+
+         For the correct worker of the cleaner, some elements cannot be removed,
+         usch as html, body, p, some others...
+     -->
+    <allowed-elements>
+      <element name="html"/>
+      <element name="body"/>
+
+      <element name="div">
+        <attribute name="class"/>
+      </element>
+      <element name="span">
+        <attribute name="class"/>
+      </element>
+
+      <element name="p">
+        <attribute name="align"/>
+        <attribute name="class"/>
+        <attribute name="id"/>
+      </element>
+      <element name="br"/>
+      <element name="pre">
+        <attribute name="class"/>
+        <attribute name="id"/>
+      </element>
+
+      <element name="blockquote">
+        <attribute name="id"/>
+      </element>
+
+      <!-- titles -->
+      <element name="h1">
+        <attribute name="id"/>
+      </element>
+      <element name="h2">
+        <attribute name="id"/>
+      </element>
+      <element name="h3">
+        <attribute name="id"/>
+      </element>
+      <element name="h4">
+        <attribute name="id"/>
+      </element>
+      <element name="h5">
+        <attribute name="id"/>
+      </element>
+
+      <!-- linking -->
+      <element name="a">
+        <attribute name="href"/>
+      </element>
+
+      <!-- inline styles -->
+      <element name="strong"/>
+      <element name="em"/>
+      <element name="sup"/>
+      <element name="sub"/>
+      <element name="tt"/>
+      <element name="del"/>
+
+      <!-- lists -->
+      <element name="ul">
+        <attribute name="id"/>
+      </element>
+      <element name="ol">
+        <attribute name="id"/>
+      </element>
+      <element name="li">
+        <attribute name="id"/>
+      </element>
+
+      <element name="img">
+        <attribute name="src"/>
+        <attribute name="align"/>
+        <attribute name="id"/>
+        <attribute name="width"/>
+        <attribute name="height"/>
+        <attribute name="print-width"/>
+        <attribute name="print-height"/>
+        <attribute name="daisy-caption"/>
+        <attribute name="daisy-image-type"/>
+      </element>
+
+      <!-- tables -->
+      <element name="table">
+        <attribute name="class"/>
+        <attribute name="id"/>
+        <attribute name="width"/>
+        <attribute name="column-widths"/>
+        <attribute name="print-width"/>
+        <attribute name="print-column-widths"/>
+        <attribute name="daisy-caption"/>
+        <attribute name="daisy-table-type"/>
+        <attribute name="align"/>
+      </element>
+      <element name="tbody"/>
+      <element name="tr"/>
+      <element name="td">
+        <attribute name="colspan"/>
+        <attribute name="rowspan"/>
+        <attribute name="valign"/>
+      </element>
+      <element name="th">
+        <attribute name="colspan"/>
+        <attribute name="rowspan"/>
+        <attribute name="valign"/>
+      </element>
+    </allowed-elements>
+  </cleanup>
+
+  <serialization>
+    <linewidth value="80"/>
+    <elements>
+      <!-- Note: to avoid unexpected results, mention all block-type tags here,
+           and NO inline tags. -->
+      <element name="html" afterOpen="1" beforeClose="1"/>
+      <element name="body" afterOpen="1" beforeClose="1"/>
+      <element name="p" beforeOpen="1" afterClose="1"/>
+      <element name="blockquote" beforeOpen="1" afterClose="1"/>
+      <element name="h1" beforeOpen="1" afterClose="1"/>
+      <element name="h2" beforeOpen="1" afterClose="1"/>
+      <element name="h3" beforeOpen="1" afterClose="1"/>
+      <element name="h4" beforeOpen="1" afterClose="1"/>
+      <element name="h5" beforeOpen="1" afterClose="1"/>
+      <element name="pre" beforeOpen="1" afterClose="1"/>
+      <element name="div" beforeOpen="1" afterClose="1"/>
+      <element name="ul" beforeOpen="1" beforeClose="1" afterClose="1"/>
+      <element name="ol" beforeOpen="1" beforeClose="1" afterClose="1"/>
+      <element name="li" beforeOpen="1"/>
+      <element name="table" beforeOpen="1" beforeClose="1" afterClose="1"/>
+      <element name="tbody" beforeOpen="1" beforeClose="1"/>
+      <element name="tr" beforeOpen="1" beforeClose="1"/>
+      <element name="td" beforeOpen="1"/>
+      <element name="th" beforeOpen="1"/>
+      <element name="br" afterClose="1"/>
+    </elements>
+  </serialization>
+
+</htmlcleaner>
\ No newline at end of file

Propchange: cocoon/whiteboard/sitemaptags2daisy/src/main/resources/org/apache/cocoon/documentation/daisy/htmlcleaner.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message