sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1705058 - in /sis: branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/book/Assembler.java site/trunk/book/en/body.html site/trunk/book/en/introduction.html
Date Thu, 24 Sep 2015 13:55:48 GMT
Author: desruisseaux
Date: Thu Sep 24 13:55:48 2015
New Revision: 1705058

URL: http://svn.apache.org/viewvc?rev=1705058&view=rev
Log:
Minor formatting in HTML output.

Modified:
    sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/book/Assembler.java
    sis/site/trunk/book/en/body.html   (contents, props changed)
    sis/site/trunk/book/en/introduction.html   (contents, props changed)

Modified: sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/book/Assembler.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/book/Assembler.java?rev=1705058&r1=1705057&r2=1705058&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/book/Assembler.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/book/Assembler.java
[UTF-8] Thu Sep 24 13:55:48 2015
@@ -21,12 +21,11 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
@@ -44,12 +43,14 @@ import org.xml.sax.SAXException;
  * This class performs the following processing:
  *
  * <ul>
- *   <li>Comments of the form {@code <!-- file:introduction.html -->} are replaced
by content
- *       of the {@code <body>} element in the given file.</li>
+ *   <li>Replace elements of the form {@code <xi:include href="introduction.html"/>}
by content of the {@code <body>} element
+ *       in the file given by the {@code href} attribute.</li>
  *
- *   <li>{@code <abbr>} elements without {@code title} attribute automatically
get the last title used for that abbreviation.
- *        However this automatic insertion is performed only for the first occurrence of
that abbreviation after a {@code h?}
- *        element.</li>
+ *   <li>Complete {@code <abbr>} elements without {@code title} attribute by
reusing the last title used for the same abbreviation.
+ *       This automatic insertion is performed only for the first occurrence of that abbreviation
after a {@code h?} element.</li>
+ *
+ *   <li>Replace the {@code <!-- TOC -->} comment by a table of content generated
from all {@code <h1>}, {@code <h2>}, etc.
+ *       found in the document.</li>
  * </ul>
  *
  * @author  Martin Desruisseaux (Geomatys)
