Author: saminda
Date: Wed Jan  2 03:44:54 2008
New Revision: 11759

Log:

1. File upload
2. Improvements to codegeneration


Added:
   trunk/commons/codegen/www/codegen_file_upload.xsl
Modified:
   
trunk/commons/codegen/src/main/java/org/wso2/codegen/service/wsdl2code/WSDL2Code.java
   trunk/commons/codegen/src/main/resources/codegen-options.xml
   trunk/commons/codegen/www/wsdl2code2.xsl

Modified: 
trunk/commons/codegen/src/main/java/org/wso2/codegen/service/wsdl2code/WSDL2Code.java
==============================================================================
--- 
trunk/commons/codegen/src/main/java/org/wso2/codegen/service/wsdl2code/WSDL2Code.java
       (original)
+++ 
trunk/commons/codegen/src/main/java/org/wso2/codegen/service/wsdl2code/WSDL2Code.java
       Wed Jan  2 03:44:54 2008
@@ -15,10 +15,7 @@
  */
 package org.wso2.codegen.service.wsdl2code;
 
-import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.*;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.xpath.AXIOMXPath;
 import org.apache.axis2.AxisFault;
@@ -40,6 +37,7 @@
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamConstants;
 import javax.xml.transform.*;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.transform.stream.StreamResult;
@@ -53,6 +51,8 @@
 
     private static Log log = LogFactory.getLog(WSDL2Code.class);
     private static final String CODEGEN_POM_XSL = "codegen-pom.xsl";
