You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-dev@jakarta.apache.org by se...@apache.org on 2009/03/25 01:38:03 UTC
svn commit: r758105 - in /jakarta/bsf/trunk/bsf3:
bsf-api/src/test/java/org/apache/bsf/
bsf-utils/src/main/java/org/apache/bsf/xml/
bsf-utils/src/main/java/org/mozilla/javascript/
bsf-utils/src/test/java/org/apache/bsf/xml/
Author: sebb
Date: Wed Mar 25 00:38:01 2009
New Revision: 758105
URL: http://svn.apache.org/viewvc?rev=758105&view=rev
Log:
Detab
Added:
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/Test.java (with props)
Modified:
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/DefaultXMLHelper.java
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JRubyReXMLHelper.java
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XAxiomHelper.java
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XHelper.java
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XXmlBeansHelper.java
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/XMLHelper.java
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/mozilla/javascript/ContextHelper.java
jakarta/bsf/trunk/bsf3/bsf-utils/src/test/java/org/apache/bsf/xml/JavaScriptXMLHelperTestCase.java
Added: jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/Test.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/Test.java?rev=758105&view=auto
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/Test.java (added)
+++ jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/Test.java Wed Mar 25 00:38:01 2009
@@ -0,0 +1,34 @@
+/*
+ * 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.bsf;
+
+import javax.script.*;
+
+import junit.framework.TestCase;
+
+public class Test extends TestCase {
+
+ public void setUp(){
+
+ }
+
+ public void test(){
+
+ }
+}
Propchange: jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/Test.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/DefaultXMLHelper.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/DefaultXMLHelper.java?rev=758105&r1=758104&r2=758105&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/DefaultXMLHelper.java (original)
+++ jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/DefaultXMLHelper.java Wed Mar 25 00:38:01 2009
@@ -34,36 +34,36 @@
*/
public class DefaultXMLHelper extends XMLHelper {
- public OMElement toOMElement(Object scriptXML) throws ScriptException {
+ public OMElement toOMElement(Object scriptXML) throws ScriptException {
try {
- StAXOMBuilder builder = new StAXOMBuilder(
+ StAXOMBuilder builder = new StAXOMBuilder(
new ByteArrayInputStream(scriptXML.toString().getBytes()));
return builder.getDocumentElement();
} catch (XMLStreamException e) {
- throw new ScriptException(e);
+ throw new ScriptException(e);
}
- }
+ }
- public Object toScriptXML(OMElement om) throws ScriptException {
+ public Object toScriptXML(OMElement om) throws ScriptException {
return om.toString();
- }
+ }
- public Node toDOMNode(Object scriptXML) throws ScriptException {
- throw new UnsupportedOperationException("not implemented yet");
- }
-
- public Object toScriptXML(XMLStreamReader reader) throws ScriptException {
- throw new UnsupportedOperationException("not implemented yet");
- }
-
- public Object toScriptXML(Node node) throws ScriptException {
- throw new UnsupportedOperationException("not implemented yet");
- }
-
- public XMLStreamReader toXMLStreamReader(Object scriptXML) throws ScriptException {
- throw new UnsupportedOperationException("not implemented yet");
- }
+ public Node toDOMNode(Object scriptXML) throws ScriptException {
+ throw new UnsupportedOperationException("not implemented yet");
+ }
+
+ public Object toScriptXML(XMLStreamReader reader) throws ScriptException {
+ throw new UnsupportedOperationException("not implemented yet");
+ }
+
+ public Object toScriptXML(Node node) throws ScriptException {
+ throw new UnsupportedOperationException("not implemented yet");
+ }
+
+ public XMLStreamReader toXMLStreamReader(Object scriptXML) throws ScriptException {
+ throw new UnsupportedOperationException("not implemented yet");
+ }
}
Modified: jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JRubyReXMLHelper.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JRubyReXMLHelper.java?rev=758105&r1=758104&r2=758105&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JRubyReXMLHelper.java (original)
+++ jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JRubyReXMLHelper.java Wed Mar 25 00:38:01 2009
@@ -33,36 +33,36 @@
*/
public class JRubyReXMLHelper extends DefaultXMLHelper {
- private final ScriptEngine scriptEngine;
+ private final ScriptEngine scriptEngine;
- JRubyReXMLHelper(ScriptEngine scriptEngine) {
- this.scriptEngine = scriptEngine;
- }
-
- public OMElement toOMElement(Object scriptXML) throws ScriptException {
- if (scriptXML == null) {
- return null;
- }
- try {
-
- byte[] xmlBytes = scriptXML.toString().getBytes();
- StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(xmlBytes));
- return builder.getDocumentElement();
-
- } catch (Exception e) {
- throw new ScriptException(e);
- }
- }
-
- public Object toScriptXML(OMElement om) throws ScriptException {
- if (om == null) {
- return null;
- }
- StringBuffer srcFragment = new StringBuffer("Document.new(<<EOF\n");
- srcFragment.append(om.toString());
- srcFragment.append("\nEOF\n");
- srcFragment.append(")");
- return scriptEngine.eval(srcFragment.toString());
- }
+ JRubyReXMLHelper(ScriptEngine scriptEngine) {
+ this.scriptEngine = scriptEngine;
+ }
+
+ public OMElement toOMElement(Object scriptXML) throws ScriptException {
+ if (scriptXML == null) {
+ return null;
+ }
+ try {
+
+ byte[] xmlBytes = scriptXML.toString().getBytes();
+ StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(xmlBytes));
+ return builder.getDocumentElement();
+
+ } catch (Exception e) {
+ throw new ScriptException(e);
+ }
+ }
+
+ public Object toScriptXML(OMElement om) throws ScriptException {
+ if (om == null) {
+ return null;
+ }
+ StringBuffer srcFragment = new StringBuffer("Document.new(<<EOF\n");
+ srcFragment.append(om.toString());
+ srcFragment.append("\nEOF\n");
+ srcFragment.append(")");
+ return scriptEngine.eval(srcFragment.toString());
+ }
}
Modified: jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XAxiomHelper.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XAxiomHelper.java?rev=758105&r1=758104&r2=758105&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XAxiomHelper.java (original)
+++ jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XAxiomHelper.java Wed Mar 25 00:38:01 2009
@@ -35,28 +35,28 @@
*/
public class JavaScriptE4XAxiomHelper extends DefaultXMLHelper {
- private final Scriptable scope;
+ private final Scriptable scope;
JavaScriptE4XAxiomHelper(ScriptEngine engine) {
- // tell Rhino to use Axiom E4X impl
+ // tell Rhino to use Axiom E4X impl
if (!ContextFactory.hasExplicitGlobal()) {
- ContextFactory.initGlobal(new AxiomE4XContextFactory());
+ ContextFactory.initGlobal(new AxiomE4XContextFactory());
}
- Context cx = Context.enter();
- try {
+ Context cx = Context.enter();
+ try {
- this.scope = cx.initStandardObjects();
+ this.scope = cx.initStandardObjects();
- } finally {
- Context.exit();
- }
- }
+ } finally {
+ Context.exit();
+ }
+ }
- public OMElement toOMElement(Object scriptXML) throws ScriptException {
+ public OMElement toOMElement(Object scriptXML) throws ScriptException {
if (scriptXML == null) {
- return null;
+ return null;
}
if (!(scriptXML instanceof XMLObject)) {
@@ -66,28 +66,28 @@
Object o = ScriptableObject.callMethod( (Scriptable) scriptXML, "getXmlObject", new Object[0]);
return (OMElement) o;
// return (OMElement) ScriptableObject.callMethod( (Scriptable) scriptXML, "getXmlObject", new Object[0]);
- }
+ }
- public Object toScriptXML(OMElement om) throws ScriptException {
+ public Object toScriptXML(OMElement om) throws ScriptException {
if (om == null) {
- return null;
+ return null;
}
Context cx = Context.enter();
try {
- // TODO: why is this needed? A bug in axiom-e4x?
- ContextHelper.setTopCallScope(cx, scope);
+ // TODO: why is this needed? A bug in axiom-e4x?
+ ContextHelper.setTopCallScope(cx, scope);
return cx.newObject(scope, "XML", new Object[]{om});
} finally {
Context.exit();
}
- }
+ }
- public static void init() {
- ContextFactory.initGlobal(new AxiomE4XContextFactory());
- }
+ public static void init() {
+ ContextFactory.initGlobal(new AxiomE4XContextFactory());
+ }
}
class AxiomE4XContextFactory extends ContextFactory {
Modified: jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XHelper.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XHelper.java?rev=758105&r1=758104&r2=758105&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XHelper.java (original)
+++ jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XHelper.java Wed Mar 25 00:38:01 2009
@@ -25,15 +25,15 @@
*/
public class JavaScriptE4XHelper extends DefaultXMLHelper {
- public static XMLHelper getXMLHelper(ScriptEngine engine) {
+ public static XMLHelper getXMLHelper(ScriptEngine engine) {
- try {
- Class.forName("org.wso2.javascript.xmlimpl.XMLLibImpl", true, JavaScriptE4XHelper.class.getClassLoader());
- return new JavaScriptE4XAxiomHelper(engine);
- } catch (ClassNotFoundException e) {
- // TODO: also support Rhino 1.6R7 DOM based E4X impl
- return new JavaScriptE4XXmlBeansHelper(engine);
- }
- }
+ try {
+ Class.forName("org.wso2.javascript.xmlimpl.XMLLibImpl", true, JavaScriptE4XHelper.class.getClassLoader());
+ return new JavaScriptE4XAxiomHelper(engine);
+ } catch (ClassNotFoundException e) {
+ // TODO: also support Rhino 1.6R7 DOM based E4X impl
+ return new JavaScriptE4XXmlBeansHelper(engine);
+ }
+ }
}
Modified: jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XXmlBeansHelper.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XXmlBeansHelper.java?rev=758105&r1=758104&r2=758105&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XXmlBeansHelper.java (original)
+++ jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/JavaScriptE4XXmlBeansHelper.java Wed Mar 25 00:38:01 2009
@@ -36,20 +36,20 @@
*/
public class JavaScriptE4XXmlBeansHelper extends DefaultXMLHelper {
- private final Scriptable scope;
+ private final Scriptable scope;
JavaScriptE4XXmlBeansHelper(ScriptEngine engine) {
- Context cx = Context.enter();
- try {
- this.scope = cx.initStandardObjects();
- } finally {
- Context.exit();
- }
- }
+ Context cx = Context.enter();
+ try {
+ this.scope = cx.initStandardObjects();
+ } finally {
+ Context.exit();
+ }
+ }
- public OMElement toOMElement(Object scriptXML) throws ScriptException {
+ public OMElement toOMElement(Object scriptXML) throws ScriptException {
if (scriptXML == null) {
- return null;
+ return null;
}
if (!(scriptXML instanceof XMLObject)) {
@@ -69,22 +69,22 @@
return builder.getDocumentElement();
} catch (XMLStreamException e) {
- throw new ScriptException(e);
+ throw new ScriptException(e);
}
- }
+ }
- public Object toScriptXML(OMElement om) throws ScriptException {
+ public Object toScriptXML(OMElement om) throws ScriptException {
if (om == null) {
- return null;
+ return null;
}
Context cx = Context.enter();
try {
- XmlObject xml = null;
+ XmlObject xml = null;
try {
xml = XmlObject.Factory.parse(om.getXMLStreamReader());
} catch (Exception e) {
- throw new ScriptException(e);
+ throw new ScriptException(e);
}
Object wrappedXML = cx.getWrapFactory().wrap(cx, scope, xml, XmlObject.class);
return cx.newObject(scope, "XML", new Object[]{wrappedXML});
@@ -92,6 +92,6 @@
} finally {
Context.exit();
}
- }
+ }
}
Modified: jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/XMLHelper.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/XMLHelper.java?rev=758105&r1=758104&r2=758105&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/XMLHelper.java (original)
+++ jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/xml/XMLHelper.java Wed Mar 25 00:38:01 2009
@@ -32,39 +32,39 @@
*/
public abstract class XMLHelper {
- /**
- * Register axiom-e4x if its available
- * @deprecated temp approach for beta2 release
- */
- public static void init() {
- try {
- Class.forName("org.wso2.javascript.xmlimpl.XMLLibImpl", true, JavaScriptE4XHelper.class.getClassLoader());
- JavaScriptE4XAxiomHelper.init();
- } catch (ClassNotFoundException e) {
- }
- }
+ /**
+ * Register axiom-e4x if its available
+ * @deprecated temp approach for beta2 release
+ */
+ public static void init() {
+ try {
+ Class.forName("org.wso2.javascript.xmlimpl.XMLLibImpl", true, JavaScriptE4XHelper.class.getClassLoader());
+ JavaScriptE4XAxiomHelper.init();
+ } catch (ClassNotFoundException e) {
+ }
+ }
- public static XMLHelper getArgHelper(ScriptEngine engine) {
- // TODO: better discovery mechanisim than hardcoded class names
- if (engine == null) {
- return null;
- }
- String language = engine.getFactory().getLanguageName();
- if ("ECMAScript".endsWith(language)) {
- return JavaScriptE4XHelper.getXMLHelper(engine);
- } else if ("ruby".endsWith(language)) {
- return new JRubyReXMLHelper(engine);
- } else {
- return new DefaultXMLHelper();
- }
- }
-
- public abstract Object toScriptXML(OMElement om) throws ScriptException;
- public abstract OMElement toOMElement(Object scriptXML) throws ScriptException;
+ public static XMLHelper getArgHelper(ScriptEngine engine) {
+ // TODO: better discovery mechanisim than hardcoded class names
+ if (engine == null) {
+ return null;
+ }
+ String language = engine.getFactory().getLanguageName();
+ if ("ECMAScript".endsWith(language)) {
+ return JavaScriptE4XHelper.getXMLHelper(engine);
+ } else if ("ruby".endsWith(language)) {
+ return new JRubyReXMLHelper(engine);
+ } else {
+ return new DefaultXMLHelper();
+ }
+ }
- public abstract Object toScriptXML(XMLStreamReader reader) throws ScriptException;
- public abstract XMLStreamReader toXMLStreamReader(Object scriptXML) throws ScriptException;
+ public abstract Object toScriptXML(OMElement om) throws ScriptException;
+ public abstract OMElement toOMElement(Object scriptXML) throws ScriptException;
- public abstract Object toScriptXML(Node node) throws ScriptException;
- public abstract Node toDOMNode(Object scriptXML) throws ScriptException;
+ public abstract Object toScriptXML(XMLStreamReader reader) throws ScriptException;
+ public abstract XMLStreamReader toXMLStreamReader(Object scriptXML) throws ScriptException;
+
+ public abstract Object toScriptXML(Node node) throws ScriptException;
+ public abstract Node toDOMNode(Object scriptXML) throws ScriptException;
}
Modified: jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/mozilla/javascript/ContextHelper.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/mozilla/javascript/ContextHelper.java?rev=758105&r1=758104&r2=758105&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/mozilla/javascript/ContextHelper.java (original)
+++ jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/mozilla/javascript/ContextHelper.java Wed Mar 25 00:38:01 2009
@@ -27,11 +27,11 @@
* does not require this.
*/
public class ContextHelper {
-
- public static void setTopCallScope(Context cx, Scriptable scope) {
- if (cx.topCallScope == null) {
- cx.topCallScope = scope;
- }
- }
+
+ public static void setTopCallScope(Context cx, Scriptable scope) {
+ if (cx.topCallScope == null) {
+ cx.topCallScope = scope;
+ }
+ }
}
Modified: jakarta/bsf/trunk/bsf3/bsf-utils/src/test/java/org/apache/bsf/xml/JavaScriptXMLHelperTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/test/java/org/apache/bsf/xml/JavaScriptXMLHelperTestCase.java?rev=758105&r1=758104&r2=758105&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-utils/src/test/java/org/apache/bsf/xml/JavaScriptXMLHelperTestCase.java (original)
+++ jakarta/bsf/trunk/bsf3/bsf-utils/src/test/java/org/apache/bsf/xml/JavaScriptXMLHelperTestCase.java Wed Mar 25 00:38:01 2009
@@ -33,33 +33,33 @@
*/
public class JavaScriptXMLHelperTestCase extends TestCase {
- private ScriptEngine engine;
+ private ScriptEngine engine;
- private XMLHelper xmlHelper;
+ private XMLHelper xmlHelper;
- public void testToOmElement() throws ScriptException {
- Object scriptXML = engine.eval("<a><b>petra</b></a>");
- assertTrue(scriptXML instanceof XMLObject);
-
- OMElement om = xmlHelper.toOMElement(scriptXML);
- assertNotNull(om);
- assertEquals("<a><b>petra</b></a>", om.toString());
- }
-
- public void testToScriptXML() throws ScriptException {
- OMElement om = xmlHelper.toOMElement(engine.eval("<a><b>petra</b></a>"));
-
- Bindings bindings = engine.createBindings();
- bindings.put("xml", xmlHelper.toScriptXML(om));
-
- assertEquals("xml", engine.eval("typeof xml", bindings));
- assertEquals("petra", engine.eval("xml.b.toString()", bindings));
- }
-
- public void setUp() {
- ScriptEngineManager manager = new ScriptEngineManager();
- engine = manager.getEngineByExtension("js");
- xmlHelper = XMLHelper.getArgHelper(engine);
- }
+ public void testToOmElement() throws ScriptException {
+ Object scriptXML = engine.eval("<a><b>petra</b></a>");
+ assertTrue(scriptXML instanceof XMLObject);
+
+ OMElement om = xmlHelper.toOMElement(scriptXML);
+ assertNotNull(om);
+ assertEquals("<a><b>petra</b></a>", om.toString());
+ }
+
+ public void testToScriptXML() throws ScriptException {
+ OMElement om = xmlHelper.toOMElement(engine.eval("<a><b>petra</b></a>"));
+
+ Bindings bindings = engine.createBindings();
+ bindings.put("xml", xmlHelper.toScriptXML(om));
+
+ assertEquals("xml", engine.eval("typeof xml", bindings));
+ assertEquals("petra", engine.eval("xml.b.toString()", bindings));
+ }
+
+ public void setUp() {
+ ScriptEngineManager manager = new ScriptEngineManager();
+ engine = manager.getEngineByExtension("js");
+ xmlHelper = XMLHelper.getArgHelper(engine);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-dev-help@jakarta.apache.org