@@ -58,12 +59,10 @@ import org.xml.sax.SAXException;
  */
 public final class Assembler {
     /**
-     * The prefix used in comments for instructing {@code Assembler} to insert the content
of another file.
-     * This is used in the source HTML file like the following example:
-     *
-     * <pre>{@literal <!-- file:introduction.html -->}</pre>
+     * The line separator to be used in the output file.
+     * We fix it to the Unix style (not the native style of the platform) for more compact
output file.
      */
-    private static final String INCLUDE_PREFIX = "file:";
+    private static final String LINE_SEPARATOR = "\n";
 
     /**
      * The directory of all input files to process.
@@ -107,27 +106,87 @@ public final class Assembler {
      * @throws SAXException if an error occurred while parsing the XML.
      */
     public Assembler(final File input) throws ParserConfigurationException, IOException,
SAXException {
+        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        // No setXIncludeAware(true) -  we will handle <xi:include> elements ourself.
+        factory.setNamespaceAware(true);
         inputDirectory = input.getParentFile();
-        builder        = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+        builder        = factory.newDocumentBuilder();
         document       = load(input.getName());
         tableOfContent = document.createElement("ul");
         tableOfContent.setAttribute("class", "toc");
+        /*
+         * Remove the "http://www.w3.org/2001/XInclude" namespace since we
+         * should have no <xi:include> elements left in the output file.
+         */
+        ((Element) document.getElementsByTagName("html").item(0)).removeAttribute("xmlns:xi");
+        /*
+         * Replace the License comment by a shorter one followed by the
+         * "This is an automatically generated file"> notice.
+         */
+        for (final Node node : toArray(document.getDocumentElement().getParentNode().getChildNodes()))
{
+            if (node.getNodeType() == Node.COMMENT_NODE) {
+                node.setNodeValue(LINE_SEPARATOR + LINE_SEPARATOR +
+                        "  Licensed to the Apache Software Foundation (ASF)" + LINE_SEPARATOR
+
+                        LINE_SEPARATOR +
+                        "      http://www.apache.org/licenses/LICENSE-2.0" + LINE_SEPARATOR
+
+                        LINE_SEPARATOR +
+                        "  This is an automatically generated file. DO NOT EDIT." + LINE_SEPARATOR
+
+                        "  See the files in the ../../../book/ directory instead." + LINE_SEPARATOR
+
+                        LINE_SEPARATOR);
+                break;
+            }
+        }
     }
 
     /**
      * Loads the XML document from the given file in the same directory than the input file
given to the constructor.
      */
     private Document load(final String filename) throws IOException, SAXException {
-        final Document include;
-        try (final InputStream in = new FileInputStream(new File(inputDirectory, filename)))
{
-            include = builder.parse(in);
-        }
+        final Document include = builder.parse(new File(inputDirectory, filename));
         builder.reset();
+        removeIndentation(include.getDocumentElement());
         return include;
     }
 
     /**
+     * Removes the indentation at the beginning of lines in the given node and all child
nodes.
+     * This can reduce the file length by as much as 20%. Note that the indentation was broken
+     * anyway after the treatment of {@code <xi:include>}, because included file does
not use
+     * the right amount of spaces for the location where it is introduced.
+     */
+    private void removeIndentation(final Node node) {
+        if (node.getNodeType() == Node.TEXT_NODE) {
+            boolean       newLine = false;
+            StringBuilder buffer  = null;
+            CharSequence  text    = node.getTextContent();
+            for (int i=0; i<text.length(); i++) {
+                switch (text.charAt(i)) {
+                    case '\r': break;  // Delete all occurrences of '\r'.
+                    case '\n': newLine = true;  continue;
+                    default  : newLine = false; continue;
+                    case ' ' : if (newLine) break; else continue;
+                }
+                if (buffer == null) {
+                    text = buffer = new StringBuilder(text);
+                }
+                buffer.deleteCharAt(i--);
+            }
+            if (buffer != null) {
+                node.setNodeValue(buffer.toString());
+            }
+            return;
+        }
+        final NodeList children = node.getChildNodes();
+        final int length = children.getLength();
+        for (int i=0; i<length; i++) {
+            removeIndentation(children.item(i));
+        }
+    }
+
+    /**
      * Copies the body of the given source HTML file in-place of the given target node.
+     * This method is doing the work of {@code <xi:include>} element. We do this work
ourself instead than relying on
+     * {@link DocumentBuilder} build-in support mostly because we have been unable to get
the {@code xpointer} to work.
      *
      * @param filename  the source XML file in the same directory than the input file given
to the constructor.
      * @param toReplace the target XML node to be replaced by the content of the given file.
@@ -187,17 +246,18 @@ public final class Assembler {
         switch (node.getNodeType()) {
             case Node.COMMENT_NODE: {
                 final String text = node.getNodeValue().trim();
-                if (text.startsWith(INCLUDE_PREFIX)) {
-                    node = replaceByBody(text.substring(INCLUDE_PREFIX.length()), node);
-                } else if (text.equals("TOC")) {
+                if ("TOC".equals(text)) {
                     node.getParentNode().replaceChild(tableOfContent, node);
-                    return;
                 }
-                break;
+                return;
             }
             case Node.ELEMENT_NODE: {
                 final String name = node.getNodeName();
                 switch (name) {
+                    case "xi:include": {
+                        node = replaceByBody(((Element) node).getAttribute("href"), node);
+                        break;
+                    }
                     case "abbr": {
                         processAbbreviation((Element) node);
                         break;
@@ -216,10 +276,8 @@ public final class Assembler {
                 break;
             }
         }
-        final NodeList nodes = node.getChildNodes();
-        final int length = nodes.getLength();
-        for (int i=0; i<length; i++) {
-            process(nodes.item(i));
+        for (final Node child : toArray(node.getChildNodes())) {
+            process(child);
         }
     }
 
@@ -250,7 +308,7 @@ public final class Assembler {
             }
             node = list;
         }
-        node.appendChild(document.createTextNode("\n"));
+        node.appendChild(document.createTextNode(LINE_SEPARATOR));
         node.appendChild(item);
     }
 
@@ -264,8 +322,13 @@ public final class Assembler {
      */
     public void run(final File output) throws IOException, SAXException, TransformerException
{
         process(document.getDocumentElement());
-        tableOfContent.appendChild(document.createTextNode("\n"));
+        tableOfContent.appendChild(document.createTextNode(LINE_SEPARATOR));
         final Transformer transformer = TransformerFactory.newInstance().newTransformer();
+        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
+        transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "about:legacy-compat");
+        transformer.setOutputProperty(OutputKeys.INDENT, "no");
         transformer.transform(new DOMSource(document), new StreamResult(output));
     }
 }

