You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2011/08/24 09:02:04 UTC
svn commit: r1160990 - in
/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine:
NewURL.java ScriptParser.java VariableURL.java
Author: kwright
Date: Wed Aug 24 07:02:04 2011
New Revision: 1160990
URL: http://svn.apache.org/viewvc?rev=1160990&view=rev
Log:
Add URL variable type
Added:
incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewURL.java (with props)
incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java (with props)
Modified:
incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewURL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewURL.java?rev=1160990&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewURL.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewURL.java Wed Aug 24 07:02:04 2011
@@ -0,0 +1,51 @@
+/* $Id$ */
+
+/**
+* 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.manifoldcf.scriptengine;
+
+/** Class defining the creation of a new URL object.
+*/
+public class NewURL implements NewOperation
+{
+ /** Parse and execute. Parsing begins right after the "new" keyword and the operation name token.
+ *@param sp is the script parser to use to help in the parsing.
+ *@param currentStream is the current token stream.
+ *@return the variable reference that got created. Should never be null.
+ */
+ public VariableReference parseAndCreate(ScriptParser sp, TokenStream currentStream)
+ throws ScriptException
+ {
+ VariableReference basePath = sp.evaluateExpression(currentStream);
+ if (basePath == null)
+ sp.syntaxError(currentStream,"Need url base path expression");
+ String basePathString = sp.resolveMustExist(currentStream,basePath).getStringValue();
+ return new VariableURL(basePathString);
+ }
+
+ /** Parse and skip. Parsing begins right after the "new" keyword and the operation name token.
+ *@param sp is the script parser to use to help in the parsing.
+ *@param currentStream is the current token stream.
+ */
+ public void parseAndSkip(ScriptParser sp, TokenStream currentStream)
+ throws ScriptException
+ {
+ sp.skipExpression(currentStream);
+ }
+
+}
Propchange: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewURL.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/NewURL.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java?rev=1160990&r1=1160989&r2=1160990&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java (original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java Wed Aug 24 07:02:04 2011
@@ -907,6 +907,7 @@ public class ScriptParser
// Add the new operations we need
sp.addNewOperation("configuration",new NewConfiguration());
sp.addNewOperation("configurationnode",new NewConfigurationNode());
+ sp.addNewOperation("url",new NewURL());
try
{
Added: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java?rev=1160990&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java (added)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java Wed Aug 24 07:02:04 2011
@@ -0,0 +1,77 @@
+/* $Id$ */
+
+/**
+* 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.manifoldcf.scriptengine;
+
+import java.net.*;
+import java.io.*;
+
+/** Variable class representing a ManifoldCF API URL. As the URL is glued together, the
+* individual path pieces are appropriately encoded.
+*/
+public class VariableURL extends VariableBase
+{
+ protected String encodedURL;
+
+ public VariableURL(String baseURLValue)
+ {
+ this.encodedURL = baseURLValue;
+ if (encodedURL.endsWith("/"))
+ this.encodedURL = this.encodedURL.substring(0,this.encodedURL.length()-1);
+ }
+
+ /** Get the variable's value as a string */
+ public String getStringValue()
+ throws ScriptException
+ {
+ return encodedURL;
+ }
+
+ public VariableReference plus(Variable v)
+ throws ScriptException
+ {
+ if (v == null)
+ throw new ScriptException("+ operand cannot be null");
+ try
+ {
+ return new VariableURL(encodedURL + "/" + URLEncoder.encode(v.getStringValue(),"utf-8"));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new ScriptException(e.getMessage(),e);
+ }
+ }
+
+ public VariableReference doubleEquals(Variable v)
+ throws ScriptException
+ {
+ if (v == null)
+ throw new ScriptException("== operand cannot be null");
+ return new VariableBoolean(encodedURL.equals(v.getStringValue()));
+ }
+
+ public VariableReference exclamationEquals(Variable v)
+ throws ScriptException
+ {
+ if (v == null)
+ throw new ScriptException("!= operand cannot be null");
+ return new VariableBoolean(!encodedURL.equals(v.getStringValue()));
+ }
+
+}
Propchange: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java
------------------------------------------------------------------------------
svn:keywords = Id