You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2012/10/30 15:56:44 UTC

svn commit: r1403727 - in /myfaces/extensions/scripting/trunk: ./ extscript-doccompiler/ extscript-doccompiler/src/ extscript-doccompiler/src/main/ extscript-doccompiler/src/main/java/ extscript-doccompiler/src/main/java/org/ extscript-doccompiler/src/...

Author: werpu
Date: Tue Oct 30 14:56:43 2012
New Revision: 1403727

URL: http://svn.apache.org/viewvc?rev=1403727&view=rev
Log:
EXTSCRIPT-179 adding the compiler

Added:
    myfaces/extensions/scripting/trunk/extscript-doccompiler/
    myfaces/extensions/scripting/trunk/extscript-doccompiler/pom.xml
    myfaces/extensions/scripting/trunk/extscript-doccompiler/src/
    myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/
    myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/java/
    myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/java/org/
    myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/java/org/apache/
    myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/java/org/apache/myfaces/
    myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/java/org/apache/myfaces/extension/
    myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/java/org/apache/myfaces/extension/scripting/
    myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/java/org/apache/myfaces/extension/scripting/doccompiler/
    myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/java/org/apache/myfaces/extension/scripting/doccompiler/XSLTDocCompiler.java
    myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/resources/
    myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/resources/xdocconversion.xslt
Modified:
    myfaces/extensions/scripting/trunk/pom.xml

Added: myfaces/extensions/scripting/trunk/extscript-doccompiler/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-doccompiler/pom.xml?rev=1403727&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-doccompiler/pom.xml (added)
+++ myfaces/extensions/scripting/trunk/extscript-doccompiler/pom.xml Tue Oct 30 14:56:43 2012
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>extscript-doccompiler</artifactId>
+    <packaging>pom</packaging>
+    <name>MyFaces Extension Scripting Doccompiler</name>
+    <version>1.0.5-SNAPSHOT</version>
+
+    <description>
+         MyFaces Extension Scripting Core Meta Project
+    </description>
+
+    <parent>
+        <groupId>org.apache.myfaces.extensions.scripting</groupId>
+        <artifactId>extscript-root</artifactId>
+        <version>1.0.5-SNAPSHOT</version>
+    </parent>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/myfaces/extensions/scripting/tags/extscript-root-1.0.4/extscript-core-root</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/myfaces/extensions/scripting/tags/extscript-root-1.0.4/extscript-core-root</developerConnection>
+        <url>http://svn.apache.org/viewvc/myfaces/extensions/scripting/tags/extscript-root-1.0.4/extscript-core-root</url>
+    </scm>
+
+
+</project>

