[mashup-dev] svn commit r1832 - in trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects: atom file wsrequest

svn at wso2.org svn at wso2.org
Mon Apr 16 02:41:36 PDT 2007


Author: thilina
Date: Mon Apr 16 02:41:25 2007
New Revision: 1832

Modified:
   trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/atom/APPClientHostObject.java
   trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/file/JavaScriptFileObject.java
   trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/file/JavaScriptTextFileObject.java
   trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestCallBack.java
   trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java
Log:
Adding license headers + initial bits to support binary data in xml

Modified: trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/atom/APPClientHostObject.java
==============================================================================
--- trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/atom/APPClientHostObject.java	(original)
+++ trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/atom/APPClientHostObject.java	Mon Apr 16 02:41:25 2007
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2006,2007 WSO2, Inc. http://www.wso2.org
+ *
+ * Licensed 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.wso2.mashup.hostobjects.atom;
 
 import java.io.IOException;

Modified: trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/file/JavaScriptFileObject.java
==============================================================================
--- trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/file/JavaScriptFileObject.java	(original)
+++ trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/file/JavaScriptFileObject.java	Mon Apr 16 02:41:25 2007
@@ -1,14 +1,63 @@
 package org.wso2.mashup.hostobjects.file;
 
 import java.io.File;
+import java.io.IOException;
 
+import javax.activation.DataHandler;
+
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
+import org.apache.axis2.AxisFault;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Function;
+import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.xmlimpl.XML;
 
 public class JavaScriptFileObject extends ScriptableObject {
     protected File file;
 
-    public void jsConstructor(String filename) {
-        file = new File(filename);
+    private DataHandler dataHandler;
+
+    private boolean isDir = false;
+
+    public static Scriptable jsConstructor(Context cx, Object[] args, Function ctorObj,
+            boolean inNewExpr) throws IOException {
+        JavaScriptFileObject result = new JavaScriptFileObject();
+        if (args.length == 1 & !(args[0] == Context.getUndefinedValue())) {
+            if (args[0] instanceof String) {
+                result.file = new File((String) args[0]);
+                if (result.file.isDirectory()) {
+                    result.isDir = true;
+                }
+                if (!result.file.exists()) {
+                    File parentFile = result.file.getParentFile();
+                    if (parentFile != null) {
+                        parentFile.mkdirs();
+                    }
+                    result.file.createNewFile();
+                }
+            } else if (args[0] instanceof XML) {
+                XML xml = (XML) args[0];
+                OMNode node = xml.getAxiomFromXML();
+                if (node instanceof OMText) {
+                    OMText textNode = (OMText) node;
+                    if (textNode.isBinary()) {
+                        result.dataHandler = (DataHandler) textNode.getDataHandler();
+                    }else{
+                        //TODO support directly writing XML to the file
+                        throw new AxisFault("XML content given for the File does not contain base64Binary.");
+                    }
+                        
+                }else{
+                    //TODO support directly writing XML to the file
+                    throw new AxisFault("XML content given for the File does not contain base64Binary.");
+                }
+            }else{
+                throw new AxisFault("Invalid parameters.");
+            }
+        }
+        return result;
     }
 
     public String getClassName() {

Modified: trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/file/JavaScriptTextFileObject.java
==============================================================================
--- trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/file/JavaScriptTextFileObject.java	(original)
+++ trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/file/JavaScriptTextFileObject.java	Mon Apr 16 02:41:25 2007
@@ -11,6 +11,7 @@
 import java.io.Writer;
 import java.util.Date;
 
+import org.apache.axis2.AxisFault;
 import org.mozilla.javascript.Context;
 
 public class JavaScriptTextFileObject extends JavaScriptFileObject {
@@ -53,8 +54,7 @@
     public Writer jsFunction_getWriter() throws IOException {
 
         if (reader != null)
-            throw Context
-                    .reportRuntimeError("Cannot write to the already reading file. Please close the reader by calling finishReading().");
+            throw new AxisFault("Cannot write to the already reading file. Please close the reader by calling finishReading().");
         if (writer == null) {
             writer = new BufferedWriter(new FileWriter(file));
         }

Modified: trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestCallBack.java
==============================================================================
--- trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestCallBack.java	(original)
+++ trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestCallBack.java	Mon Apr 16 02:41:25 2007
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2006,2007 WSO2, Inc. http://www.wso2.org
+ *
+ * Licensed 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.wso2.mashup.hostobjects.wsrequest;
 
 import org.apache.axiom.om.OMElement;

Modified: trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java
==============================================================================
--- trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java	(original)
+++ trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java	Mon Apr 16 02:41:25 2007
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2006,2007 WSO2, Inc. http://www.wso2.org
+ *
+ * Licensed 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.wso2.mashup.hostobjects.wsrequest;
 
 import java.io.StringReader;




More information about the Mashup-dev mailing list