Modified: sis/site/trunk/book/en/body.html
URL: http://svn.apache.org/viewvc/sis/site/trunk/book/en/body.html?rev=1705058&r1=1705057&r2=1705058&view=diff
==============================================================================
--- sis/site/trunk/book/en/body.html (original)
+++ sis/site/trunk/book/en/body.html Thu Sep 24 13:55:48 2015
@@ -20,7 +20,10 @@
   under the License.
 -->
 
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<html xmlns    = "http://www.w3.org/1999/xhtml"
+      xmlns:xi = "http://www.w3.org/2001/XInclude"
+      xml:lang = "en">
+
   <head>
     <title>Introduction to Apache SIS</title>
     <link rel="stylesheet" type="text/css" href="../../content/book/book.css"/>
@@ -39,7 +42,7 @@
     </nav>
 
     <main>
-      <!-- file:introduction.html -->
+      <xi:include href="introduction.html"/>
     </main>
   </body>
 </html>

Propchange: sis/site/trunk/book/en/body.html
------------------------------------------------------------------------------
--- svn:mime-type (original)
+++ svn:mime-type Thu Sep 24 13:55:48 2015
@@ -1 +1 @@
-text/html
+text/xml

Modified: sis/site/trunk/book/en/introduction.html
URL: http://svn.apache.org/viewvc/sis/site/trunk/book/en/introduction.html?rev=1705058&r1=1705057&r2=1705058&view=diff
==============================================================================
--- sis/site/trunk/book/en/introduction.html [UTF-8] (original)
+++ sis/site/trunk/book/en/introduction.html [iso-8859-1] Thu Sep 24 13:55:48 2015
@@ -26,7 +26,9 @@
     <link rel="stylesheet" type="text/css" href="../../content/book/book.css"/>
   </head>
   <body>
-    <h1 id="Foreword">Foreward</h1>
+    <header>
+      <h1 id="Foreword">Foreward</h1>
+    </header>
     <p>
       A geospatial information community is a collection of systems or individuals capable
of exchanging their geospatial data
       through the use of common standards, allowing them to communicate with one another.
@@ -51,14 +53,14 @@
       In other words, the <abbr>API</abbr> must come as near as possible to industrial
standards.
     </p><p>
       For example, one task that benefit from a successful standardization is the accessing
of relational databases.
-      The industry has established a common language — the <abbr title="Structured Query
Language">SQL</abbr> standard —
+      The industry has established a common language — the <abbr title="Structured
Query Language">SQL</abbr> standard —
       that the creators of Java have embedded in standard <abbr title="Java DataBase Connectivity">JDBC</abbr>
programming interfaces.
       Today, these interfaces are implemented by many software programs, both free and commercial.
       Like databases, methods of accessing geographic information have been standardized.
-      In this case, however, the efforts have been more recent, and their integration in
software — especially in older programs — is incomplete and not always coherent.
+      In this case, however, the efforts have been more recent, and their integration in
software — especially in older programs — is incomplete and not always coherent.
       At the time of writing, no product to our knowledge has implemented all of the specifications
in their entirety.
       However, there are many implementations that cover a fairly large spectrum.
-      One of these is the Apache <abbr>SIS</abbr>® library that is described
in this document.
+      One of these is the Apache <abbr>SIS</abbr>® library that is described
in this document.
     </p><p>
       Apache <abbr title="Spatial Information System">SIS</abbr> is characterized
