sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1591678 - in /sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal: doclet/Doclet.java taglet/Include.java taglet/InlineTaglet.java taglet/Preformat.java taglet/SourceRepositoryURL.java
Date Thu, 01 May 2014 15:18:26 GMT
Author: desruisseaux
Date: Thu May  1 15:18:25 2014
New Revision: 1591678

URL: http://svn.apache.org/r1591678
Log:
Added an @include taglet for allowing us to reference MathML formulas in an external file.
Note that the Javadoc team in OpenJDK is also considered to add an @include javadoc tag,
but we do not know if and when this may happen. This commit allow us to get this functionality
in the mean time. This is needed in order to workaround the javadoc tools in JDK 8 which does
not accept unknown HTML tags.

Added:
    sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/Include.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java
    sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/InlineTaglet.java
    sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/Preformat.java
    sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/SourceRepositoryURL.java

Modified: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java?rev=1591678&r1=1591677&r2=1591678&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java
[UTF-8] Thu May  1 15:18:25 2014
@@ -33,7 +33,7 @@ import com.sun.tools.doclets.formats.htm
  * A doclet which delegates the work to the standard doclet, except for the {@code -stylesheet}
option.
  * Rather than overwriting the standard stylesheet with the given one, this keep both the
standard and
  * the specified stylesheets as separated files. The standard stylesheet will be renamed
{@code standard.css}.
- * The stylesheet provided by the user shall contains an import stantement for the standard
stylesheet.
+ * The stylesheet provided by the user shall contains an import statement for the standard
stylesheet.
  *
  * <p>This class presumes that all CSS files are encoded in UTF-8.</p>
  *

Added: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/Include.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/Include.java?rev=1591678&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/Include.java
(added)
+++ sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/Include.java
[UTF-8] Thu May  1 15:18:25 2014
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sis.internal.taglet;
+
+import java.io.*;
+import java.util.Map;
+import com.sun.javadoc.Tag;
+import com.sun.javadoc.SourcePosition;
+import com.sun.tools.doclets.Taglet;
+
+
+/**
+ * The <code>@include</code> tag for inserting a HTML fragment defined in an
external file.
+ * This tag is used mostly for formulas written in MathML. Those formulas are provided in
+ * separated files for easier edition and for avoiding errors with compilers that verify
the
+ * HTML tags (e.g. JDK 8 javac). Fragment of the external files are inserted in the Javadoc
+ * by the following tag:
+ *
+ * <blockquote><pre>{@include formulas.html#<var>title</var>}</pre></blockquote>
+ *
+ * where <var>title</var> is the text inside <code>&lt;h2&gt;…&lt;/h2&gt;</code>
elements
+ * just before the parts to copy in the javadoc.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+public final class Include extends InlineTaglet {
+    /**
+     * The beginning and the end of the anchor texts. Must be on the same line.
+     */
+    private static final String ANCHOR_START = "<h2>", ANCHOR_END = "</h2>";
+
+    /**
+     * End of document.
+     */
+    private static final String DOCUMENT_END = "</body>";
+
+    /**
+     * Register this taglet.
+     *
+     * @param tagletMap the map to register this tag to.
+     */
+    public static void register(final Map<String,Taglet> tagletMap) {
+       final Include tag = new Include();
+       tagletMap.put(tag.getName(), tag);
+    }
+
+    /**
+     * Constructs a default <code>@include</code> taglet.
+     */
+    private Include() {
+        super();
+    }
+
+    /**
+     * Returns the name of this custom tag.
+     *
+     * @return The tag name.
+     */
+    @Override
+    public String getName() {
+        return "include";
+    }
+
+    /**
+     * Given the <code>Tag</code> representation of this custom tag, return its
string representation.
+     *
+     * @param tag The tag to format.
+     * @return A string representation of the given tag.
+     */
+    @Override
+    public String toString(final Tag tag) {
+        final SourcePosition position = tag.position();
+        final String reference = tag.text();
+        final int sep = reference.indexOf('#');
+        if (sep < 0) {
+            printWarning(position, "@include expected a reference like \"filename#anchor\"
but got \"" + reference + "\".");
+            return reference;
+        }
+        File file = position.file();
+        file = new File(file.getParentFile(), reference.substring(0, sep));
+        final String anchor = reference.substring(sep + 1);
+        final StringBuilder buffer = new StringBuilder();
+        try (final BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),
"UTF-8"))) {
+            /*
+             * Search the anchor.
+             */
+            String line;
+            int start, end;
+            do if ((line = in.readLine()) == null) {
+                printWarning(position, "Header \"" + anchor + "\" not found in file " + file);
+                return reference;
+            }
+            while ((start = line.indexOf(ANCHOR_START)) < 0 ||
+                     (end = line.lastIndexOf(ANCHOR_END)) < start ||
+                     !line.substring(start + ANCHOR_START.length(), end).trim().equals(anchor));
+            /*
+             * At this point, the anchor has been found. Now copy everything up to the next
anchor,
+             * or to the </body> HTML tag.
+             */
+            while (true) {
+                line = in.readLine();
+                if (line == null) {
+                    printWarning(position, "Unexpected end of file in " + file);
+                    return reference;
+                }
+                start = line.indexOf(ANCHOR_START);
+                if (start >= 0 && line.lastIndexOf(ANCHOR_END) >= start) {
+                    break; // Found the next section - stop this one.
+                }
+                if (line.contains(DOCUMENT_END)) {
+                    break;
+                }
+                buffer.append(line).append('\n');
+            }
+        } catch (IOException e) {
+            printError(position, "Error reading " + file + ":\n" + e);
+        }
+        return buffer.toString();
+    }
+}