+    //Codegen option file is taken from classpath
+    private static final String CODEGEN_OPTIONS = "codegen-options.xml";
 
     /**
      * User will be able to get the codegen options file
@@ -61,12 +61,16 @@
      * @throws AxisFault throws an AxisFault
      */
     public OMElement getCodegenOptions() throws AxisFault {
-        //Codegen option file is taken from classpath
-        String s1 = "codegen-options.xml";
-        InputStream inStream = getClass().getResourceAsStream(s1);
+        OMElement docEle = loadCodegenOptions();
+        docEle.build();
+        return docEle;
+    }
+
+    private OMElement loadCodegenOptions() throws AxisFault {
+        InputStream inStream = getClass().getResourceAsStream(CODEGEN_OPTIONS);
         if (inStream == null) {
             inStream = Thread.currentThread().getContextClassLoader()
-                    .getResourceAsStream(s1);
+                    .getResourceAsStream(CODEGEN_OPTIONS);
             if (inStream == null) {
                 String s = "Codegen option file is not available";
                 log.error(s);
@@ -81,9 +85,50 @@
             throw AxisFault.makeFault(e);
         }
         StAXOMBuilder builder = new StAXOMBuilder(streamReader);
-        OMElement docEle = builder.getDocumentElement();
-        docEle.build();
-        return docEle;
+        return builder.getDocumentElement();
+    }
+
+    /**
+     * uploadFileValue element will be generated for given codegen option and 
value.
+     *
+     * @param codegenOption      codegen option that need to be fill with
+     * @param codegenOptionValue value
+     * @return OMElement return
+     * @throws AxisFault with be thrown
+     */
+    public OMElement getCodegenOptionsWithValues(String codegenOption, String 
codegenOptionValue)
+            throws AxisFault {
+        OMElement docEle = loadCodegenOptions();
+        try {
+            XPath xp = new AXIOMXPath("/codegen/[EMAIL PROTECTED]'" + 
codegenOption + "']");
+            OMElement nameEle = (OMElement) xp.selectSingleNode(docEle);
+            if (nameEle != null) {
+                OMFactory fac = OMAbstractFactory.getOMFactory();
+                OMElement uploadFileValueEle = fac.createOMElement(new 
QName("uploadFileValue"));
+                nameEle.addChild(uploadFileValueEle);
+                Map fileResourcesMap =
+                    (Map) 
MessageContext.getCurrentMessageContext().getConfigurationContext()
+                            .getProperty(WSO2Constants.FILE_RESOURCE_MAP);
+                if (fileResourcesMap == null) {
+                    String msg = "File resource is not available";
+                    log.error(msg);
+                    throw new AxisFault(msg);
+                }
+                String absFilePath = 
(String)fileResourcesMap.get(codegenOptionValue);
+                if (absFilePath == null) {
+                    String msg = "Uploaded file is not available";
+                    log.error(msg);
+                    throw new AxisFault(msg);
+                }
+                OMText omText = fac.createOMText(absFilePath, 
XMLStreamConstants.CDATA);
+                uploadFileValueEle.addChild(omText);
+            }
+            return nameEle;
+        } catch (JaxenException e) {
+            String msg = "Xpath error has been encounted while looking for the 
argument : " + codegenOption;
+            log.error(msg, e);
+            throw new AxisFault(msg, e);
+        }
     }
 
     /**

Modified: trunk/commons/codegen/src/main/resources/codegen-options.xml
==============================================================================
--- trunk/commons/codegen/src/main/resources/codegen-options.xml        
(original)
+++ trunk/commons/codegen/src/main/resources/codegen-options.xml        Wed Jan 
 2 03:44:54 2008
@@ -1,13 +1,14 @@
 <codegen>
-    <!--<argument uiType="text | option | check | skip " default="true | false 
| custom value">
+    <!--<argument uiType="text | option | check | skip " default="true | false 
| custom value" uploadFile="false | true" readOnly="true | false" 
[name="codegen-short-name"]>
         <name></name>
         <description></description>
         <values>
             <value></value>
         </values>
+        [<uploadFileValue>VALUE-OF-UPLOADED-FILE</uploadFileValue>]
     </argument>-->
 
-    <argument uiType="text">
+    <argument uiType="text" uploadFile="true" name="uri">
         <name>uri</name>
         <description>A url or path to a WSDL</description>
     </argument>

Added: trunk/commons/codegen/www/codegen_file_upload.xsl
==============================================================================
--- (empty file)
+++ trunk/commons/codegen/www/codegen_file_upload.xsl   Wed Jan  2 03:44:54 2008
@@ -0,0 +1,38 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
+    <xsl:template match="codegenFileUpload">
+        <div id="formset">
+            <form method="post" name="codegenFileUpload" action="fileupload/*"
+                  enctype="multipart/form-data" target="globalIFrame">
+                <fieldset>
+                    <legend>Upload file</legend>
+                    <div>
+                        <input type="file" size="40" name="codegenFile"/>
+                    </div>
+                    <div>
+                        <input type="submit" value="Submit">
+                            <xsl:attribute name="onclick">
+                                javascript:
+                                var fileName = 
document.codegenFileUpload.codegenFile.value;
+                                if (fileName == '') {
+                                    wso2.wsf.Util.alertWarning('Please select 
a file to upload');
+                                    return false;
+                                }
+                            </xsl:attribute>
+                        </input>
+                        <input type="button" value="Cancel">
+                            <xsl:attribute name="onclick">
+                                javascript:
+                                var divObj = 
document.getElementById("divCodegenFileupload");
+                                if (divObj) {
+                                    divObj.innerHTML = "";
+                                    divObj.style.display = "none";
+                                }
+                                return false;
+                            </xsl:attribute>
+                        </input>
+                    </div>
+                </fieldset>
+            </form>
+        </div>
+    </xsl:template>
+</xsl:stylesheet>
\ No newline at end of file

Modified: trunk/commons/codegen/www/wsdl2code2.xsl
==============================================================================
--- trunk/commons/codegen/www/wsdl2code2.xsl    (original)
+++ trunk/commons/codegen/www/wsdl2code2.xsl    Wed Jan  2 03:44:54 2008
@@ -84,6 +84,7 @@
     <!-- This will be a table rows-->
     <xsl:template match="argument">
         <xsl:variable name="uiType" select="./@uiType"/>
+        <xsl:variable name="uploadFile" select="./@uploadFile"/>
         <xsl:if test="not($uiType='skip')">
             <xsl:variable name="description" 
select="normalize-space(description)"/>
             <xsl:variable name="name" select="normalize-space(name)"/>
@@ -107,9 +108,25 @@
                             <input>
                                 <xsl:attribute 
name="class">toolsClass</xsl:attribute>
                                 <xsl:attribute name="type">text</xsl:attribute>
-                                <xsl:attribute name="size">40</xsl:attribute>
+                                <xsl:choose>
+                                    <xsl:when test="$uploadFile">
+                                        <xsl:attribute 
name="size">37</xsl:attribute>
+                                    </xsl:when>
+                                    <xsl:otherwise>
+                                        <xsl:attribute 
name="size">40</xsl:attribute>
+                                    </xsl:otherwise>
+                                </xsl:choose>
                                 <xsl:attribute name="id"><xsl:value-of 
select="$name"/>_<xsl:value-of select="$idSuffix"/></xsl:attribute>
                             </input>
+                            <xsl:if test="$uploadFile">
+                                <input>
+                                    <xsl:attribute 
name="type">button</xsl:attribute>
+                                    <xsl:attribute 
name="style">width:20px;</xsl:attribute>
+                                    <xsl:attribute 
name="value">...</xsl:attribute>
+                                    <xsl:attribute 
name="onclick">codeGenFileUploadeHelper('<xsl:value-of 
select="$name"/>','<xsl:value-of select="$name"/>_<xsl:value-of 
select="$idSuffix"/>'); return false;</xsl:attribute>
+                                </input>
+                            </xsl:if>
+
                         </xsl:when>
                         <xsl:when test="$uiType='check'">
                              <input>

_______________________________________________
Commons-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/commons-dev

Reply via email to