by a sustained effort to comply with standards.
       In general, complying with standards demands a greater effort than would be required
for an isolated development,
@@ -179,30 +181,30 @@
     <h3 id="SpecificationTypes">Different Types of Specifications</h3>
     <p>
       <abbr>OGC</abbr> standards are specified in several dozen documents.
-      Each document outlines a service — for example, the transformation of coordinates.
+      Each document outlines a service — for example, the transformation of coordinates.
       The function of each service is described by a collection of object classes and their
interactions.
-      These elements are illustrated by <abbr>UML</abbr> (Unified Modeling Language)
diagrams in specifications called “abstracts”.
+      These elements are illustrated by <abbr>UML</abbr> (Unified Modeling Language)
diagrams in specifications called “abstracts”.
     </p><p>
       <a href="http://www.opengeospatial.org/standards/as">Abstract specifications</a>
do not refer to any specific computer language.
       Their concepts may be applied more or less directly to a programming language, a database
or an <abbr>XML</abbr> schema.
       There is always an element of arbitrariness in the method of applying an abstract specification,
       given that adjustments are often necessary to take into account the constraints or
conventions of the target language.
-      Certain data structures only exist in a few languages — for example, unions that
exist in C/C++ but not in Java.
+      Certain data structures only exist in a few languages — for example, unions that
exist in C/C++ but not in Java.
     </p><p>
       At the turn of the millennium, the abstract specifications were explicitly concretized
in <i>implementation specifications</i>.
-      The term “implementation” is used here in the sense of all types of interfaces
(Java or others) derived from
+      The term “implementation” is used here in the sense of all types of interfaces
(Java or others) derived from
       <abbr title="Unified Modeling Language">UML</abbr> diagrams, and not implementations
in the Java sense.
       Such specifications existed for <abbr title="Structured Query Language">SQL</abbr>,
       <abbr title="Common Object Request Broker Architecture">CORBA</abbr>, <abbr
title="Component Object Model">COM</abbr>, and Java languages.
       As these languages are capable of executing procedures, the specifications of this
period define not only data structures,
       but also operations that apply to these structures.
     </p><p>
-      Thereafter, enthusiasm for “Web 2.0” increased interest for <abbr>XML</abbr>
over other languages.
+      Thereafter, enthusiasm for “Web 2.0” increased interest for <abbr>XML</abbr>
over other languages.
       Older implementation specifications were deprecated,
       and <abbr title="XML Schema Definition">XSD</abbr> schemas became the main
concretization of abstract specifications.
       Even the way abstract specifications are designed has evolved: they are less likely
to define operations, and so what remains is closer to descriptions of database schemas.
       Some operations that were defined in older standards now appear, in another form, in
web service specifications.
-      Finally, the term “implementation specification” has been deprecated, to be subsumed
under the term “<abbr>OGC</abbr> standard.”
+      Finally, the term “implementation specification” has been deprecated, to
be subsumed under the term “<abbr>OGC</abbr> standard.”
       But despite their depreciation, <a href="http://www.opengeospatial.org/standards/retired">old
implementation specifications</a> remain useful to programs in Java, because:
     </p>
     <ul>
@@ -213,7 +215,7 @@
     <p>
       The Apache <abbr>SIS</abbr> project is based on the most recent specifications,
       drawing from the archives of the <abbr>OGC</abbr> to complete certain abstract
standards or make them more usable.
-      Some old definitions are preserved as “convenience methods”, not always bringing
new functionality, but facilitating the practical use of a library.
+      Some old definitions are preserved as “convenience methods”, not always bringing
new functionality, but facilitating the practical use of a library.
     </p><p>
       The following table lists the main norms used by the project.
       Many norms are published both as <abbr>ISO</abbr> standards and as <abbr>OGC</abbr>
standards,

Propchange: sis/site/trunk/book/en/introduction.html
------------------------------------------------------------------------------
--- svn:mime-type (original)
+++ svn:mime-type Thu Sep 24 13:55:48 2015
@@ -1 +1 @@
-text/plain;charset=UTF-8
+text/html



Mime
View raw message