Propchange: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/Include.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/Include.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/InlineTaglet.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/InlineTaglet.java?rev=1591678&r1=1591677&r2=1591678&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/InlineTaglet.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/InlineTaglet.java
[UTF-8] Thu May  1 15:18:25 2014
@@ -17,6 +17,8 @@
 package org.apache.sis.internal.taglet;
 
 import com.sun.javadoc.Tag;
+import com.sun.javadoc.RootDoc;
+import com.sun.javadoc.SourcePosition;
 import com.sun.tools.doclets.Taglet;
 import com.sun.tools.doclets.internal.toolkit.Configuration;
 import com.sun.tools.doclets.formats.html.ConfigurationImpl;
@@ -42,7 +44,7 @@ abstract class InlineTaglet implements T
     /**
      * Returns the doclet configuration.
      */
-    static synchronized Configuration getConfiguration() {
+    private static synchronized Configuration getConfiguration() {
         if (configuration == null) {
             configuration = new ConfigurationImpl();
         }
@@ -142,4 +144,28 @@ abstract class InlineTaglet implements T
         }
         return buffer.toString();
     }
+
+    /**
+     * Prints a warning message.
+     */
+    static void printWarning(final SourcePosition position, final String message) {
+        final RootDoc root = getConfiguration().root;
+        if (root != null) {
+            root.printWarning(position, message);
+        } else {
+            System.err.println(message);
+        }
+    }
+
+    /**
+     * Prints an error message.
+     */
+    static void printError(final SourcePosition position, final String message) {
+        final RootDoc root = getConfiguration().root;
+        if (root != null) {
+            root.printError(position, message);
+        } else {
+            System.err.println(message);
+        }
+    }
 }

Modified: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/Preformat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/Preformat.java?rev=1591678&r1=1591677&r2=1591678&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/Preformat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/Preformat.java
[UTF-8] Thu May  1 15:18:25 2014
@@ -19,7 +19,6 @@ package org.apache.sis.internal.taglet;
 import java.util.*;
 import com.sun.javadoc.Tag;
 import com.sun.tools.doclets.Taglet;
-import com.sun.tools.doclets.formats.html.ConfigurationImpl;
 
 
 /**
@@ -118,7 +117,7 @@ public final class Preformat extends Inl
         try {
             style = Style.valueOf(format);
         } catch (IllegalArgumentException e) {
-            getConfiguration().root.printWarning(tag.position(), "Unknown format: " + format);
+            printWarning(tag.position(), "Unknown format: " + format);
             style = Style.text;
         }
         /*

Modified: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/SourceRepositoryURL.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/SourceRepositoryURL.java?rev=1591678&r1=1591677&r2=1591678&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/SourceRepositoryURL.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/taglet/SourceRepositoryURL.java
[UTF-8] Thu May  1 15:18:25 2014
@@ -19,7 +19,6 @@ package org.apache.sis.internal.taglet;
 import java.util.Map;
 import com.sun.javadoc.Tag;
 import com.sun.tools.doclets.Taglet;
-import com.sun.tools.doclets.formats.html.ConfigurationImpl;
 
 
 /**
@@ -89,7 +88,7 @@ public final class SourceRepositoryURL e
                 break;
             }
             default: {
-                getConfiguration().root.printWarning(tag.position(), "Unknown keyword: "
+ keyword);
+                printWarning(tag.position(), "Unknown keyword: " + keyword);
                 break;
             }
         }



Mime
View raw message