You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2012/04/26 12:38:25 UTC

svn commit: r1330764 - in /ofbiz/trunk/framework/minilang: config/MiniLang.xslt src/org/ofbiz/minilang/MiniLangUtil.java src/org/ofbiz/minilang/SimpleMethod.java

Author: adrianc
Date: Thu Apr 26 10:38:25 2012
New Revision: 1330764

URL: http://svn.apache.org/viewvc?rev=1330764&view=rev
Log:
Added a Mini-language XML style sheet.

Added:
    ofbiz/trunk/framework/minilang/config/MiniLang.xslt   (with props)
Modified:
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangUtil.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java

Added: ofbiz/trunk/framework/minilang/config/MiniLang.xslt
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/config/MiniLang.xslt?rev=1330764&view=auto
==============================================================================
--- ofbiz/trunk/framework/minilang/config/MiniLang.xslt (added)
+++ ofbiz/trunk/framework/minilang/config/MiniLang.xslt Thu Apr 26 10:38:25 2012
@@ -0,0 +1,40 @@
+<?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.
+-->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt" version="1.0">
+    <xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="no" indent="yes" xalan:indent-amount="4" />
+    <xsl:strip-space elements="*" />
+    <xsl:template match="@*|node()">
+        <xsl:copy>
+            <xsl:apply-templates select="@*|node()" />
+        </xsl:copy>
+    </xsl:template>
+    <xsl:template match="/comment()|/simple-methods">
+        <xsl:text>&#xa;</xsl:text>
+        <xsl:copy>
+            <xsl:apply-templates select="@*|node()"/>
+        </xsl:copy>
+    </xsl:template>
+    <xsl:template match="/simple-methods/simple-method">
+        <xsl:text>&#xa;&#xa;    </xsl:text>
+        <xsl:copy>
+            <xsl:apply-templates select="@*|node()"/>
+        </xsl:copy>
+    </xsl:template>
+</xsl:stylesheet>

Propchange: ofbiz/trunk/framework/minilang/config/MiniLang.xslt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/minilang/config/MiniLang.xslt
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/framework/minilang/config/MiniLang.xslt
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangUtil.java?rev=1330764&r1=1330763&r2=1330764&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangUtil.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangUtil.java Thu Apr 26 10:38:25 2012
@@ -18,12 +18,23 @@
  *******************************************************************************/
 package org.ofbiz.minilang;
 
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamSource;
+
+import org.ofbiz.base.location.FlexibleLocation;
+import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.ScriptUtil;
 import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -92,8 +103,7 @@ public final class MiniLangUtil {
     }
 
     public static boolean isDocumentAutoCorrected(Document document) {
-        String autoCorrected = (String) document.getUserData("autoCorrected");
-        return "true".equals(autoCorrected);
+        return "true".equals(document.getUserData("autoCorrected"));
     }
 
     public static void removeInvalidAttributes(Element element, String... validAttributeNames) {
@@ -115,5 +125,44 @@ public final class MiniLangUtil {
         }
     }
 
+    public static void writeMiniLangDocument(URL xmlURL, Document document) {
+        URL styleSheetURL = null;
+        InputStream styleSheetInStream = null;
+        Transformer transformer = null;
+        try {
+            styleSheetURL = FlexibleLocation.resolveLocation("component://minilang/config/MiniLang.xslt");
+            styleSheetInStream = styleSheetURL.openStream();
+            TransformerFactory transformerFactory = TransformerFactory.newInstance();
+            transformer = transformerFactory.newTransformer(new StreamSource(styleSheetInStream));
+        } catch (Exception e) {
+            Debug.logWarning(e, "Error reading minilang/config/MiniLang.xslt: ", module);
+            return;
+        } finally {
+            if (styleSheetInStream != null) {
+                try {
+                    styleSheetInStream.close();
+                } catch (IOException e) {
+                    Debug.logWarning(e, "Error closing minilang/config/MiniLang.xslt: ", module);
+                }
+            }
+        }
+        FileOutputStream fos = null;
+        try {
+            fos = new FileOutputStream(xmlURL.getFile());
+            UtilXml.transformDomDocument(transformer, document, fos);
+            Debug.logInfo("Saved Mini-language file " + xmlURL, module);
+        } catch (Exception e) {
+            Debug.logWarning(e, "Error writing mini-language file " + xmlURL + ": ", module);
+        } finally {
+            if (fos != null) {
+                try {
+                    fos.close();
+                } catch (IOException e) {
+                    Debug.logWarning(e, "Error closing " + xmlURL + ": ", module);
+                }
+            }
+        }
+    }
+
     private MiniLangUtil() {}
 }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java?rev=1330764&r1=1330763&r2=1330764&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java Thu Apr 26 10:38:25 2012
@@ -307,12 +307,7 @@ public class SimpleMethod {
             simpleMethods.put(simpleMethod.getMethodName(), simpleMethod);
         }
         if (MiniLangUtil.isDocumentAutoCorrected(document)) {
-            try {
-                UtilXml.writeXmlDocument(xmlURL.getFile(), document);
-                Debug.logInfo("Saved auto-corrected Mini-language file " + xmlURL, module);
-            } catch (Exception e) {
-                Debug.logWarning(e, "Error writing auto-corrected mini-language file " + xmlURL + ": ", module);
-            }
+            MiniLangUtil.writeMiniLangDocument(xmlURL, document);
         }
         return simpleMethods;
     }