Added: myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/java/org/apache/myfaces/extension/scripting/doccompiler/XSLTDocCompiler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/java/org/apache/myfaces/extension/scripting/doccompiler/XSLTDocCompiler.java?rev=1403727&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/java/org/apache/myfaces/extension/scripting/doccompiler/XSLTDocCompiler.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/java/org/apache/myfaces/extension/scripting/doccompiler/XSLTDocCompiler.java Tue Oct 30 14:56:43 2012
@@ -0,0 +1,145 @@
+/*
+ * 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.myfaces.extension.scripting.doccompiler;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.nio.charset.Charset;
+import java.util.Iterator;
+
+/**
+ * A simple cross compile solution for the xslt mdtext conversion
+ * for the apache cms. It uses xslt as transformation language
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class XSLTDocCompiler
+{
+    static final String docRootPath = "../../../src/site/xdoc";
+    static final String strTargetDir = "../../../src/site/mdtext";
+    static final String strXsltFile = "../../src/main/resources/xdocconversion.xslt";
+
+    static String currentPath = null;
+
+    static
+    {
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+        try
+        {
+            currentPath = URLDecoder.decode(loader.getResource("./").getPath(),
+                    Charset.defaultCharset().toString());
+        }
+        catch (UnsupportedEncodingException e)
+        {
+
+        }
+    }
+
+    public static void main(String... argv)
+    {
+
+        String[] fileEndings = {"xml"};
+
+        Iterator fileIter = FileUtils.iterateFiles(new File(FilenameUtils.normalize(currentPath + File.separator + docRootPath)), fileEndings, true);
+        while (fileIter.hasNext())
+        {
+            File toProcess = (File) fileIter.next();
+            transformFile(toProcess);
+        }
+
+    }
+
+    static String formatter(String in)
+    {
+        StringBuilder target = new StringBuilder();
+        String[] lines = in.split("\n+");
+        for (String line : lines)
+        {
+            //no inline xml/html formatting
+            if (line.matches("\\s+[^<#]+"))
+            {
+                line = line.replaceAll("\\s+", " ");
+            }
+            if (line.matches("\\s+#.+"))
+            {
+                line = line.replaceAll("\\s+", "");
+            }
+            target.append(line);
+            target.append("\n");
+        }
+        return target.toString();
+    }
+
+    private static void transformFile(File xmlFile)
+    {
+        //File xmlFile = new File(strXmlFile);
+        File xsltFile = new File(FilenameUtils.normalize(currentPath+File.separator+strXsltFile));
+
+        // JAXP liest Daten über die Source-Schnittstelle
+        Source xmlSource = new StreamSource(xmlFile);
+        Source xsltSource = new StreamSource(xsltFile);
+
+        // das Factory-Pattern unterstützt verschiedene XSLT-Prozessoren
+        TransformerFactory transFact =
+                TransformerFactory.newInstance();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+        try
+        {
+            Transformer trans = transFact.newTransformer(xsltSource);
+            trans.transform(xmlSource, new StreamResult(baos));
+            String result = baos.toString("UTF-8");
+
+            String fileName = FilenameUtils.normalize(currentPath+File.separator+strTargetDir + File.separator + xmlFile.getName().split("\\.")[0] + ".mdtext");
+            File target = new File(fileName);
+            FileUtils.deleteQuietly(target);
+            result = formatter(result);
+
+            FileUtils.writeStringToFile(target, result);
+        }
+        catch (TransformerException e)
+        {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+        catch (UnsupportedEncodingException e)
+        {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+        catch (IOException e)
+        {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/resources/xdocconversion.xslt
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/resources/xdocconversion.xslt?rev=1403727&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/resources/xdocconversion.xslt (added)
+++ myfaces/extensions/scripting/trunk/extscript-doccompiler/src/main/resources/xdocconversion.xslt Tue Oct 30 14:56:43 2012
@@ -0,0 +1,61 @@
+<?xml version="1.0" ?>
+<!--
+    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.
+-->
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+	<xsl:template match="section">#<xsl:attribute name="name"></xsl:attribute><xsl:value-of select="@name"/>
+        <xsl:apply-templates/>
+	</xsl:template>
+
+	<xsl:template match="subsection">## <xsl:attribute name="name"/><xsl:value-of select="@name"/>
+        <xsl:apply-templates/>
+	</xsl:template>
+
+    <xsl:template match="subsubsection">## <xsl:attribute name="name"/><xsl:value-of select="@name"/>
+        <xsl:apply-templates/>
+    </xsl:template>
+    <xsl:template match="subsubsubsection">### <xsl:attribute name="name"/><xsl:value-of select="@name"/>
+        <xsl:apply-templates/>
+    </xsl:template>
+    <xsl:template match="ul">
+        <xsl:copy-of select="."/>
+    </xsl:template>
+    <xsl:template match="source">
+<code><xsl:value-of disable-output-escaping="yes" select="." /></code>
+    </xsl:template>
+    <xsl:template match="a">
+        <xsl:attribute name="href"/>
+        [<xsl:value-of disable-output-escaping="yes" select="." />]: <xsl:value-of select="@href"/>
+    </xsl:template>
+    <xsl:template match="table">
+        <xsl:copy-of select="."/>
+    </xsl:template>
+    <xsl:template match="iframe">
+        <xsl:copy-of select="."/>
+    </xsl:template>
+    <xsl:template match="img">
+        <xsl:copy-of select="."/>
+    </xsl:template>
+	<xsl:template match="/">
+		<xsl:apply-templates/>
+	</xsl:template>
+    <xsl:template match="properties"/>
+    <xsl:output encoding="UTF-8" indent="no" omit-xml-declaration="yes"/>
+</xsl:stylesheet>

Modified: myfaces/extensions/scripting/trunk/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/pom.xml?rev=1403727&r1=1403726&r2=1403727&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/pom.xml (original)
+++ myfaces/extensions/scripting/trunk/pom.xml Tue Oct 30 14:56:43 2012
@@ -54,6 +54,7 @@
         <module>extscript-core-root</module>
         <module>extscript-bundles</module>
         <module>extscript-examples</module>
+        <module>extscript-doccompiler</module>
     </modules>
 
     <scm>