Wikitty-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
July 2011
- 4 participants
- 85 discussions
r1090 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine
by mfortun@users.nuiton.org 26 Jul '11
by mfortun@users.nuiton.org 26 Jul '11
26 Jul '11
Author: mfortun
Date: 2011-07-26 14:24:33 +0200 (Tue, 26 Jul 2011)
New Revision: 1090
Url: http://nuiton.org/repositories/revision/wikitty/1090
Log:
* add comments
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java 2011-07-26 11:43:51 UTC (rev 1089)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java 2011-07-26 12:24:33 UTC (rev 1090)
@@ -14,11 +14,23 @@
import javax.script.SimpleBindings;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.nuiton.util.ArrayUtil;
import org.nuiton.util.StringUtil;
+/**
+ * Script engine for html code.
+ * Use to handle binds element invocation inside html code.
+ *
+ * @author mfortun
+ *
+ */
public class HtmlScriptEngine implements ScriptEngine {
+
+ final static Log log = LogFactory.getLog(HtmlScriptEngine.class);
+
/*
* algo super simple en fait.
*
@@ -34,6 +46,9 @@
static public String REGEX_END = "$";
static public String REGEX_EMPTY = " +";
static public String REGEX_EMPTY_END = REGEX_EMPTY + REGEX_END;
+ /**
+ * regex to match string method argument
+ */
static public String REGEX_STRING_ARG = "\"[\\w\\d]*\"";
protected ScriptEngineFactory factory;
@@ -135,16 +150,23 @@
return factory;
}
+ /**
+ * Finaly handle html to found invokation to bindings element
+ * @param code the html code
+ * @param binds the binding
+ * @return code with binds value/invokation replacement
+ */
protected String evaluateCodeInsideHtml(String code, Bindings binds) {
String result = new String(code);
for (String bindingElement : binds.keySet()) {
Object oo = binds.get(bindingElement);
-
+
+ // parse to search method invokation on binds element
String[] hmtl = result.split(bindingElement
+ REGEX_BIND_ELEMENT_METHOD);
-
+
String pageModified = hmtl[0];
for (int i = 0; i < hmtl.length - 1; i++) {
@@ -153,17 +175,15 @@
int end = code.indexOf(hmtl[i + 1]);
// end = end;
-
+ // Isolate method invocation
String codeToExecude = code.substring(begin, end);
codeToExecude = codeToExecude.trim();
-
+ //invoke
String resultCode = invokeFromName(oo, codeToExecude, binds);
// replace at position by result
-
pageModified += resultCode;
-
pageModified += hmtl[i + 1];
}
@@ -186,11 +206,18 @@
* Si ça match seulement avec le nom alors on fait
* getValue().tostring
*/
-
}
return result;
}
+ /**
+ * use to invoke method on the object contained in the bindinds
+ * @param oo the object bind
+ * @param invokation the string containing the invokation
+ * @param binds binding used inside evaluation
+ * @return result of the invokation or if method not found the invokation
+ * string
+ */
protected String invokeFromName(Object oo, String invokation, Bindings binds) {
int dotPosition = invokation.indexOf(".");
@@ -203,15 +230,16 @@
//
String methodName = invokation.substring(dotPosition + 1,
openBracketPosition);
-
+ // obtain param list
String params = invokation.substring(openBracketPosition + 1,
closingBracketPosition);
-
+ // parse params
String[] parsedParam = StringUtil.split(params, ",");
List<Object> listParam = new LinkedList<Object>();
List<Class<?>> listType = new LinkedList<Class<?>>();
-
+
+ // found param type and values
for (String argument : parsedParam) {
Object value = argument;
/*
@@ -261,8 +289,7 @@
result = methodBindin.invoke(oo, args).toString();
} catch (Exception e) {
- e.printStackTrace();
- // TODO mfortun-2011-07-25 handle exception
+ log.debug("Method "+methodName+ " not found on:" + oo);
}
return result;
1
0
r1089 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine
by mfortun@users.nuiton.org 26 Jul '11
by mfortun@users.nuiton.org 26 Jul '11
26 Jul '11
Author: mfortun
Date: 2011-07-26 13:43:51 +0200 (Tue, 26 Jul 2011)
New Revision: 1089
Url: http://nuiton.org/repositories/revision/wikitty/1089
Log:
* correct engine for method invoke
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java 2011-07-25 15:24:41 UTC (rev 1088)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java 2011-07-26 11:43:51 UTC (rev 1089)
@@ -14,6 +14,7 @@
import javax.script.SimpleBindings;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
+import org.nuiton.util.ArrayUtil;
import org.nuiton.util.StringUtil;
public class HtmlScriptEngine implements ScriptEngine {
@@ -29,10 +30,11 @@
* usefull to match element contained inside the binding map that on which
* method are called. like : objectName.getName() objectName.setName("truc")
*/
- static public String REGEX_BIND_ELEMENT_METHOD = "\\.\\w+\\(\\w*\\)";
+ static public String REGEX_BIND_ELEMENT_METHOD = "\\.\\w+\\([\\w\"\\d]*\\)";
static public String REGEX_END = "$";
- static public String REGEX_EMPTY = " *";
+ static public String REGEX_EMPTY = " +";
static public String REGEX_EMPTY_END = REGEX_EMPTY + REGEX_END;
+ static public String REGEX_STRING_ARG = "\"[\\w\\d]*\"";
protected ScriptEngineFactory factory;
protected ScriptContext context;
@@ -54,8 +56,8 @@
try {
return this.eval(IOUtils.toString(reader), context);
} catch (IOException e) {
- //TODO mfortun-2011-07-25 handle this, change ?
- return StringUtils.EMPTY;
+ // TODO mfortun-2011-07-25 handle this, change ?
+ return StringUtils.EMPTY;
}
}
@@ -85,8 +87,8 @@
try {
return this.eval(IOUtils.toString(reader), n);
} catch (IOException e) {
- //TODO mfortun-2011-07-25 handle this, change ?
- return StringUtils.EMPTY;
+ // TODO mfortun-2011-07-25 handle this, change ?
+ return StringUtils.EMPTY;
}
}
@@ -147,26 +149,31 @@
for (int i = 0; i < hmtl.length - 1; i++) {
int begin = code.indexOf(hmtl[i]);
- begin = begin + hmtl[i].length() + 1;
+ begin = begin + hmtl[i].length();
int end = code.indexOf(hmtl[i + 1]);
- end = end - 1;
+ // end = end;
String codeToExecude = code.substring(begin, end);
codeToExecude = codeToExecude.trim();
+
String resultCode = invokeFromName(oo, codeToExecude, binds);
// replace at position by result
- pageModified += " " + resultCode + " ";
+ pageModified += resultCode;
pageModified += hmtl[i + 1];
}
- pageModified.replaceAll(bindingElement + REGEX_END, oo.toString());
- pageModified.replaceAll(bindingElement + REGEX_EMPTY_END,
- oo.toString() + " ");
+ pageModified = pageModified.replaceAll(bindingElement + REGEX_END
+ + "|" + REGEX_EMPTY + bindingElement + REGEX_EMPTY,
+ oo.toString());
+ // pageModified = pageModified.replaceAll(bindingElement +
+ // REGEX_EMPTY_END,
+ // oo.toString() + " ");
+
result = pageModified;
/*
@@ -186,17 +193,19 @@
protected String invokeFromName(Object oo, String invokation, Bindings binds) {
- String result = StringUtils.EMPTY;
-
int dotPosition = invokation.indexOf(".");
int openBracketPosition = invokation.indexOf("(");
int closingBracketPosition = invokation.indexOf(")");
+ // if no method found just let the same string in place
+ String result = invokation;
+ // .substring(0,dotPosition);;
+ //
String methodName = invokation.substring(dotPosition + 1,
- openBracketPosition - 1);
+ openBracketPosition);
String params = invokation.substring(openBracketPosition + 1,
- closingBracketPosition - 1);
+ closingBracketPosition);
String[] parsedParam = StringUtil.split(params, ",");
@@ -209,6 +218,13 @@
* check if argument is contained inside binding
*/
+ if (argument.matches(REGEX_STRING_ARG)){
+ value = argument.substring(1, argument.length()-1);
+ listParam.add(value);
+ listType.add(String.class);
+ continue;
+ }
+
if (binds.containsKey(argument)) {
value = binds.get(argument);
listParam.add(value);
@@ -235,14 +251,17 @@
}
Object[] args = listParam.toArray();
- Class<?>[] types = (Class<?>[]) listType.toArray();
+ Class<?>[] types = ArrayUtil.toArray(listType, Class.class);
+
try {
Method methodBindin = oo.getClass().getMethod(methodName, types);
+
result = methodBindin.invoke(oo, args).toString();
} catch (Exception e) {
+ e.printStackTrace();
// TODO mfortun-2011-07-25 handle exception
}
@@ -250,7 +269,4 @@
}
-
-
-
}
1
0
r1088 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine
by mfortun@users.nuiton.org 25 Jul '11
by mfortun@users.nuiton.org 25 Jul '11
25 Jul '11
Author: mfortun
Date: 2011-07-25 17:24:41 +0200 (Mon, 25 Jul 2011)
New Revision: 1088
Url: http://nuiton.org/repositories/revision/wikitty/1088
Log:
* complete factory
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java 2011-07-25 13:34:29 UTC (rev 1087)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java 2011-07-25 15:24:41 UTC (rev 1088)
@@ -1,17 +1,43 @@
package org.nuiton.wikitty.publication.engine;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
+public class HtmlScriptEngineFactory implements ScriptEngineFactory {
-public class HtmlScriptEngineFactory implements ScriptEngineFactory{
+ static protected List<String> extensions;
+ static protected List<String> names;
+ static protected List<String> mimesTypes;
+ static {
+ extensions = new ArrayList<String>(5);
+ extensions.add("xhtml");
+ extensions.add("xht");
+ extensions.add("xml");
+ extensions.add("html");
+ extensions.add("htm");
+ extensions = Collections.unmodifiableList(extensions);
+
+ names = new ArrayList<String>(2);
+ names.add("HtmlScriptEngine");
+ names.add("WikittyPublicationHtmlEngine");
+ names = Collections.unmodifiableList(names);
+
+ mimesTypes = new ArrayList<String>(2);
+ mimesTypes.add("application/xhtml+xml");
+ mimesTypes.add("text/html");
+
+ mimesTypes = Collections.unmodifiableList(mimesTypes);
+ }
+
@Override
public String getEngineName() {
return "HTML";
-
+
}
@Override
@@ -21,26 +47,17 @@
@Override
public List<String> getExtensions() {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ return extensions;
}
@Override
public List<String> getMimeTypes() {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ return mimesTypes;
}
@Override
public List<String> getNames() {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ return names;
}
@Override
@@ -50,54 +67,70 @@
@Override
public String getLanguageVersion() {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ return "5.0";
}
@Override
public Object getParameter(String key) {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+
+ if (key.equals(ScriptEngine.ENGINE)) {
+ return this.getScriptEngine();
+ }
+ if (key.equals(ScriptEngine.ENGINE_VERSION)) {
+ return this.getEngineVersion();
+ }
+ if (key.equals(ScriptEngine.NAME)) {
+ return this.getEngineName();
+ }
+ if (key.equals(ScriptEngine.LANGUAGE)) {
+ return this.getLanguageName();
+ }
+ if (key.equals(ScriptEngine.LANGUAGE_VERSION)) {
+ return this.getLanguageVersion();
+ }
+
+ throw new IllegalArgumentException("Invalid key");
+
}
@Override
public String getMethodCallSyntax(String obj, String m, String... args) {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ String ret = obj + "." + m + "(";
+ int len = args.length;
+ if (len == 0) {
+ ret += ")";
+ return ret;
+ }
+
+ for (int i = 0; i < len; i++) {
+ ret += args[i];
+ if (i != len - 1) {
+ ret += ",";
+ } else {
+ ret += ")";
+ }
+ }
+ return ret;
}
@Override
public String getOutputStatement(String toDisplay) {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ return toDisplay;
}
@Override
public String getProgram(String... statements) {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ int len = statements.length;
+ String ret = "";
+ for (int i = 0; i < len; i++) {
+ ret += statements[i] + ";";
+ }
+
+ return ret;
}
@Override
public ScriptEngine getScriptEngine() {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ return new HtmlScriptEngine();
}
-
-
-
-
-
}
1
0
r1087 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine
by mfortun@users.nuiton.org 25 Jul '11
by mfortun@users.nuiton.org 25 Jul '11
25 Jul '11
Author: mfortun
Date: 2011-07-25 15:34:29 +0200 (Mon, 25 Jul 2011)
New Revision: 1087
Url: http://nuiton.org/repositories/revision/wikitty/1087
Log:
* complete html script engine methods
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java 2011-07-25 13:08:27 UTC (rev 1086)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java 2011-07-25 13:34:29 UTC (rev 1087)
@@ -1,5 +1,6 @@
package org.nuiton.wikitty.publication.engine;
+import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Method;
import java.util.LinkedList;
@@ -11,6 +12,7 @@
import javax.script.ScriptEngineFactory;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.nuiton.util.StringUtil;
@@ -29,7 +31,8 @@
*/
static public String REGEX_BIND_ELEMENT_METHOD = "\\.\\w+\\(\\w*\\)";
static public String REGEX_END = "$";
- static public String REGEX_EMPTY_END = " *" + REGEX_END;
+ static public String REGEX_EMPTY = " *";
+ static public String REGEX_EMPTY_END = REGEX_EMPTY + REGEX_END;
protected ScriptEngineFactory factory;
protected ScriptContext context;
@@ -38,51 +41,53 @@
@Override
public Object eval(String script, ScriptContext context)
throws ScriptException {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
+ if (context.getBindings(ScriptContext.ENGINE_SCOPE) == null) {
+ return script;
+ }
+ return evaluateCodeInsideHtml(script,
+ context.getBindings(ScriptContext.ENGINE_SCOPE));
}
@Override
public Object eval(Reader reader, ScriptContext context)
throws ScriptException {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
+ try {
+ return this.eval(IOUtils.toString(reader), context);
+ } catch (IOException e) {
+ //TODO mfortun-2011-07-25 handle this, change ?
+ return StringUtils.EMPTY;
+ }
}
@Override
public Object eval(String script) throws ScriptException {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
+ if (context.getBindings(ScriptContext.ENGINE_SCOPE) == null) {
+ return script;
+ }
+ return evaluateCodeInsideHtml(script,
+ context.getBindings(ScriptContext.ENGINE_SCOPE));
}
@Override
public Object eval(Reader reader) throws ScriptException {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
+ return this.eval(reader, getContext());
}
@Override
public Object eval(String script, Bindings n) throws ScriptException {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
+ return evaluateCodeInsideHtml(script, n);
}
@Override
public Object eval(Reader reader, Bindings n) throws ScriptException {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
+ try {
+ return this.eval(IOUtils.toString(reader), n);
+ } catch (IOException e) {
+ //TODO mfortun-2011-07-25 handle this, change ?
+ return StringUtils.EMPTY;
+ }
}
@Override
@@ -245,4 +250,7 @@
}
+
+
+
}
1
0
r1086 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine
by mfortun@users.nuiton.org 25 Jul '11
by mfortun@users.nuiton.org 25 Jul '11
25 Jul '11
Author: mfortun
Date: 2011-07-25 15:08:27 +0200 (Mon, 25 Jul 2011)
New Revision: 1086
Url: http://nuiton.org/repositories/revision/wikitty/1086
Log:
* dummy evaluate algorithm
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java 2011-07-25 08:54:20 UTC (rev 1085)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java 2011-07-25 13:08:27 UTC (rev 1086)
@@ -1,56 +1,47 @@
package org.nuiton.wikitty.publication.engine;
import java.io.Reader;
+import java.lang.reflect.Method;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
-import java.util.StringTokenizer;
-
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
+import org.apache.commons.lang.StringUtils;
+import org.nuiton.util.StringUtil;
+public class HtmlScriptEngine implements ScriptEngine {
-public class HtmlScriptEngine implements ScriptEngine{
-
/*
* algo super simple en fait.
*
- * On lit le code.
- * pour tout ce qui est dans les clés des bindings on fait l'invocation
- * java qui va avec.
- *
+ * On lit le code. pour tout ce qui est dans les clés des bindings on fait
+ * l'invocation java qui va avec.
*/
-
-
-
+
/**
* usefull to match element contained inside the binding map that on which
- * method are called. like :
- * objectName.getName()
- * objectName.setName("truc")
+ * method are called. like : objectName.getName() objectName.setName("truc")
*/
- static public String REGEX_BIND_ELEMENT_METHOD = "\\..*\\(.*\\)";
- static public String REGEX_END="$";
- static public String REGEX_EMPTY_END=" *"+REGEX_END;
+ static public String REGEX_BIND_ELEMENT_METHOD = "\\.\\w+\\(\\w*\\)";
+ static public String REGEX_END = "$";
+ static public String REGEX_EMPTY_END = " *" + REGEX_END;
-
protected ScriptEngineFactory factory;
protected ScriptContext context;
protected Map<String, Object> attributes;
-
-
-
-
-
+
@Override
public Object eval(String script, ScriptContext context)
throws ScriptException {
// TODO mfortun
throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ // return null;
+
}
@Override
@@ -58,45 +49,45 @@
throws ScriptException {
// TODO mfortun
throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ // return null;
+
}
@Override
public Object eval(String script) throws ScriptException {
// TODO mfortun
throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ // return null;
+
}
@Override
public Object eval(Reader reader) throws ScriptException {
// TODO mfortun
throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ // return null;
+
}
@Override
public Object eval(String script, Bindings n) throws ScriptException {
// TODO mfortun
throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ // return null;
+
}
@Override
public Object eval(Reader reader, Bindings n) throws ScriptException {
// TODO mfortun
throw new UnsupportedOperationException("not yet implemented");
- //return null;
-
+ // return null;
+
}
@Override
public void put(String key, Object value) {
- attributes.put(key, value);
+ attributes.put(key, value);
}
@Override
@@ -126,69 +117,132 @@
@Override
public void setContext(ScriptContext context) {
- this.context=context;
+ this.context = context;
}
@Override
public ScriptEngineFactory getFactory() {
- if (factory==null){
+ if (factory == null) {
factory = new HtmlScriptEngineFactory();
}
return factory;
}
-
- protected String evaluateCodeInsideHtml(String code, Bindings binds){
- String result = new String (code);
-
- for (String key: binds.keySet()){
+ protected String evaluateCodeInsideHtml(String code, Bindings binds) {
+ String result = new String(code);
- Object oo = binds.get(key);
-
- String [] hmtl = code.split(key+REGEX_BIND_ELEMENT_METHOD);
-
+ for (String bindingElement : binds.keySet()) {
- for(int i=0; i<hmtl.length-1; i++){
+ Object oo = binds.get(bindingElement);
+
+ String[] hmtl = result.split(bindingElement
+ + REGEX_BIND_ELEMENT_METHOD);
+
+ String pageModified = hmtl[0];
+ for (int i = 0; i < hmtl.length - 1; i++) {
+
int begin = code.indexOf(hmtl[i]);
- begin = begin+hmtl[i].length()+1;
-
- int end = code.indexOf(hmtl[i+1]);
- end=end-1;
-
+ begin = begin + hmtl[i].length() + 1;
+
+ int end = code.indexOf(hmtl[i + 1]);
+ end = end - 1;
+
String codeToExecude = code.substring(begin, end);
+ codeToExecude = codeToExecude.trim();
- String resultCode="";
-
+ String resultCode = invokeFromName(oo, codeToExecude, binds);
+
// replace at position by result
-
-
-
+ pageModified += " " + resultCode + " ";
+
+ pageModified += hmtl[i + 1];
}
- code.replaceAll(key+REGEX_END, oo.toString());
- code.replaceAll(key+REGEX_EMPTY_END, oo.toString()+" ");
-
-
-
+ pageModified.replaceAll(bindingElement + REGEX_END, oo.toString());
+ pageModified.replaceAll(bindingElement + REGEX_EMPTY_END,
+ oo.toString() + " ");
+
+ result = pageModified;
+
/*
- * Voir si on match aussi les trucs plus générique avec
- * déclaration de classe et tout le tintouint
+ * Voir si on match aussi les trucs plus générique avec déclaration
+ * de classe et tout le tintouint
*
- * Si ça match le nom et avec le nom associé à la regex method
- * cette derniuère est prioritaire.
- * Et on éxécute la méthode sur l'objet.
+ * Si ça match le nom et avec le nom associé à la regex method cette
+ * derniuère est prioritaire. Et on éxécute la méthode sur l'objet.
*
- * Si ça match seulement avec le nom alors on fait
+ * Si ça match seulement avec le nom alors on fait
* getValue().tostring
- *
- *
- *
*/
-
-
-
+
}
return result;
}
-
+
+ protected String invokeFromName(Object oo, String invokation, Bindings binds) {
+
+ String result = StringUtils.EMPTY;
+
+ int dotPosition = invokation.indexOf(".");
+ int openBracketPosition = invokation.indexOf("(");
+ int closingBracketPosition = invokation.indexOf(")");
+
+ String methodName = invokation.substring(dotPosition + 1,
+ openBracketPosition - 1);
+
+ String params = invokation.substring(openBracketPosition + 1,
+ closingBracketPosition - 1);
+
+ String[] parsedParam = StringUtil.split(params, ",");
+
+ List<Object> listParam = new LinkedList<Object>();
+ List<Class<?>> listType = new LinkedList<Class<?>>();
+
+ for (String argument : parsedParam) {
+ Object value = argument;
+ /*
+ * check if argument is contained inside binding
+ */
+
+ if (binds.containsKey(argument)) {
+ value = binds.get(argument);
+ listParam.add(value);
+ listType.add(value.getClass());
+ continue;
+ }
+ // dummy algo, try to determine type of the argument
+ // if exception throwned try another type of object
+ try {
+ value = Double.parseDouble(argument);
+ } catch (Exception e) {
+ try {
+ value = Integer.parseInt(argument);
+ } catch (Exception ee) {
+ try {
+ value = Boolean.parseBoolean(argument);
+ } catch (Exception eee) {
+
+ }
+ }
+ }
+ listParam.add(value);
+ listType.add(value.getClass());
+ }
+
+ Object[] args = listParam.toArray();
+ Class<?>[] types = (Class<?>[]) listType.toArray();
+
+ try {
+
+ Method methodBindin = oo.getClass().getMethod(methodName, types);
+ result = methodBindin.invoke(oo, args).toString();
+
+ } catch (Exception e) {
+ // TODO mfortun-2011-07-25 handle exception
+ }
+
+ return result;
+
+ }
+
}
1
0
r1085 - in trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts: . component
by mfortun@users.nuiton.org 25 Jul '11
by mfortun@users.nuiton.org 25 Jul '11
25 Jul '11
Author: mfortun
Date: 2011-07-25 10:54:20 +0200 (Mon, 25 Jul 2011)
New Revision: 1085
Url: http://nuiton.org/repositories/revision/wikitty/1085
Log:
* add regex to check if fqFieldName attribut or FqFieldName list are correctly set
Modified:
trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/WikittyFieldHandler.java
trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/AbstractWikittyComponent.java
trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/AbstractWikittyComponentBean.java
trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/FormTagBean.java
Modified: trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/WikittyFieldHandler.java
===================================================================
--- trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/WikittyFieldHandler.java 2011-07-22 16:22:08 UTC (rev 1084)
+++ trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/WikittyFieldHandler.java 2011-07-25 08:54:20 UTC (rev 1085)
@@ -300,15 +300,9 @@
public boolean isIncluded(String fqFieldName) {
- String[] fields = StringUtil.split(fqFieldName,
- WikittyUtil.FQ_FIELD_NAME_SEPARATOR);
+ String extName = WikittyUtil.getExtensionNameFromFQFieldName(fqFieldName);
+ String fieldName = WikittyUtil.getFieldNameFromFQFieldName(fqFieldName);
- if (fields.length != 2) {
- // TODO mfortun-2011-06-29 exception
- }
- String extName = fields[0];
- String fieldName = fields[1];
-
return this.isIncluded(extName, fieldName);
}
Modified: trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/AbstractWikittyComponent.java
===================================================================
--- trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/AbstractWikittyComponent.java 2011-07-22 16:22:08 UTC (rev 1084)
+++ trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/AbstractWikittyComponent.java 2011-07-25 08:54:20 UTC (rev 1085)
@@ -4,13 +4,15 @@
import javax.servlet.http.HttpServletResponse;
import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.WikittyUtil;
import org.nuiton.wikitty.entities.BusinessEntity;
import org.nuiton.wikitty.entities.BusinessEntityImpl;
import org.nuiton.wikitty.entities.Wikitty;
import com.opensymphony.xwork2.util.ValueStack;
-public abstract class AbstractWikittyComponent extends AbstractWikittyClosingUIBean {
+public abstract class AbstractWikittyComponent extends
+ AbstractWikittyClosingUIBean {
/**
* Never used directly this attribute use the getter
@@ -25,6 +27,36 @@
*/
protected WikittyProxy proxy;
+ static public String REGEX_EMPTY = " *";
+ static public String REGEX_FIELD_SEP = ",";
+ static public String REGEX_FIELD_JOKER="\\*";
+
+
+ /**
+ * Regex to check that field name are correct
+ * " *\w+\.\w+ *"
+ */
+ static public String REGEX_WIKITTY_FQFIELDNAME = REGEX_EMPTY
+ + WikittyUtil.extensionNamePattern
+ + WikittyUtil.FQ_FIELD_NAME_SEPARATOR_REGEX
+ + WikittyUtil.extensionNamePattern + REGEX_EMPTY;
+
+ /**
+ * regex to check joker field and fqfield name for field name
+ * " *\w+\.(\w+|\*) *"
+ */
+ static public String REGEX_WIKITTY_FQFIELDNAME_EXT_JOKER = REGEX_EMPTY
+ + WikittyUtil.extensionNamePattern
+ + WikittyUtil.FQ_FIELD_NAME_SEPARATOR_REGEX
+ + WikittyUtil.extensionNamePattern+"(|"+REGEX_FIELD_JOKER+")" + REGEX_EMPTY;
+
+ /**
+ * regex to check if field are list correctly
+ * " *\w+\.\w+|\* *(, *\w+\.\w+|\* *)*"
+ */
+ static public String REGEX_LIST_FQFIELDNAME = REGEX_WIKITTY_FQFIELDNAME_EXT_JOKER + "("
+ + REGEX_FIELD_SEP + REGEX_WIKITTY_FQFIELDNAME_EXT_JOKER + ")*";
+
public AbstractWikittyComponent(ValueStack stack,
HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
@@ -36,7 +68,7 @@
public Wikitty getWikitty() {
if (wikitty == null) {
- wikitty = ((BusinessEntityImpl)getBusinessEntity()).getWikitty();
+ wikitty = ((BusinessEntityImpl) getBusinessEntity()).getWikitty();
}
return wikitty;
}
Modified: trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/AbstractWikittyComponentBean.java
===================================================================
--- trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/AbstractWikittyComponentBean.java 2011-07-22 16:22:08 UTC (rev 1084)
+++ trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/AbstractWikittyComponentBean.java 2011-07-25 08:54:20 UTC (rev 1085)
@@ -11,7 +11,8 @@
import org.nuiton.wikitty.struts.WikittyFieldHandler;
import com.opensymphony.xwork2.util.ValueStack;
-public abstract class AbstractWikittyComponentBean extends AbstractWikittyComponent {
+public abstract class AbstractWikittyComponentBean extends
+ AbstractWikittyComponent {
/** to use log facility, just put in your code: log.info(\"...\"); */
final static private Log log = LogFactory
@@ -19,6 +20,7 @@
protected WikittyFieldHandler handler;
protected String fqFieldName;
+
protected AbstractWikittyComponentBean(ValueStack stack,
HttpServletRequest request, HttpServletResponse response) {
@@ -27,7 +29,7 @@
handler = (WikittyFieldHandler) stack.getContext().get(
WikittyFieldHandler.WIKITTY_STACK_KEY);
- }
+ }
public boolean isIncluded(String fieldName) {
if (handler != null) {
@@ -47,7 +49,7 @@
if (handler != null) {
return handler.getWikitty();
}
-
+
return super.getWikitty();
}
@@ -57,47 +59,46 @@
}
return super.getBusinessEntity();
}
-
-
-
-
+
@Override
protected void evaluateExtraParams() {
super.evaluateExtraParams();
-
+
if (handler == null && wikitty == null && businessEntity == null) {
log.info("Handler not found in the stack and wikitty or businessEntity not declared");
-
+
throw new TagUseException(
- "Tag must declare Wikitty or businessEntity attribute if used outside ws:form tag");
+ "Tag must declare Wikitty or businessEntity attribute if used outside ws:form tag");
}
-
+
+ if (!fqFieldName.matches(REGEX_WIKITTY_FQFIELDNAME)) {
+ log.debug("fqFieldName: " + fqFieldName + " expected match"
+ + REGEX_WIKITTY_FQFIELDNAME);
+ throw new TagUseException("fqFieldName must be valid: "
+ + REGEX_WIKITTY_FQFIELDNAME);
+ }
+
if (name != null && handler == null) {
addParameter("name", name);
} else {
addParameter("name", fqFieldName);
}
-
-
+
/*
- if (id!=null || id.equals("")) {
- id = name==null?fqFieldName:name;
- } else {
- addParameter("name", fqFieldName);
- }*/
-
+ * if (id!=null || id.equals("")) { id = name==null?fqFieldName:name; }
+ * else { addParameter("name", fqFieldName); }
+ */
+
// check if field included
// if so add the parametter included
- // and add the field to the addedfield (usefull if inside
-
-
-
- if (isIncluded(fqFieldName)){
+ // and add the field to the addedfield (usefull if inside
+
+ if (isIncluded(fqFieldName)) {
addParameter("included", true);
if (handler != null) {
handler.addAddedField(fqFieldName);
}
- }
+ }
}
public WikittyFieldHandler getHandler() {
@@ -112,8 +113,13 @@
return fqFieldName;
}
+ /**
+ * set the fqfieldname, value will be trimed
+ *
+ * @param fqFieldName
+ */
public void setFqFieldName(String fqFieldName) {
- this.fqFieldName = fqFieldName;
+ this.fqFieldName = fqFieldName.trim();
}
}
Modified: trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/FormTagBean.java
===================================================================
--- trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/FormTagBean.java 2011-07-22 16:22:08 UTC (rev 1084)
+++ trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/component/FormTagBean.java 2011-07-25 08:54:20 UTC (rev 1085)
@@ -15,29 +15,26 @@
import com.opensymphony.xwork2.util.ValueStack;
-@StrutsTag(name = "Wikitty", tldTagClass = "org.nuiton.wikitty.struts.tag.FormTag",
- description = "", allowDynamicAttributes = false)
+@StrutsTag(name = "Wikitty", tldTagClass = "org.nuiton.wikitty.struts.tag.FormTag", description = "", allowDynamicAttributes = false)
public class FormTagBean extends AbstractWikittyComponent {
-
+
/** to use log facility, just put in your code: log.info(\"...\"); */
final static private Log log = LogFactory.getLog(FormTagBean.class);
-
public static final String OPEN_TEMPLATE = "ws-form";
public static final String TEMPLATE = "ws-form-close";
-
protected String action;
protected String redirect;
protected String include;
protected String exclude;
-
+
protected String order;
protected Boolean orderBefore;
-
+
protected Boolean allowDelete;
-
+
public FormTagBean(ValueStack stack, HttpServletRequest request,
HttpServletResponse response) {
super(stack, request, response);
@@ -46,29 +43,54 @@
@Override
protected void evaluateExtraParams() {
super.evaluateExtraParams();
-
-
- if ( wikitty == null && businessEntity == null) {
+
+ if (wikitty == null && businessEntity == null) {
log.info("wikitty and businessEntity not declared");
-
+
throw new TagUseException(
- "Tag must declare a valid Wikitty or businessEntity attribute");
+ "Tag must declare a valid Wikitty or businessEntity attribute");
}
+
+ /*
+ * check for for fqfieldname list if respect regex
+ */
+ if (include.length() != 0 && !include.matches(REGEX_LIST_FQFIELDNAME)) {
+ log.debug("Include list set: " + include + " expected match: "
+ + REGEX_WIKITTY_FQFIELDNAME);
+ throw new TagUseException(
+ "Include list field must be set with correct value: "
+ + REGEX_LIST_FQFIELDNAME);
+ }
-
- /* this methode is called two times:
- * - first when the wikitty open tag is red
- * - second when the wikitty closing tag is red
+ if (order.length() != 0 && !order.matches(REGEX_LIST_FQFIELDNAME)) {
+ log.debug("Order list set: " + order + " expected match: "
+ + REGEX_WIKITTY_FQFIELDNAME);
+ throw new TagUseException(
+ "Order list field must be set with correct value: "
+ + REGEX_LIST_FQFIELDNAME);
+
+ }
+
+ if (exclude.length() != 0 && !exclude.matches(REGEX_LIST_FQFIELDNAME)) {
+ log.debug("Exclude list set: " + exclude + " expected match: "
+ + REGEX_WIKITTY_FQFIELDNAME);
+ throw new TagUseException(
+ "Exclude list field must be set with correct value: "
+ + REGEX_LIST_FQFIELDNAME);
+
+ }
+
+ /*
+ * this methode is called two times: - first when the wikitty open tag
+ * is red - second when the wikitty closing tag is red
*
- * for the first called this create an object wikittyfieldhandler
- * that will be store inside the stack and used by the included tag (
- * inside the wikitty tags to store)
- *
- *
+ * for the first called this create an object wikittyfieldhandler that
+ * will be store inside the stack and used by the included tag ( inside
+ * the wikitty tags to store)
*/
-
+
if (action != null) {
addParameter("action", findString(action));
}
@@ -80,18 +102,16 @@
if (allowDelete != null) {
addParameter("allowDelete", allowDelete);
}
-
- if (orderBefore!=null) {
+
+ if (orderBefore != null) {
addParameter("orderBefore", orderBefore);
}
-
-
- if (name==null || name.equals(StringUtils.EMPTY)) {
- name = "wikitty-form-"+getWikitty().getId();
-
- }
-
-
+
+ if (name == null || name.equals(StringUtils.EMPTY)) {
+ name = "wikitty-form-" + getWikitty().getId();
+
+ }
+
addParameter("wikittyid", findString(getWikitty().getId()));
// no uses finally:
// addParameter("wikittyversion", findString(wikitty.getVersion()));
@@ -99,19 +119,21 @@
// .getExtensionNames().toString()));
addParameter("name", name);
-
- Object temp = stack.getContext().get(WikittyFieldHandler.WIKITTY_STACK_KEY);
+
+ Object temp = stack.getContext().get(
+ WikittyFieldHandler.WIKITTY_STACK_KEY);
WikittyFieldHandler handler;
if (temp == null) {
-
+
// construct wikitty field handler withh
// all required param and put it in the stack
handler = new WikittyFieldHandler();
-
+
log.info(handler + " Added to the stack");
-
- stack.getContext().put(WikittyFieldHandler.WIKITTY_STACK_KEY, handler);
+ stack.getContext().put(WikittyFieldHandler.WIKITTY_STACK_KEY,
+ handler);
+
handler.setExclude(exclude);
handler.setInclude(include);
handler.setOrder(order);
@@ -120,21 +142,17 @@
handler.setOrderBefore(orderBefore);
} else {
- // when the tag is closing remove the handler from the stack
- stack.getContext().remove(WikittyFieldHandler.WIKITTY_STACK_KEY);
-
-
- handler = (WikittyFieldHandler) temp;
+ // when the tag is closing remove the handler from the stack
+ stack.getContext().remove(WikittyFieldHandler.WIKITTY_STACK_KEY);
+
+ handler = (WikittyFieldHandler) temp;
}
// add field that have to be write inside the page
log.info("add wikitty fields to the parametters");
addParameter("wikittyfields", handler.getWikittyField());
-
}
-
-
public String getDefaultOpenTemplate() {
return OPEN_TEMPLATE;
}
@@ -143,8 +161,6 @@
return TEMPLATE;
}
-
-
public String getAction() {
return action;
}
@@ -165,24 +181,39 @@
return include;
}
+ /**
+ * set fqFieldName include list, value trimed
+ *
+ * @param include
+ */
public void setInclude(String include) {
- this.include = include;
+ this.include = include.trim();
}
public String getExclude() {
return exclude;
}
+ /**
+ * set fqfieldName exclude list, value trimed
+ *
+ * @param exclude
+ */
public void setExclude(String exclude) {
- this.exclude = exclude;
+ this.exclude = exclude.trim();
}
public String getOrder() {
return order;
}
+ /**
+ * set fqfieldName order list, value trimed
+ *
+ * @param order
+ */
public void setOrder(String order) {
- this.order = order;
+ this.order = order.trim();
}
public boolean isAllowDelete() {
@@ -208,5 +239,5 @@
public void setAllowDelete(Boolean allowDelete) {
this.allowDelete = allowDelete;
}
-
+
}
1
0
r1084 - in trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication: . engine
by mfortun@users.nuiton.org 22 Jul '11
by mfortun@users.nuiton.org 22 Jul '11
22 Jul '11
Author: mfortun
Date: 2011-07-22 18:22:08 +0200 (Fri, 22 Jul 2011)
New Revision: 1084
Url: http://nuiton.org/repositories/revision/wikitty/1084
Log:
* first step to build a script engine for html
Added:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java
Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java 2011-07-22 16:22:08 UTC (rev 1084)
@@ -0,0 +1,194 @@
+package org.nuiton.wikitty.publication.engine;
+
+import java.io.Reader;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptException;
+import javax.script.SimpleBindings;
+
+
+public class HtmlScriptEngine implements ScriptEngine{
+
+ /*
+ * algo super simple en fait.
+ *
+ * On lit le code.
+ * pour tout ce qui est dans les clés des bindings on fait l'invocation
+ * java qui va avec.
+ *
+ */
+
+
+
+ /**
+ * usefull to match element contained inside the binding map that on which
+ * method are called. like :
+ * objectName.getName()
+ * objectName.setName("truc")
+ */
+ static public String REGEX_BIND_ELEMENT_METHOD = "\\..*\\(.*\\)";
+ static public String REGEX_END="$";
+ static public String REGEX_EMPTY_END=" *"+REGEX_END;
+
+
+ protected ScriptEngineFactory factory;
+ protected ScriptContext context;
+ protected Map<String, Object> attributes;
+
+
+
+
+
+ @Override
+ public Object eval(String script, ScriptContext context)
+ throws ScriptException {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public Object eval(Reader reader, ScriptContext context)
+ throws ScriptException {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public Object eval(String script) throws ScriptException {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public Object eval(Reader reader) throws ScriptException {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public Object eval(String script, Bindings n) throws ScriptException {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public Object eval(Reader reader, Bindings n) throws ScriptException {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public void put(String key, Object value) {
+ attributes.put(key, value);
+ }
+
+ @Override
+ public Object get(String key) {
+ return attributes.get(key);
+ }
+
+ @Override
+ public Bindings getBindings(int scope) {
+ return context.getBindings(scope);
+ }
+
+ @Override
+ public void setBindings(Bindings bindings, int scope) {
+ context.setBindings(bindings, scope);
+ }
+
+ @Override
+ public Bindings createBindings() {
+ return new SimpleBindings();
+ }
+
+ @Override
+ public ScriptContext getContext() {
+ return context;
+ }
+
+ @Override
+ public void setContext(ScriptContext context) {
+ this.context=context;
+ }
+
+ @Override
+ public ScriptEngineFactory getFactory() {
+ if (factory==null){
+ factory = new HtmlScriptEngineFactory();
+ }
+ return factory;
+ }
+
+
+ protected String evaluateCodeInsideHtml(String code, Bindings binds){
+ String result = new String (code);
+
+ for (String key: binds.keySet()){
+
+ Object oo = binds.get(key);
+
+ String [] hmtl = code.split(key+REGEX_BIND_ELEMENT_METHOD);
+
+
+ for(int i=0; i<hmtl.length-1; i++){
+ int begin = code.indexOf(hmtl[i]);
+ begin = begin+hmtl[i].length()+1;
+
+ int end = code.indexOf(hmtl[i+1]);
+ end=end-1;
+
+ String codeToExecude = code.substring(begin, end);
+
+ String resultCode="";
+
+ // replace at position by result
+
+
+
+
+ }
+ code.replaceAll(key+REGEX_END, oo.toString());
+ code.replaceAll(key+REGEX_EMPTY_END, oo.toString()+" ");
+
+
+
+ /*
+ * Voir si on match aussi les trucs plus générique avec
+ * déclaration de classe et tout le tintouint
+ *
+ * Si ça match le nom et avec le nom associé à la regex method
+ * cette derniuère est prioritaire.
+ * Et on éxécute la méthode sur l'objet.
+ *
+ * Si ça match seulement avec le nom alors on fait
+ * getValue().tostring
+ *
+ *
+ *
+ */
+
+
+
+ }
+ return result;
+ }
+
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java 2011-07-22 16:22:08 UTC (rev 1084)
@@ -0,0 +1,103 @@
+package org.nuiton.wikitty.publication.engine;
+
+import java.util.List;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+
+
+public class HtmlScriptEngineFactory implements ScriptEngineFactory{
+
+ @Override
+ public String getEngineName() {
+ return "HTML";
+
+ }
+
+ @Override
+ public String getEngineVersion() {
+ return "0.1";
+ }
+
+ @Override
+ public List<String> getExtensions() {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public List<String> getMimeTypes() {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public List<String> getNames() {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public String getLanguageName() {
+ return "HTML";
+ }
+
+ @Override
+ public String getLanguageVersion() {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public Object getParameter(String key) {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public String getMethodCallSyntax(String obj, String m, String... args) {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public String getOutputStatement(String toDisplay) {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public String getProgram(String... statements) {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+ @Override
+ public ScriptEngine getScriptEngine() {
+ // TODO mfortun
+ throw new UnsupportedOperationException("not yet implemented");
+ //return null;
+
+ }
+
+
+
+
+
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
1
0
r1083 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action
by mfortun@users.nuiton.org 21 Jul '11
by mfortun@users.nuiton.org 21 Jul '11
21 Jul '11
Author: mfortun
Date: 2011-07-21 12:43:56 +0200 (Thu, 21 Jul 2011)
New Revision: 1083
Url: http://nuiton.org/repositories/revision/wikitty/1083
Log:
* remove unused method
* add method to have access to argument map
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationActionEval.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationContext.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationActionEval.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationActionEval.java 2011-07-21 08:38:06 UTC (rev 1082)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationActionEval.java 2011-07-21 10:43:56 UTC (rev 1083)
@@ -58,18 +58,9 @@
@Override
public String execute() throws Exception {
- List<String> argsString = new ArrayList<String>();
- String args = ActionContext.getContext().getParameters().get(ARGS_KEY)
- .toString();
- String[] argsTab = StringUtil.split(args, SEPARATOR);
+ inputStream = new ByteArrayInputStream(doAction(this,
+ getMandatoryArguments()).toString().getBytes());
- for (String arg : argsTab) {
- argsString.add(arg);
- }
-
- inputStream = new ByteArrayInputStream(doAction(this, argsString)
- .toString().getBytes());
-
return SUCCESS;
}
@@ -227,13 +218,7 @@
return WikittyPublicationConfig.getConfig();
}
- @Override
- public String getActionName() {
- // TODO mfortun-2011-05-09 really needed ?
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
- }
@Override
public String makeUrl(String url) {
@@ -261,28 +246,17 @@
@Override
public List<String> getMandatoryArguments() {
- // TODO mfortun-2011-05-09 really needed ?
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
+ List<String> argsString = new ArrayList<String>();
+ String args = ActionContext.getContext().getParameters().get(ARGS_KEY)
+ .toString();
+ String[] argsTab = StringUtil.split(args, SEPARATOR);
+ for (String arg : argsTab) {
+ argsString.add(arg);
+ }
+ return argsString;
}
- @Override
- public Map<String, String> getArguments() {
- // TODO mfortun-2011-05-09 really needed ?
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public Map<String, byte[]> getArgumentFiles() {
- // TODO mfortun-2011-05-09 really needed ?
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
public String getContentType() {
return contentType;
}
@@ -296,4 +270,15 @@
return getWikittyPublicationProxy();
}
+ @Override
+ public Map<String, String> getArguments() {
+ Map<String,String> result = new HashMap<String, String>();
+
+ for( String argElm : ActionContext.getContext().getParameters().keySet()){
+ result.put(argElm, this.getArgument(argElm, ""));
+ }
+
+ return result;
+ }
+
}
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationContext.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationContext.java 2011-07-21 08:38:06 UTC (rev 1082)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationContext.java 2011-07-21 10:43:56 UTC (rev 1083)
@@ -37,12 +37,6 @@
public abstract ApplicationConfig getAppConfig();
- /**
- * le nom de l'action a faire
- * @return
- */
- public abstract String getActionName();
-
public abstract WikittyProxy getWikittyProxy();
@@ -57,16 +51,14 @@
public abstract List<String> getMandatoryArguments();
- public abstract Map<String, String> getArguments();
-
- public abstract Map<String, byte[]> getArgumentFiles();
-
public abstract String getArgument(String name, String defaultValue);
public abstract String getContentType();
public abstract void setContentType(String contentType);
-
+
public abstract String toString();
+
+ public abstract Map<String,String> getArguments();
}
\ No newline at end of file
1
0
r1082 - in trunk/wikitty-publication: . src/main/java/org/nuiton/wikitty/publication src/main/java/org/nuiton/wikitty/publication/externalize src/main/java/org/nuiton/wikitty/publication/interceptor src/main/java/org/nuiton/wikitty/publication/synchro src/main/resources
by mfortun@users.nuiton.org 21 Jul '11
by mfortun@users.nuiton.org 21 Jul '11
21 Jul '11
Author: mfortun
Date: 2011-07-21 10:38:06 +0200 (Thu, 21 Jul 2011)
New Revision: 1082
Url: http://nuiton.org/repositories/revision/wikitty/1082
Log:
* remove wikitty struts from publication
* organize packages
Added:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/AbstractWikittyFileService.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/MimeTypePubHelper.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyFileUtil.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/interceptor/
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/interceptor/LoginInterceptor.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/interceptor/LogoutInterceptor.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationSynchronize.java
trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-jar.properties
Removed:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/LoginInterceptor.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/LogoutInterceptor.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/AbstractWikittyFileService.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/MimeTypePubHelper.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/PropertiesExtended.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyFileUtil.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
Modified:
trunk/wikitty-publication/pom.xml
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationConfig.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyPublicationExternalize.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyServiceJarLoader.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
trunk/wikitty-publication/src/main/resources/struts.xml
Modified: trunk/wikitty-publication/pom.xml
===================================================================
--- trunk/wikitty-publication/pom.xml 2011-07-20 15:26:30 UTC (rev 1081)
+++ trunk/wikitty-publication/pom.xml 2011-07-21 08:38:06 UTC (rev 1082)
@@ -37,13 +37,6 @@
</dependency>
<dependency>
- <groupId>org.nuiton.wikitty</groupId>
- <artifactId>wikitty-struts</artifactId>
- <version>${project.version}</version>
- <scope>runtime</scope>
- </dependency>
-
- <dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
@@ -113,7 +106,7 @@
<groupId>org.apache.struts.xwork</groupId>
<artifactId>xwork-core</artifactId>
</dependency>
-
+
</dependencies>
<!-- ************************************************************* -->
Copied: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/AbstractWikittyFileService.java (from rev 1078, trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/AbstractWikittyFileService.java)
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/AbstractWikittyFileService.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/AbstractWikittyFileService.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -0,0 +1,541 @@
+package org.nuiton.wikitty.publication;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.WikittyUtil;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.search.operators.And;
+import org.nuiton.wikitty.search.operators.AssociatedRestriction;
+import org.nuiton.wikitty.search.operators.Between;
+import org.nuiton.wikitty.search.operators.BinaryOperator;
+import org.nuiton.wikitty.search.operators.Contains;
+import org.nuiton.wikitty.search.operators.Element;
+import org.nuiton.wikitty.search.operators.False;
+import org.nuiton.wikitty.search.operators.In;
+import org.nuiton.wikitty.search.operators.Keyword;
+import org.nuiton.wikitty.search.operators.Not;
+import org.nuiton.wikitty.search.operators.Null;
+import org.nuiton.wikitty.search.operators.Or;
+import org.nuiton.wikitty.search.operators.Restriction;
+import org.nuiton.wikitty.search.operators.RestrictionName;
+import org.nuiton.wikitty.search.operators.True;
+
+
+/**
+ * This service must be extends by wikitty service that are over file system
+ * directly or this kind of storage for wikitty.
+ *
+ *
+ *
+ * @author mfortun
+ *
+ */
+public abstract class AbstractWikittyFileService implements WikittyService{
+
+
+ final static Log log = LogFactory.getLog(AbstractWikittyFileService.class);
+
+ public AbstractWikittyFileService() {
+ super();
+ }
+
+ /**
+ * Method that must be implemented by the extended service. This must return
+ * all the wikitty stored. The result will be use to checkrestriction for
+ * a find.
+ * @return a Map with wikittyId as Key and wikitty as value
+ */
+ protected abstract Map<String, Wikitty> getAllWikitties();
+
+
+
+ /**
+ * Write by jcouteau, used to check if a wikitty check a restriction
+ *
+ * @see org.nuiton.wikitty.storage.WikittySearchEngineInMemory#checkRestriction
+ *
+ * @param restriction
+ * the restriction
+ * @param w
+ * the wikitty to check
+ * @return if the wikitty check the restriction
+ */
+ public boolean checkRestriction(Restriction restriction, Wikitty w) {
+
+
+ if (restriction instanceof BinaryOperator) {
+ BinaryOperator binOp = (BinaryOperator) restriction;
+
+ String fqfieldName = binOp.getElement().getName();
+
+ // Checks on extensions
+ if (Element.ELT_EXTENSION.equals(fqfieldName)) {
+ boolean checked = false;
+
+ switch (restriction.getName()) {
+ case NOT_EQUALS:
+ checked = !w.getExtensionNames().contains(binOp.getValue());
+ break;
+ case EQUALS:
+ checked = w.getExtensionNames().contains(binOp.getValue());
+ break;
+ }
+
+ return checked;
+
+ // Checks on id
+ } else if (Element.ELT_ID.equals(fqfieldName)) {
+
+ boolean checked = false;
+
+ switch (restriction.getName()) {
+ case NOT_EQUALS:
+ checked = !w.getId().equals(binOp.getValue());
+ break;
+ case EQUALS:
+ checked = w.getId().equals(binOp.getValue());
+ break;
+ }
+
+ return checked;
+ }
+
+ // si les wikitty n'ont meme pas l'extension concerné
+ // Le check restriction, ne doit pas tester les champs
+ // si les wikitty n'ont meme pas l'extension concerné
+ String[] extName = fqfieldName.split("\\.");
+ if (!w.hasField(extName[0], extName[1])) {
+
+ // return true in case of not equals
+ if (RestrictionName.NOT_EQUALS == restriction.getName()) {
+ return true;
+ }
+
+ return false;
+ }
+ // recupere la valeur dans le wikitty
+ Object o = w.getFqField(fqfieldName);
+
+ // recupere le type de la valeur
+ FieldType t = w.getFieldType(fqfieldName);
+ // convertie la valeur a verifier dans le meme type que la valeur
+ // du wikitty
+ Object value = binOp.getValue();
+ if (!(value instanceof Collection) && t.isCollection()) {
+ // on doit encapsuler dans une collection, car la creation
+ // de la requete ajoute autant de v == o && ... que de valeurs
+ // dans la collection (champs multi-value solr). Mais
+ // dans le inmemory on doit retrouve des collections et non pas
+ // des objets seuls :(
+ value = Collections.singleton(value);
+ }
+ value = t.getValidValue(value);
+
+ boolean checked = false;
+
+ switch (restriction.getName()) {
+ case EQUALS:
+
+ if (value instanceof String && o instanceof String) {
+ String pattern = (String) value;
+ pattern = pattern.replace("*", "\\p{ASCII}*");
+ pattern = pattern.replace("?", "\\p{ASCII}");
+
+ Pattern p = Pattern.compile(pattern);
+ Matcher m = p.matcher((String) o);
+ checked = m.matches();
+ } else {
+ checked = value.equals(o);
+ }
+ break;
+ case LESS:
+ checked = ((Comparable) o).compareTo(value) < 0;
+ break;
+ case LESS_OR_EQUAL:
+ checked = ((Comparable) o).compareTo(value) <= 0;
+ break;
+ case GREATER:
+ checked = ((Comparable) o).compareTo(value) > 0;
+ break;
+ case GREATER_OR_EQUAL:
+ checked = ((Comparable) o).compareTo(value) >= 0;
+ break;
+ case NOT_EQUALS:
+ checked = !value.equals(o);
+ break;
+ case ENDS_WITH:
+ if (t.getType() != TYPE.STRING) {
+ throw new WikittyException(
+ "Can't search for contents that 'ends with' on attribute type different of String. "
+ + "Attribute "
+ + fqfieldName
+ + " is "
+ + t.getType().name());
+ }
+ checked = ((String) o).endsWith((String) value);
+ break;
+ case STARTS_WITH:
+ if (t.getType() != TYPE.STRING) {
+ throw new WikittyException(
+ "Can't search for contents that 'starts with' on attribute type different of String. "
+ + "Attribute "
+ + fqfieldName
+ + " is "
+ + t.getType().name());
+ }
+
+ // FIXME mfortun-2011-04-20 rustine pour champs multivalué de
+ // type string
+ // et restriction startwith dessus. ça marche mais faudrait
+ // quelque chose de plus
+ // propre, et surtout généraliser pour toutes les restrictions
+
+ if (o instanceof Collection<?>
+ && value instanceof Collection<?>) {
+
+ for (Object val : (Collection) value) {
+
+ String valu = (String) val;
+
+ for (Object oo : (Collection) o) {
+ String cotainedO = (String) oo;
+ if (cotainedO != null) {
+ checked = checked || cotainedO.startsWith(valu);
+ }
+ }
+
+ }
+
+ } else {
+
+ checked = ((String) o).startsWith((String) value);
+ }
+ break;
+ }
+ return checked;
+ } else if (restriction instanceof Null) {
+ Null nullRes = (Null) restriction;
+
+ String fqfieldName = nullRes.getFieldName();
+
+ // check my wikitty got the right extension before doing anything.
+ String[] extName = fqfieldName.split("\\.");
+ if (!w.hasField(extName[0], extName[1])) {
+ return false;
+ }
+ // get the value in the wikitty
+ Object o = w.getFqField(fqfieldName);
+
+ // No null on extensions, always return false
+ if (fqfieldName.equals(Element.ELT_EXTENSION)) {
+ return false;
+ }
+
+ // No null on ids, always return false
+ if (fqfieldName.equals(Element.ELT_ID)) {
+ return false;
+ }
+
+ boolean checked = false;
+
+ switch (nullRes.getName()) {
+ case IS_NULL:
+ checked = (o == null);
+ break;
+ case IS_NOT_NULL:
+ checked = (o != null);
+ break;
+ }
+
+ return checked;
+
+ } else if (restriction instanceof In) {
+ In in = (In) restriction;
+ String fqfieldName = in.getElement().getName();
+ String testedValue = String.valueOf(w.getFqField(fqfieldName));
+ for (String value : in.getValue()) {
+ if (testedValue.equals(value)) {
+ return true;
+ }
+ }
+
+ return false;
+
+ } else if (restriction instanceof True) {
+ return true;
+ } else if (restriction instanceof False) {
+ return false;
+ } else if (restriction instanceof Contains) {
+ Contains contains = (Contains) restriction;
+
+ String fqfieldName = contains.getElement().getName();
+ List<String> values = contains.getValue();
+
+ String extension = WikittyUtil
+ .getExtensionNameFromFQFieldName(fqfieldName);
+ String fieldName = WikittyUtil
+ .getFieldNameFromFQFieldName(fqfieldName);
+
+ if (!w.hasField(extension, fieldName)) {
+ return false;
+ }
+
+ // Get field as string and then split it to take into account not
+ // multivalued fields.
+ String testedValuesAsString = w.getFieldAsString(extension,
+ fieldName);
+
+ if ('[' == testedValuesAsString.charAt(0)) {
+ testedValuesAsString = testedValuesAsString.substring(1,
+ testedValuesAsString.length());
+ }
+
+ List<String> testedValues = Arrays.asList(testedValuesAsString
+ .split(","));
+
+ for (Object value : values) {
+ if (!testedValues.contains(String.valueOf(value))) {
+ return false;
+ }
+ }
+
+ return true;
+
+ } else if (restriction instanceof And) {
+ And and = (And) restriction;
+ for (Restriction sub : and.getRestrictions()) {
+ if (!checkRestriction(sub, w)) {
+ return false;
+ }
+ }
+ return true;
+ } else if (restriction instanceof Or) {
+ Or or = (Or) restriction;
+ for (Restriction sub : or.getRestrictions()) {
+ if (checkRestriction(sub, w)) {
+ return true;
+ }
+ }
+ return false;
+ } else if (restriction instanceof Keyword) {
+ Keyword keyword = (Keyword) restriction;
+
+ String value = keyword.getValue();
+
+ //TODO mfortun-2011-07-06 hack to ensure that * is intepreted as
+ // the real meaning aka any
+ if (value.equals("*")){
+ return true;
+ }
+
+ for (String fieldName : w.getAllFieldNames()) {
+ String testedValue = String.valueOf(w.getFqField(fieldName));
+ if (testedValue.contains(value)) {
+ return true;
+ }
+ }
+ return false;
+ } else if (restriction instanceof Not) {
+ Not or = (Not) restriction;
+ Restriction sub = or.getRestriction();
+ return !checkRestriction(sub, w);
+ } else if (restriction instanceof AssociatedRestriction) {
+
+ AssociatedRestriction ass = (AssociatedRestriction) restriction;
+
+ String fqfieldName = ass.getElement().getName();
+
+ // check my wikitty got the right extension before doing anything.
+ String[] extName = fqfieldName.split("\\.");
+ if (!w.hasField(extName[0], extName[1])) {
+ return false;
+ }
+ // get the value in the wikitty, it is a wikitty's id
+ Object o = w.getFqField(fqfieldName);
+
+ // Get sub-restriction
+ Restriction sub = ass.getRestriction();
+
+ Criteria associatedSearch = new Criteria();
+ associatedSearch.setRestriction(sub);
+
+ // find everything that validate the sub-restriction
+
+ List<Criteria> dummyList = new ArrayList<Criteria>();
+ dummyList.add(associatedSearch);
+ // same as proxy for "fix" unique param to list param
+ PagedResult<String> associatedResult = findAllByCriteria("",
+ dummyList).get(0);
+
+ List<String> associatedList = associatedResult.getAll();
+
+ // Check that my field is contained in the sub-restriction results.
+ return associatedList.contains(String.valueOf(o));
+ } else if (restriction instanceof Between) {
+
+ Between op = (Between) restriction;
+
+ Object max = op.getMax();
+ Object min = op.getMin();
+
+ // No between on extensions, always return false
+ if (op.getElement().getName().equals(Element.ELT_EXTENSION)) {
+ return false;
+ }
+
+ // No between on ids, always return false
+ if (op.getElement().getName().equals(Element.ELT_ID)) {
+ return false;
+ }
+
+ String fqfieldName = op.getElement().getName();
+
+ // si les wikitty n'ont meme pas l'extension concerné
+ // Le check restriction, ne doit pas tester les champs
+ // si les wikitty n'ont meme pas l'extension concerné
+ String[] extName = fqfieldName.split("\\.");
+ if (!w.hasField(extName[0], extName[1])) {
+ return false;
+ }
+
+ // recupere la valeur dans le wikitty
+ Object o = w.getFqField(fqfieldName);
+
+ // recupere le type de la valeur
+ FieldType t = w.getFieldType(fqfieldName);
+
+ if (!(min instanceof Collection) && t.isCollection()) {
+ // on doit encapsuler dans une collection, car la creation
+ // de la requete ajoute autant de v == o && ... que de valeurs
+ // dans la collection (champs multi-value solr). Mais
+ // dans le inmemory on doit retrouve des collections et non pas
+ // des objets seuls :(
+ min = Collections.singleton(min);
+ }
+ min = t.getValidValue(min);
+
+ if (!(max instanceof Collection) && t.isCollection()) {
+ // on doit encapsuler dans une collection, car la creation
+ // de la requete ajoute autant de v == o && ... que de valeurs
+ // dans la collection (champs multi-value solr). Mais
+ // dans le inmemory on doit retrouve des collections et non pas
+ // des objets seuls :(
+ max = Collections.singleton(max);
+ }
+ max = t.getValidValue(max);
+
+ return ((Comparable) o).compareTo(min) >= 0
+ && ((Comparable) o).compareTo(max) <= 0;
+ } else {
+ throw new UnsupportedOperationException(restriction.getName()
+ + " Search Not yet implemented");
+ }
+ }
+
+
+ @Override
+ public List<PagedResult<String>> findAllByCriteria(String securityToken,
+ List<Criteria> criteria) {
+
+
+ List<PagedResult<String>> result = new ArrayList<PagedResult<String>>();
+
+ Map<String, Wikitty> wikitties = getAllWikitties();
+
+ // for each criteria
+ for (Criteria cr : criteria) {
+ // prepare restriction on result
+ int firstIndex = cr.getFirstIndex();
+ int endIndex = cr.getEndIndex();
+ List<String> ids = new LinkedList<String>();
+ int currentIndex = 0;
+ Restriction restriction = cr.getRestriction();
+ // for each wikitty check if it match the resttriction
+ for (Entry<String, Wikitty> entry : wikitties.entrySet()) {
+ String id = entry.getKey();
+ Wikitty w = entry.getValue();
+ // if macth
+
+
+ if (checkRestriction(restriction, w)) {
+
+ // increment result number
+ currentIndex++;
+ if (currentIndex > firstIndex) {
+ ids.add(id);
+ }
+ // if the number of wikitty found is match
+ // stop the search for other wikitty
+ if (endIndex >= 0 && currentIndex >= endIndex) {
+ break;
+ }
+ }
+ }
+ result.add(new PagedResult<String>(firstIndex, ids.size(),
+ restriction.toString(), null, ids));
+
+ }
+ return result;
+ }
+
+
+ @Override
+ public List<String> findByCriteria(String securityToken,
+ List<Criteria> criteria) {
+ List<String> result = new ArrayList<String>();
+
+ Map<String, Wikitty> wikitties = getAllWikitties();
+ // for each criteria
+ for (Criteria cr : criteria) {
+ // prepare restriction on result
+ int firstIndex = cr.getFirstIndex();
+ int endIndex = cr.getEndIndex();
+ List<String> ids = new LinkedList<String>();
+ int currentIndex = 0;
+ Restriction restriction = cr.getRestriction();
+ // for each wikitty check if it match the resttriction
+ for (Entry<String, Wikitty> entry : wikitties.entrySet()) {
+ String id = entry.getKey();
+ Wikitty w = entry.getValue();
+ // if macth
+
+ log.debug("Check restriction for wikitty: " + w
+ + " Restriction:" + restriction);
+
+ if (checkRestriction(restriction, w)) {
+ // increment result number
+ currentIndex++;
+ if (currentIndex > firstIndex) {
+ ids.add(id);
+ }
+ // if the number of wikitty found is match
+ // stop the search for other wikitty
+ if (endIndex >= 0 && currentIndex >= endIndex) {
+ break;
+ }
+ }
+ }
+ result.addAll(ids);
+ }
+ return result;
+ }
+
+
+}
\ No newline at end of file
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/AbstractWikittyFileService.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/LoginInterceptor.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/LoginInterceptor.java 2011-07-20 15:26:30 UTC (rev 1081)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/LoginInterceptor.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -1,80 +0,0 @@
-/*
- * #%L
- * bow
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2010 - 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.nuiton.wikitty.publication;
-
-import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-import org.apache.struts2.ServletActionContext;
-import org.nuiton.wikitty.entities.WikittyUser;
-
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
-
-/**
- * Interceptor used to redirect a non-logged user if he tries to access a page
- * where logging is mandatory
- */
-public class LoginInterceptor extends AbstractInterceptor {
- private static final long serialVersionUID = -7520186185205372272L;
-
- protected String error;
-
- public String getError() {
- return error;
- }
-
- public void setError(String error) {
- this.error = error;
- }
-
- @Override
- public String intercept(ActionInvocation invocation) throws Exception {
-
- Map<String, Object> session = ActionContext.getContext().getSession();
-
- WikittyPublicationSession pubSession = WikittyPublicationSession
- .getWikittyPublicationSession(session);
- WikittyUser user = pubSession.getUser();
- String result = null;
-
- HttpServletRequest request = ServletActionContext.getRequest();
-
-
- // Construct redirect url.
- String redirect = request.getContextPath() + error ;
- redirect += "?success="+request.getServletPath();
-
- // If the user isn't logged in
- if (user == null) {
- ServletActionContext.getResponse().sendRedirect(redirect);
- } else {
- result = invocation.invoke();
- }
-
- return result;
- }
-
-}
Deleted: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/LogoutInterceptor.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/LogoutInterceptor.java 2011-07-20 15:26:30 UTC (rev 1081)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/LogoutInterceptor.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -1,51 +0,0 @@
-/*
- * #%L
- * bow
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2010 - 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.nuiton.wikitty.publication;
-
-import java.util.Map;
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
-
-/**
- * Interceptor used to remove all trace of user in session. Used for login page
- */
-public class LogoutInterceptor extends AbstractInterceptor {
-
- /**
- *
- */
- private static final long serialVersionUID = -66045004020326043L;
-
-
-
- @Override
- public String intercept(ActionInvocation invocation) throws Exception {
- Map<String, Object> session = ActionContext.getContext().getSession();
- WikittyPublicationSession.invalidate(session);
- String result = invocation.invoke();
- return result;
- }
-}
Copied: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/MimeTypePubHelper.java (from rev 1078, trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/MimeTypePubHelper.java)
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/MimeTypePubHelper.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/MimeTypePubHelper.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -0,0 +1,147 @@
+/*
+ * #%L
+ * Wikitty :: publication
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2010 - 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.wikitty.publication;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Class used to determine mimetype for an extension, used to determine type of
+ * wikittypub (data or text) with the extension and the mime type
+ *
+ *
+ * @author mfortun
+ *
+ */
+public class MimeTypePubHelper {
+
+ /**
+ * Mapping between extention and mime type, key: extension, value: mimeType
+ */
+ protected Map<String, String> mapExtensionMime;
+
+ /**
+ * White list of mime type that have to be transform as a wikittyPubText
+ */
+ protected List<String> mimePubText;
+
+ /**
+ * The default mime type
+ */
+ public static String DEFAULT_MIME_TYPE = "application/octet-stream";
+
+ public MimeTypePubHelper() {
+ this.mapExtensionMime = new HashMap<String, String>();
+ this.mimePubText = new ArrayList<String>();
+
+ // TODO create a property file to store and handle mimetype for pub
+ // text
+ mimePubText.add("application/javascript");
+
+ mapExtensionMime.put("wp", "application/javascript");
+ mapExtensionMime.put("js", "application/javascript");
+ mapExtensionMime.put("jpg", "image/jpeg");
+ mapExtensionMime.put("png", "image/png");
+ }
+
+ public Map<String, String> getMapExtensionMime() {
+ return mapExtensionMime;
+ }
+
+ public void setMapExtensionMime(Map<String, String> mapExtensionMime) {
+ this.mapExtensionMime = mapExtensionMime;
+ }
+
+ public List<String> getMimePubText() {
+ return mimePubText;
+ }
+
+ public void setMimePubText(List<String> mimePubText) {
+ this.mimePubText = mimePubText;
+ }
+
+ /**
+ * Return the corresponding mime Type for an extension, default if not
+ * recognized
+ *
+ * @param ext
+ * the extension
+ * @return the corresponding mimeTypeForExt DEFAULT_MIME_TYPE if ext not
+ * recognized
+ */
+ public String getMimeForExtension(String ext) {
+ String result = mapExtensionMime.get(ext);
+
+ if (result == null) {
+ result = DEFAULT_MIME_TYPE;
+ }
+
+ return result;
+ }
+
+ /**
+ * Used to check if a file have to be converted as a wikittyPubText
+ *
+ * @param mimeType
+ * of the file
+ * @return if the mimetype of a file correspond to a wikittyPubText
+ */
+ public boolean isPubTextMime(String mimeType) {
+ return mimePubText.contains(mimeType);
+ }
+
+ /**
+ * used to check if a file have to be converted as a wikittyPubText
+ * with his extension similar to :
+ * <br>isPubTextMime(getMimeForExtension(extension))</br>
+ * @param extension the file extension
+ * @return if the extension correspond to a wikittyPubText
+ */
+ public boolean isPubTextExtension(String extension) {
+ return isPubTextMime(getMimeForExtension(extension));
+ }
+
+ /**
+ * Add a mimeType corresponding to a WikittyPubText
+ *
+ * @param mime
+ */
+ public void addMimeForPubText(String mime) {
+ mimePubText.add(mime);
+ }
+
+ /**
+ * Add an entry in the map that store mapping between extension and
+ * mimeType.
+ *
+ * @param extension
+ * @param mime
+ */
+ public void addExtensionMime(String extension, String mime) {
+ mapExtensionMime.put(extension, mime);
+ }
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/MimeTypePubHelper.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision HeadURL
Copied: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java (from rev 1076, trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/PropertiesExtended.java)
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -0,0 +1,115 @@
+/*
+ * #%L
+ * Wikitty :: publication
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2010 - 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.wikitty.publication;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * Class usefull when load properties file, update, delete, then save again File
+ * used to load properties is store, and this allow to save again the properties
+ * inside the file used to load them.
+ *
+ * @author mfortun
+ *
+ */
+public class PropertiesExtended extends Properties {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -264337198024996529L;
+
+ /**
+ * The original file used to load and create properties
+ */
+ protected File origin;
+
+
+ public File getOrigin() {
+ return origin;
+ }
+
+ public void setOrigin(File origin) {
+ this.origin = origin;
+ }
+
+
+
+ /**
+ * Default constructor, need a file from whom load the properties. This is
+ * equivalent of a basic creation of properties and load after property from
+ * a file.
+ *
+ * @param origin
+ * the file from whom load the property, it is save for store.
+ * @throws IOException
+ * if error while reading the file
+ * @throws FileNotFoundException
+ * if file not found
+ */
+ public PropertiesExtended(File origin) throws FileNotFoundException,
+ IOException {
+ super();
+ this.load(origin);
+
+ }
+
+
+ /**
+ * Load the property from the file, and store the file, for storage.
+ *
+ * @param file
+ * the file from whom to load the property, it replace the file
+ * use to create this class
+ * @throws IOException
+ * if error while reading the file
+ * @throws FileNotFoundException
+ * if file not found
+ */
+ public void load(File file) throws FileNotFoundException, IOException {
+ this.origin = file;
+ this.load(new FileReader(origin));
+ }
+
+ /**
+ * Store the properties inside the last file used to load the property (or
+ * by default file used to create the class), equivalent of store(new
+ * FileWriter('File'),"");
+ *
+ * @throws IOException
+ * if error while reading the file
+ * @throws FileNotFoundException
+ * if file not found
+ */
+ public void store() throws IOException {
+ this.store(new FileWriter(origin), "");
+ }
+
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision HeadURL
Copied: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyFileUtil.java (from rev 1078, trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyFileUtil.java)
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyFileUtil.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyFileUtil.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -0,0 +1,93 @@
+package org.nuiton.wikitty.publication;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.FileUtil;
+import org.nuiton.util.StringUtil;
+
+/**
+ *
+ * Class that containt utils method when handle wikitty store as file.
+ *
+ * @author mfortun
+ *
+ */
+public class WikittyFileUtil {
+
+ /**
+ * The file name of the meta property file
+ */
+ static public String WIKITTY_FILE_META_PROPERTIES_FILE = "meta.properties";
+
+ /*
+ * Need a different file for id and meta information about wikittiesFiles
+ * because with this solution we can simply read the ids with props.keySet()
+ */
+ /**
+ * The file Name of the id property file
+ */
+ static public String WIKITTY_ID_PROPERTIES_FILE = "ids.properties";
+
+ final static Log log = LogFactory.getLog(WikittyFileUtil.class);
+
+ /**
+ * Construct correctly the path from a label
+ *
+ * @param label
+ * the label
+ * @return the correct path
+ */
+ public static String labelToPath(String label) {
+
+ String result = label;
+
+ result = result.replace(".", File.separator);
+
+ // correct the pb with directory name begin by .
+ result = result.replace(File.separator + File.separator, File.separator
+ + ".");
+
+ log.info("Convert label to path: " + label + " path:" + result);
+
+ return result;
+ }
+
+ /**
+ * Creates all the file system require from a label path in the working
+ * directory
+ *
+ * @param label
+ * the path string
+ * @return if all the path was created
+ * @throws IOException
+ */
+ public static boolean createFilesFromLabelPath(File homeFile, String label)
+ throws IOException {
+
+ label = labelToPath(label);
+
+ log.info("Create directory from path:" + label);
+
+ String[] pathElements = StringUtil.split(label, File.separator);
+
+ boolean result = false;
+
+ if (homeFile.exists() && homeFile.isDirectory()) {
+ String path = homeFile.getCanonicalPath();
+ result = true;
+ for (int i = 0; i < pathElements.length; i++) {
+
+ path = path + File.separator + pathElements[i];
+ File temp = new File(path);
+ FileUtil.createDirectoryIfNecessary(temp);
+ result = result && temp.exists();
+ }
+ }
+
+ return result;
+ }
+
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyFileUtil.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationConfig.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationConfig.java 2011-07-20 15:26:30 UTC (rev 1081)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationConfig.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -54,7 +54,7 @@
public enum Option implements ApplicationConfig.OptionDef {
CONFIG_FILE(ApplicationConfig.CONFIG_FILE_NAME,
_("wikitty-publication.config.configFileName.description"),
- "wikitty-publication-ws-jar.properties", String.class, false,
+ "wikitty-publication-ws-default.properties", String.class, false,
false);
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyPublicationExternalize.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyPublicationExternalize.java 2011-07-20 15:26:30 UTC (rev 1081)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyPublicationExternalize.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -15,15 +15,15 @@
import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.entities.WikittyLabel;
import org.nuiton.wikitty.entities.WikittyLabelHelper;
+import org.nuiton.wikitty.publication.PropertiesExtended;
+import org.nuiton.wikitty.publication.WikittyFileUtil;
import org.nuiton.wikitty.publication.WikittyPublicationConstant;
import org.nuiton.wikitty.publication.entities.WikittyPubData;
import org.nuiton.wikitty.publication.entities.WikittyPubDataHelper;
import org.nuiton.wikitty.publication.entities.WikittyPubText;
import org.nuiton.wikitty.publication.entities.WikittyPubTextHelper;
import org.nuiton.wikitty.publication.entities.WikittyPubTextImpl;
-import org.nuiton.wikitty.publication.synchro.PropertiesExtended;
-import org.nuiton.wikitty.publication.synchro.WikittyFileUtil;
-import org.nuiton.wikitty.publication.synchro.WikittyPublication;
+import org.nuiton.wikitty.publication.synchro.WikittyPublicationSynchronize;
import org.nuiton.wikitty.publication.synchro.WikittyPublicationFileSystem;
import org.nuiton.wikitty.search.Criteria;
import org.nuiton.wikitty.search.PagedResult;
@@ -71,7 +71,7 @@
String Label = currentFile.getName();
// String urlFileSystem = "file:///home/User/testWP#wp";
- String urlFileSystem = currentFile.getParent() + WikittyPublication.LABEL_DELIM + Label;
+ String urlFileSystem = currentFile.getParent() + WikittyPublicationSynchronize.LABEL_DELIM + Label;
appconfig.setOption(WikittyConfigOption.WIKITTY_SERVER_URL.getKey(),
urlFileSystem);
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyServiceJarLoader.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyServiceJarLoader.java 2011-07-20 15:26:30 UTC (rev 1081)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyServiceJarLoader.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -18,6 +18,9 @@
import org.nuiton.wikitty.entities.WikittyLabel;
import org.nuiton.wikitty.entities.WikittyLabelHelper;
import org.nuiton.wikitty.entities.WikittyLabelImpl;
+import org.nuiton.wikitty.publication.AbstractWikittyFileService;
+import org.nuiton.wikitty.publication.MimeTypePubHelper;
+import org.nuiton.wikitty.publication.WikittyFileUtil;
import org.nuiton.wikitty.publication.entities.WikittyPubData;
import org.nuiton.wikitty.publication.entities.WikittyPubDataHelper;
import org.nuiton.wikitty.publication.entities.WikittyPubDataImpl;
@@ -27,9 +30,6 @@
import org.nuiton.wikitty.publication.entities.WikittyPubTextCompiledImpl;
import org.nuiton.wikitty.publication.entities.WikittyPubTextHelper;
import org.nuiton.wikitty.publication.entities.WikittyPubTextImpl;
-import org.nuiton.wikitty.publication.synchro.AbstractWikittyFileService;
-import org.nuiton.wikitty.publication.synchro.MimeTypePubHelper;
-import org.nuiton.wikitty.publication.synchro.WikittyFileUtil;
import org.nuiton.wikitty.publication.synchro.WikittyPublicationFileSystem;
import org.nuiton.wikitty.search.Criteria;
import org.nuiton.wikitty.search.TreeNodeResult;
Copied: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/interceptor/LoginInterceptor.java (from rev 1076, trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/LoginInterceptor.java)
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/interceptor/LoginInterceptor.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/interceptor/LoginInterceptor.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -0,0 +1,81 @@
+/*
+ * #%L
+ * bow
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2010 - 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.nuiton.wikitty.publication.interceptor;
+
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import org.apache.struts2.ServletActionContext;
+import org.nuiton.wikitty.entities.WikittyUser;
+import org.nuiton.wikitty.publication.WikittyPublicationSession;
+
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
+
+/**
+ * Interceptor used to redirect a non-logged user if he tries to access a page
+ * where logging is mandatory
+ */
+public class LoginInterceptor extends AbstractInterceptor {
+ private static final long serialVersionUID = -7520186185205372272L;
+
+ protected String error;
+
+ public String getError() {
+ return error;
+ }
+
+ public void setError(String error) {
+ this.error = error;
+ }
+
+ @Override
+ public String intercept(ActionInvocation invocation) throws Exception {
+
+ Map<String, Object> session = ActionContext.getContext().getSession();
+
+ WikittyPublicationSession pubSession = WikittyPublicationSession
+ .getWikittyPublicationSession(session);
+ WikittyUser user = pubSession.getUser();
+ String result = null;
+
+ HttpServletRequest request = ServletActionContext.getRequest();
+
+
+ // Construct redirect url.
+ String redirect = request.getContextPath() + error ;
+ redirect += "?success="+request.getServletPath();
+
+ // If the user isn't logged in
+ if (user == null) {
+ ServletActionContext.getResponse().sendRedirect(redirect);
+ } else {
+ result = invocation.invoke();
+ }
+
+ return result;
+ }
+
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/interceptor/LoginInterceptor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision HeadURL
Copied: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/interceptor/LogoutInterceptor.java (from rev 1076, trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/LogoutInterceptor.java)
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/interceptor/LogoutInterceptor.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/interceptor/LogoutInterceptor.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -0,0 +1,53 @@
+/*
+ * #%L
+ * bow
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2010 - 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.nuiton.wikitty.publication.interceptor;
+
+import java.util.Map;
+
+import org.nuiton.wikitty.publication.WikittyPublicationSession;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
+
+/**
+ * Interceptor used to remove all trace of user in session. Used for login page
+ */
+public class LogoutInterceptor extends AbstractInterceptor {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -66045004020326043L;
+
+
+
+ @Override
+ public String intercept(ActionInvocation invocation) throws Exception {
+ Map<String, Object> session = ActionContext.getContext().getSession();
+ WikittyPublicationSession.invalidate(session);
+ String result = invocation.invoke();
+ return result;
+ }
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/interceptor/LogoutInterceptor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision HeadURL
Deleted: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/AbstractWikittyFileService.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/AbstractWikittyFileService.java 2011-07-20 15:26:30 UTC (rev 1081)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/AbstractWikittyFileService.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -1,541 +0,0 @@
-package org.nuiton.wikitty.publication.synchro;
-
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.wikitty.WikittyException;
-import org.nuiton.wikitty.WikittyService;
-import org.nuiton.wikitty.WikittyUtil;
-import org.nuiton.wikitty.entities.FieldType;
-import org.nuiton.wikitty.entities.FieldType.TYPE;
-import org.nuiton.wikitty.entities.Wikitty;
-import org.nuiton.wikitty.search.Criteria;
-import org.nuiton.wikitty.search.PagedResult;
-import org.nuiton.wikitty.search.operators.And;
-import org.nuiton.wikitty.search.operators.AssociatedRestriction;
-import org.nuiton.wikitty.search.operators.Between;
-import org.nuiton.wikitty.search.operators.BinaryOperator;
-import org.nuiton.wikitty.search.operators.Contains;
-import org.nuiton.wikitty.search.operators.Element;
-import org.nuiton.wikitty.search.operators.False;
-import org.nuiton.wikitty.search.operators.In;
-import org.nuiton.wikitty.search.operators.Keyword;
-import org.nuiton.wikitty.search.operators.Not;
-import org.nuiton.wikitty.search.operators.Null;
-import org.nuiton.wikitty.search.operators.Or;
-import org.nuiton.wikitty.search.operators.Restriction;
-import org.nuiton.wikitty.search.operators.RestrictionName;
-import org.nuiton.wikitty.search.operators.True;
-
-
-/**
- * This service must be extends by wikitty service that are over file system
- * directly or this kind of storage for wikitty.
- *
- *
- *
- * @author mfortun
- *
- */
-public abstract class AbstractWikittyFileService implements WikittyService{
-
-
- final static Log log = LogFactory.getLog(AbstractWikittyFileService.class);
-
- public AbstractWikittyFileService() {
- super();
- }
-
- /**
- * Method that must be implemented by the extended service. This must return
- * all the wikitty stored. The result will be use to checkrestriction for
- * a find.
- * @return a Map with wikittyId as Key and wikitty as value
- */
- protected abstract Map<String, Wikitty> getAllWikitties();
-
-
-
- /**
- * Write by jcouteau, used to check if a wikitty check a restriction
- *
- * @see org.nuiton.wikitty.storage.WikittySearchEngineInMemory#checkRestriction
- *
- * @param restriction
- * the restriction
- * @param w
- * the wikitty to check
- * @return if the wikitty check the restriction
- */
- public boolean checkRestriction(Restriction restriction, Wikitty w) {
-
-
- if (restriction instanceof BinaryOperator) {
- BinaryOperator binOp = (BinaryOperator) restriction;
-
- String fqfieldName = binOp.getElement().getName();
-
- // Checks on extensions
- if (Element.ELT_EXTENSION.equals(fqfieldName)) {
- boolean checked = false;
-
- switch (restriction.getName()) {
- case NOT_EQUALS:
- checked = !w.getExtensionNames().contains(binOp.getValue());
- break;
- case EQUALS:
- checked = w.getExtensionNames().contains(binOp.getValue());
- break;
- }
-
- return checked;
-
- // Checks on id
- } else if (Element.ELT_ID.equals(fqfieldName)) {
-
- boolean checked = false;
-
- switch (restriction.getName()) {
- case NOT_EQUALS:
- checked = !w.getId().equals(binOp.getValue());
- break;
- case EQUALS:
- checked = w.getId().equals(binOp.getValue());
- break;
- }
-
- return checked;
- }
-
- // si les wikitty n'ont meme pas l'extension concerné
- // Le check restriction, ne doit pas tester les champs
- // si les wikitty n'ont meme pas l'extension concerné
- String[] extName = fqfieldName.split("\\.");
- if (!w.hasField(extName[0], extName[1])) {
-
- // return true in case of not equals
- if (RestrictionName.NOT_EQUALS == restriction.getName()) {
- return true;
- }
-
- return false;
- }
- // recupere la valeur dans le wikitty
- Object o = w.getFqField(fqfieldName);
-
- // recupere le type de la valeur
- FieldType t = w.getFieldType(fqfieldName);
- // convertie la valeur a verifier dans le meme type que la valeur
- // du wikitty
- Object value = binOp.getValue();
- if (!(value instanceof Collection) && t.isCollection()) {
- // on doit encapsuler dans une collection, car la creation
- // de la requete ajoute autant de v == o && ... que de valeurs
- // dans la collection (champs multi-value solr). Mais
- // dans le inmemory on doit retrouve des collections et non pas
- // des objets seuls :(
- value = Collections.singleton(value);
- }
- value = t.getValidValue(value);
-
- boolean checked = false;
-
- switch (restriction.getName()) {
- case EQUALS:
-
- if (value instanceof String && o instanceof String) {
- String pattern = (String) value;
- pattern = pattern.replace("*", "\\p{ASCII}*");
- pattern = pattern.replace("?", "\\p{ASCII}");
-
- Pattern p = Pattern.compile(pattern);
- Matcher m = p.matcher((String) o);
- checked = m.matches();
- } else {
- checked = value.equals(o);
- }
- break;
- case LESS:
- checked = ((Comparable) o).compareTo(value) < 0;
- break;
- case LESS_OR_EQUAL:
- checked = ((Comparable) o).compareTo(value) <= 0;
- break;
- case GREATER:
- checked = ((Comparable) o).compareTo(value) > 0;
- break;
- case GREATER_OR_EQUAL:
- checked = ((Comparable) o).compareTo(value) >= 0;
- break;
- case NOT_EQUALS:
- checked = !value.equals(o);
- break;
- case ENDS_WITH:
- if (t.getType() != TYPE.STRING) {
- throw new WikittyException(
- "Can't search for contents that 'ends with' on attribute type different of String. "
- + "Attribute "
- + fqfieldName
- + " is "
- + t.getType().name());
- }
- checked = ((String) o).endsWith((String) value);
- break;
- case STARTS_WITH:
- if (t.getType() != TYPE.STRING) {
- throw new WikittyException(
- "Can't search for contents that 'starts with' on attribute type different of String. "
- + "Attribute "
- + fqfieldName
- + " is "
- + t.getType().name());
- }
-
- // FIXME mfortun-2011-04-20 rustine pour champs multivalué de
- // type string
- // et restriction startwith dessus. ça marche mais faudrait
- // quelque chose de plus
- // propre, et surtout généraliser pour toutes les restrictions
-
- if (o instanceof Collection<?>
- && value instanceof Collection<?>) {
-
- for (Object val : (Collection) value) {
-
- String valu = (String) val;
-
- for (Object oo : (Collection) o) {
- String cotainedO = (String) oo;
- if (cotainedO != null) {
- checked = checked || cotainedO.startsWith(valu);
- }
- }
-
- }
-
- } else {
-
- checked = ((String) o).startsWith((String) value);
- }
- break;
- }
- return checked;
- } else if (restriction instanceof Null) {
- Null nullRes = (Null) restriction;
-
- String fqfieldName = nullRes.getFieldName();
-
- // check my wikitty got the right extension before doing anything.
- String[] extName = fqfieldName.split("\\.");
- if (!w.hasField(extName[0], extName[1])) {
- return false;
- }
- // get the value in the wikitty
- Object o = w.getFqField(fqfieldName);
-
- // No null on extensions, always return false
- if (fqfieldName.equals(Element.ELT_EXTENSION)) {
- return false;
- }
-
- // No null on ids, always return false
- if (fqfieldName.equals(Element.ELT_ID)) {
- return false;
- }
-
- boolean checked = false;
-
- switch (nullRes.getName()) {
- case IS_NULL:
- checked = (o == null);
- break;
- case IS_NOT_NULL:
- checked = (o != null);
- break;
- }
-
- return checked;
-
- } else if (restriction instanceof In) {
- In in = (In) restriction;
- String fqfieldName = in.getElement().getName();
- String testedValue = String.valueOf(w.getFqField(fqfieldName));
- for (String value : in.getValue()) {
- if (testedValue.equals(value)) {
- return true;
- }
- }
-
- return false;
-
- } else if (restriction instanceof True) {
- return true;
- } else if (restriction instanceof False) {
- return false;
- } else if (restriction instanceof Contains) {
- Contains contains = (Contains) restriction;
-
- String fqfieldName = contains.getElement().getName();
- List<String> values = contains.getValue();
-
- String extension = WikittyUtil
- .getExtensionNameFromFQFieldName(fqfieldName);
- String fieldName = WikittyUtil
- .getFieldNameFromFQFieldName(fqfieldName);
-
- if (!w.hasField(extension, fieldName)) {
- return false;
- }
-
- // Get field as string and then split it to take into account not
- // multivalued fields.
- String testedValuesAsString = w.getFieldAsString(extension,
- fieldName);
-
- if ('[' == testedValuesAsString.charAt(0)) {
- testedValuesAsString = testedValuesAsString.substring(1,
- testedValuesAsString.length());
- }
-
- List<String> testedValues = Arrays.asList(testedValuesAsString
- .split(","));
-
- for (Object value : values) {
- if (!testedValues.contains(String.valueOf(value))) {
- return false;
- }
- }
-
- return true;
-
- } else if (restriction instanceof And) {
- And and = (And) restriction;
- for (Restriction sub : and.getRestrictions()) {
- if (!checkRestriction(sub, w)) {
- return false;
- }
- }
- return true;
- } else if (restriction instanceof Or) {
- Or or = (Or) restriction;
- for (Restriction sub : or.getRestrictions()) {
- if (checkRestriction(sub, w)) {
- return true;
- }
- }
- return false;
- } else if (restriction instanceof Keyword) {
- Keyword keyword = (Keyword) restriction;
-
- String value = keyword.getValue();
-
- //TODO mfortun-2011-07-06 hack to ensure that * is intepreted as
- // the real meaning aka any
- if (value.equals("*")){
- return true;
- }
-
- for (String fieldName : w.getAllFieldNames()) {
- String testedValue = String.valueOf(w.getFqField(fieldName));
- if (testedValue.contains(value)) {
- return true;
- }
- }
- return false;
- } else if (restriction instanceof Not) {
- Not or = (Not) restriction;
- Restriction sub = or.getRestriction();
- return !checkRestriction(sub, w);
- } else if (restriction instanceof AssociatedRestriction) {
-
- AssociatedRestriction ass = (AssociatedRestriction) restriction;
-
- String fqfieldName = ass.getElement().getName();
-
- // check my wikitty got the right extension before doing anything.
- String[] extName = fqfieldName.split("\\.");
- if (!w.hasField(extName[0], extName[1])) {
- return false;
- }
- // get the value in the wikitty, it is a wikitty's id
- Object o = w.getFqField(fqfieldName);
-
- // Get sub-restriction
- Restriction sub = ass.getRestriction();
-
- Criteria associatedSearch = new Criteria();
- associatedSearch.setRestriction(sub);
-
- // find everything that validate the sub-restriction
-
- List<Criteria> dummyList = new ArrayList<Criteria>();
- dummyList.add(associatedSearch);
- // same as proxy for "fix" unique param to list param
- PagedResult<String> associatedResult = findAllByCriteria("",
- dummyList).get(0);
-
- List<String> associatedList = associatedResult.getAll();
-
- // Check that my field is contained in the sub-restriction results.
- return associatedList.contains(String.valueOf(o));
- } else if (restriction instanceof Between) {
-
- Between op = (Between) restriction;
-
- Object max = op.getMax();
- Object min = op.getMin();
-
- // No between on extensions, always return false
- if (op.getElement().getName().equals(Element.ELT_EXTENSION)) {
- return false;
- }
-
- // No between on ids, always return false
- if (op.getElement().getName().equals(Element.ELT_ID)) {
- return false;
- }
-
- String fqfieldName = op.getElement().getName();
-
- // si les wikitty n'ont meme pas l'extension concerné
- // Le check restriction, ne doit pas tester les champs
- // si les wikitty n'ont meme pas l'extension concerné
- String[] extName = fqfieldName.split("\\.");
- if (!w.hasField(extName[0], extName[1])) {
- return false;
- }
-
- // recupere la valeur dans le wikitty
- Object o = w.getFqField(fqfieldName);
-
- // recupere le type de la valeur
- FieldType t = w.getFieldType(fqfieldName);
-
- if (!(min instanceof Collection) && t.isCollection()) {
- // on doit encapsuler dans une collection, car la creation
- // de la requete ajoute autant de v == o && ... que de valeurs
- // dans la collection (champs multi-value solr). Mais
- // dans le inmemory on doit retrouve des collections et non pas
- // des objets seuls :(
- min = Collections.singleton(min);
- }
- min = t.getValidValue(min);
-
- if (!(max instanceof Collection) && t.isCollection()) {
- // on doit encapsuler dans une collection, car la creation
- // de la requete ajoute autant de v == o && ... que de valeurs
- // dans la collection (champs multi-value solr). Mais
- // dans le inmemory on doit retrouve des collections et non pas
- // des objets seuls :(
- max = Collections.singleton(max);
- }
- max = t.getValidValue(max);
-
- return ((Comparable) o).compareTo(min) >= 0
- && ((Comparable) o).compareTo(max) <= 0;
- } else {
- throw new UnsupportedOperationException(restriction.getName()
- + " Search Not yet implemented");
- }
- }
-
-
- @Override
- public List<PagedResult<String>> findAllByCriteria(String securityToken,
- List<Criteria> criteria) {
-
-
- List<PagedResult<String>> result = new ArrayList<PagedResult<String>>();
-
- Map<String, Wikitty> wikitties = getAllWikitties();
-
- // for each criteria
- for (Criteria cr : criteria) {
- // prepare restriction on result
- int firstIndex = cr.getFirstIndex();
- int endIndex = cr.getEndIndex();
- List<String> ids = new LinkedList<String>();
- int currentIndex = 0;
- Restriction restriction = cr.getRestriction();
- // for each wikitty check if it match the resttriction
- for (Entry<String, Wikitty> entry : wikitties.entrySet()) {
- String id = entry.getKey();
- Wikitty w = entry.getValue();
- // if macth
-
-
- if (checkRestriction(restriction, w)) {
-
- // increment result number
- currentIndex++;
- if (currentIndex > firstIndex) {
- ids.add(id);
- }
- // if the number of wikitty found is match
- // stop the search for other wikitty
- if (endIndex >= 0 && currentIndex >= endIndex) {
- break;
- }
- }
- }
- result.add(new PagedResult<String>(firstIndex, ids.size(),
- restriction.toString(), null, ids));
-
- }
- return result;
- }
-
-
- @Override
- public List<String> findByCriteria(String securityToken,
- List<Criteria> criteria) {
- List<String> result = new ArrayList<String>();
-
- Map<String, Wikitty> wikitties = getAllWikitties();
- // for each criteria
- for (Criteria cr : criteria) {
- // prepare restriction on result
- int firstIndex = cr.getFirstIndex();
- int endIndex = cr.getEndIndex();
- List<String> ids = new LinkedList<String>();
- int currentIndex = 0;
- Restriction restriction = cr.getRestriction();
- // for each wikitty check if it match the resttriction
- for (Entry<String, Wikitty> entry : wikitties.entrySet()) {
- String id = entry.getKey();
- Wikitty w = entry.getValue();
- // if macth
-
- log.debug("Check restriction for wikitty: " + w
- + " Restriction:" + restriction);
-
- if (checkRestriction(restriction, w)) {
- // increment result number
- currentIndex++;
- if (currentIndex > firstIndex) {
- ids.add(id);
- }
- // if the number of wikitty found is match
- // stop the search for other wikitty
- if (endIndex >= 0 && currentIndex >= endIndex) {
- break;
- }
- }
- }
- result.addAll(ids);
- }
- return result;
- }
-
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/MimeTypePubHelper.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/MimeTypePubHelper.java 2011-07-20 15:26:30 UTC (rev 1081)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/MimeTypePubHelper.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -1,147 +0,0 @@
-/*
- * #%L
- * Wikitty :: publication
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2010 - 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.wikitty.publication.synchro;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Class used to determine mimetype for an extension, used to determine type of
- * wikittypub (data or text) with the extension and the mime type
- *
- *
- * @author mfortun
- *
- */
-public class MimeTypePubHelper {
-
- /**
- * Mapping between extention and mime type, key: extension, value: mimeType
- */
- protected Map<String, String> mapExtensionMime;
-
- /**
- * White list of mime type that have to be transform as a wikittyPubText
- */
- protected List<String> mimePubText;
-
- /**
- * The default mime type
- */
- public static String DEFAULT_MIME_TYPE = "application/octet-stream";
-
- public MimeTypePubHelper() {
- this.mapExtensionMime = new HashMap<String, String>();
- this.mimePubText = new ArrayList<String>();
-
- // TODO create a property file to store and handle mimetype for pub
- // text
- mimePubText.add("application/javascript");
-
- mapExtensionMime.put("wp", "application/javascript");
- mapExtensionMime.put("js", "application/javascript");
- mapExtensionMime.put("jpg", "image/jpeg");
- mapExtensionMime.put("png", "image/png");
- }
-
- public Map<String, String> getMapExtensionMime() {
- return mapExtensionMime;
- }
-
- public void setMapExtensionMime(Map<String, String> mapExtensionMime) {
- this.mapExtensionMime = mapExtensionMime;
- }
-
- public List<String> getMimePubText() {
- return mimePubText;
- }
-
- public void setMimePubText(List<String> mimePubText) {
- this.mimePubText = mimePubText;
- }
-
- /**
- * Return the corresponding mime Type for an extension, default if not
- * recognized
- *
- * @param ext
- * the extension
- * @return the corresponding mimeTypeForExt DEFAULT_MIME_TYPE if ext not
- * recognized
- */
- public String getMimeForExtension(String ext) {
- String result = mapExtensionMime.get(ext);
-
- if (result == null) {
- result = DEFAULT_MIME_TYPE;
- }
-
- return result;
- }
-
- /**
- * Used to check if a file have to be converted as a wikittyPubText
- *
- * @param mimeType
- * of the file
- * @return if the mimetype of a file correspond to a wikittyPubText
- */
- public boolean isPubTextMime(String mimeType) {
- return mimePubText.contains(mimeType);
- }
-
- /**
- * used to check if a file have to be converted as a wikittyPubText
- * with his extension similar to :
- * <br>isPubTextMime(getMimeForExtension(extension))</br>
- * @param extension the file extension
- * @return if the extension correspond to a wikittyPubText
- */
- public boolean isPubTextExtension(String extension) {
- return isPubTextMime(getMimeForExtension(extension));
- }
-
- /**
- * Add a mimeType corresponding to a WikittyPubText
- *
- * @param mime
- */
- public void addMimeForPubText(String mime) {
- mimePubText.add(mime);
- }
-
- /**
- * Add an entry in the map that store mapping between extension and
- * mimeType.
- *
- * @param extension
- * @param mime
- */
- public void addExtensionMime(String extension, String mime) {
- mapExtensionMime.put(extension, mime);
- }
-}
Deleted: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/PropertiesExtended.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/PropertiesExtended.java 2011-07-20 15:26:30 UTC (rev 1081)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/PropertiesExtended.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -1,115 +0,0 @@
-/*
- * #%L
- * Wikitty :: publication
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2010 - 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.wikitty.publication.synchro;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.Properties;
-
-/**
- * Class usefull when load properties file, update, delete, then save again File
- * used to load properties is store, and this allow to save again the properties
- * inside the file used to load them.
- *
- * @author mfortun
- *
- */
-public class PropertiesExtended extends Properties {
-
- /**
- *
- */
- private static final long serialVersionUID = -264337198024996529L;
-
- /**
- * The original file used to load and create properties
- */
- protected File origin;
-
-
- public File getOrigin() {
- return origin;
- }
-
- public void setOrigin(File origin) {
- this.origin = origin;
- }
-
-
-
- /**
- * Default constructor, need a file from whom load the properties. This is
- * equivalent of a basic creation of properties and load after property from
- * a file.
- *
- * @param origin
- * the file from whom load the property, it is save for store.
- * @throws IOException
- * if error while reading the file
- * @throws FileNotFoundException
- * if file not found
- */
- public PropertiesExtended(File origin) throws FileNotFoundException,
- IOException {
- super();
- this.load(origin);
-
- }
-
-
- /**
- * Load the property from the file, and store the file, for storage.
- *
- * @param file
- * the file from whom to load the property, it replace the file
- * use to create this class
- * @throws IOException
- * if error while reading the file
- * @throws FileNotFoundException
- * if file not found
- */
- public void load(File file) throws FileNotFoundException, IOException {
- this.origin = file;
- this.load(new FileReader(origin));
- }
-
- /**
- * Store the properties inside the last file used to load the property (or
- * by default file used to create the class), equivalent of store(new
- * FileWriter('File'),"");
- *
- * @throws IOException
- * if error while reading the file
- * @throws FileNotFoundException
- * if file not found
- */
- public void store() throws IOException {
- this.store(new FileWriter(origin), "");
- }
-
-}
Deleted: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyFileUtil.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyFileUtil.java 2011-07-20 15:26:30 UTC (rev 1081)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyFileUtil.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -1,96 +0,0 @@
-package org.nuiton.wikitty.publication.synchro;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.FileUtil;
-import org.nuiton.util.StringUtil;
-
-
-/**
- *
- * Class that containt utils method when handle wikitty store as file.
- *
- * @author mfortun
- *
- */
-public class WikittyFileUtil {
-
- /**
- * The file name of the meta property file
- */
- static public String WIKITTY_FILE_META_PROPERTIES_FILE = "meta.properties";
-
- /*
- * Need a different file for id and meta information about wikittiesFiles
- * because with this solution we can simply read the ids with props.keySet()
- */
- /**
- * The file Name of the id property file
- */
- static public String WIKITTY_ID_PROPERTIES_FILE = "ids.properties";
-
-
-
- final static Log log = LogFactory.getLog(WikittyFileUtil.class);
-
- /**
- * Construct correctly the path from a label
- *
- * @param label
- * the label
- * @return the correct path
- */
- public static String labelToPath(String label) {
-
- String result = label;
-
- result = result.replace(".", File.separator);
-
- // correct the pb with directory name begin by .
- result = result.replace(File.separator + File.separator, File.separator
- + ".");
-
- log.info("Convert label to path: " + label + " path:" + result);
-
- return result;
- }
-
- /**
- * Creates all the file system require from a label path in the working
- * directory
- *
- * @param label
- * the path string
- * @return if all the path was created
- * @throws IOException
- */
- public static boolean createFilesFromLabelPath(File homeFile, String label) throws IOException
- {
-
- label = labelToPath(label);
-
- log.info("Create directory from path:" + label);
-
- String[] pathElements = StringUtil.split(label, File.separator);
-
- boolean result = false;
-
- if (homeFile.exists() && homeFile.isDirectory()) {
- String path = homeFile.getCanonicalPath();
- result = true;
- for (int i = 0; i < pathElements.length; i++) {
-
- path = path + File.separator + pathElements[i];
- File temp = new File(path);
- FileUtil.createDirectoryIfNecessary(temp);
- result = result && temp.exists();
- }
- }
-
- return result;
- }
-
-}
Deleted: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-07-20 15:26:30 UTC (rev 1081)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -1,678 +0,0 @@
-/*
- * #%L
- * Wikitty :: publication
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2010 - 2011 CodeLutin mfortun
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.wikitty.publication.synchro;
-
-import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.ApplicationConfig;
-import org.nuiton.util.ArgumentsParserException;
-import org.nuiton.util.FileUtil;
-import org.nuiton.wikitty.WikittyConfigOption;
-import org.nuiton.wikitty.WikittyProxy;
-import org.nuiton.wikitty.WikittyServiceFactory;
-import org.nuiton.wikitty.WikittyUtil;
-import org.nuiton.wikitty.entities.Wikitty;
-import org.nuiton.wikitty.entities.WikittyLabel;
-import org.nuiton.wikitty.entities.WikittyLabelHelper;
-import org.nuiton.wikitty.publication.entities.WikittyPubData;
-import org.nuiton.wikitty.publication.entities.WikittyPubText;
-import org.nuiton.wikitty.search.Criteria;
-import org.nuiton.wikitty.search.Search;
-
-/**
- * Main class of the sync part of wikitty publication, this class is the entry
- * point for sync operation. Existing, delete and update.
- *
- *
- * @author mfortun
- *
- */
-public class WikittyPublication {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- final static private Log log = LogFactory.getLog(WikittyPublication.class);
-
- /**
- * Key for the other uri, usefull in the case of commit/update with a file
- * system wikitty service.
- */
- static public String WIKITTY_SERVICE_INTERLOCUTEUR = "wikitty.service.interlocuteur";
-
- static protected ApplicationConfig applicationConfig;
-
- /**
- * for recursion option
- */
- static public String IS_RECURSION_OPTION = "isRecur";
- /**
- * for delete option
- */
- static public String IS_DELETE_OPTION = "delete";
- /**
- * for existing option
- */
- static public String IS_EXISTING_OPTION = "existing";
-
- /**
- * Use to save the label by the wikitty publication file system
- */
- static public String LABEL_KEY = "working.label";
-
- /**
- * the string that mark the beginnning of the label
- */
- static public String LABEL_DELIM = "#";
- /**
- * regex to select the label part of the uri
- */
- static public String LABEL_REGEX = "\\#.*";
-
- /**
- * the prefix use in file url
- */
- static public String FILE_URI_PREFIX = "file";
-
- /**
- * the prefix use in cajo url
- */
- static public String CAJO_URI_PREFIX = "cajo";
-
- /**
- * the prefix use in hessian url
- */
- static public String HESSIAN_URI_PREFIX = "hessian";
-
-
-
- /*
- * Class don't have to be instantiate
- */
- private WikittyPublication() {
-
- }
-
- /**
- * @param args
- * @throws ArgumentsParserException
- */
- static public void main(String[] args) throws Exception {
-
- applicationConfig = new ApplicationConfig();
-
- /*
- * TODO mfortun-2011-04-14 construct option def instance to initialize
- * correctly application config
- */
-
- applicationConfig.setDefaultOption(IS_DELETE_OPTION, "false");
- applicationConfig.setDefaultOption(IS_EXISTING_OPTION, "false");
- applicationConfig.setDefaultOption(IS_RECURSION_OPTION, "true");
-
- // allias for norecursion
- applicationConfig.addAlias("--norecursion", "--option",
- WikittyPublication.IS_RECURSION_OPTION, "false");
-
- applicationConfig.addAlias("--delete", "--option", IS_DELETE_OPTION,
- "true");
-
- applicationConfig.addAlias("--existing", "--option",
- IS_EXISTING_OPTION, "true");
-
- // allias for all the action
- applicationConfig.addAlias("wp sync", "--option", "sync");
-
- applicationConfig.addAlias("wp commit", "--option", "commit");
-
- applicationConfig.addAlias("wp update", "--option", "update");
-
- applicationConfig
- .addActionAlias("sync",
- "org.nuiton.wikitty.publication.synchro.WikittyPublication#synchronisation");
-
- applicationConfig
- .addActionAlias("commit",
- "org.nuiton.wikitty.publication.synchro.WikittyPublication#commit");
-
- applicationConfig
- .addActionAlias("update",
- "org.nuiton.wikitty.publication.synchro.WikittyPublication#update");
- // parsing
- applicationConfig.parse(args);
-
- // execution
- applicationConfig.doAction(0);
-
- }
-
- static public void synchronisation(String origin, String target)
- throws URISyntaxException {
-
- boolean isRecur = applicationConfig
- .getOptionAsBoolean(IS_RECURSION_OPTION);
-
- boolean isDelete = applicationConfig
- .getOptionAsBoolean(IS_DELETE_OPTION);
- boolean isExisting = applicationConfig
- .getOptionAsBoolean(IS_EXISTING_OPTION);
- // update operation is the default operation
- boolean isUpdate = !isDelete && !isExisting;
-
- log.info("Sync uri origin: " + origin + " uri target: " + target
- + " isRecur:" + isRecur + " isUpdate:" + isUpdate
- + " isDelete:" + isDelete + "isExisting:" + isExisting);
-
- URI uriOrigin = new URI(origin);
-
- URI uriTarget = new URI(target);
-
- /*
- * necessary to have property correctly initialize in order to obtain
- * the correct implementation of the wikitty service
- */
-
- // once on the service origin
- applicationConfig.setOption(WIKITTY_SERVICE_INTERLOCUTEUR, new String(
- target.replaceAll(LABEL_REGEX, StringUtils.EMPTY)));
-
- ApplicationConfig temp1 = setUpApplicationConfigServerConnector(uriOrigin);
-
- WikittyProxy proxyOrigin = new WikittyProxy(
- WikittyServiceFactory.buildWikittyService(temp1));
-
- // store the other uri in the application, if the service is a
- // wikittypublication file system
- // it can need it to store wikittyservice property
- applicationConfig.setOption(WIKITTY_SERVICE_INTERLOCUTEUR, new String(
- origin.replaceAll(LABEL_REGEX, StringUtils.EMPTY)));
- // once on the service target
- ApplicationConfig temp2 = setUpApplicationConfigServerConnector(uriTarget);
-
- WikittyProxy proxyTarget = new WikittyProxy(
- WikittyServiceFactory.buildWikittyService(temp2));
-
- String labelOrigin = uriOrigin.getFragment();
- String labelTarget = uriTarget.getFragment();
-
- Criteria critOrigin = constructCriteriaLabelRecur(labelOrigin, isRecur);
- Criteria critTarget = constructCriteriaLabelRecur(labelTarget, isRecur);
-
- List<String> listOrigin = proxyOrigin.findAllIdByCriteria(critOrigin)
- .getAll();
- List<String> listTarget = proxyTarget.findAllIdByCriteria(critTarget)
- .getAll();
-
- // construct list of wikitty contained in both location
- List<String> existInBoth = new ArrayList<String>();
- existInBoth.addAll(listOrigin);
- existInBoth.retainAll(listTarget);
-
- // construct list of wikitty contained only in origin location
- List<String> existOnlyOnOrigin = new ArrayList<String>();
- existOnlyOnOrigin.addAll(listOrigin);
- existOnlyOnOrigin.removeAll(listTarget);
-
- // construct list of wikitty contained only in target location
- List<String> existOnlyOnTarget = new ArrayList<String>();
- existOnlyOnTarget.addAll(listTarget);
- existOnlyOnTarget.removeAll(listOrigin);
-
- if (log.isDebugEnabled()) {
- log.debug("Wikitty exist on both: " + existInBoth.size());
- for (String ex : existInBoth) {
- log.debug(ex);
- }
-
- log.debug("Wikitty exist only on origin: "
- + existOnlyOnOrigin.size());
- for (String ex : existOnlyOnOrigin) {
- log.debug(ex);
- }
-
- log.debug("Wikitty exist only on target: "
- + existOnlyOnTarget.size());
- for (String ex : existOnlyOnTarget) {
- log.debug(ex);
- }
- }
-
- /*
- * FIXME mfortun-2011-04-27 remove all that stuff for the safety of the
- * version when a solution rise for the wikitty version
- */
-
- /*
- * if option is update send wikitty that are not in the target.
- */
- if (isUpdate) {
-
- log.info("Store on target new wikitty");
-
- List<Wikitty> newWikitties = proxyOrigin.restore(existOnlyOnOrigin);
-
- for (Wikitty wikittyNew : newWikitties) {
-
- Set<String> saveLabelOrigin = WikittyLabelHelper
- .getLabels(wikittyNew);
-
- Set<String> targetLabels = new HashSet<String>();
-
- // prepare set of target label
- // we save all the label except the one corresponding
- // to origin, determine by isRecur
- for (String labels : saveLabelOrigin) {
-
- if (isRecur && labels.startsWith(labelOrigin)) {
- String finalLabelTarge = new String(labels.replace(
- labelOrigin, labelTarget));
- targetLabels.add(finalLabelTarge);
- } else if (!isRecur && labels.equals(labelOrigin)) {
- targetLabels.add(labelTarget);
- } else {
- targetLabels.add(labels);
- }
-
- }
-
- // save the version before reset label
- String wikittyVersionLocal = wikittyNew.getVersion();
- WikittyLabelHelper.setLabels(wikittyNew, targetLabels);
- // restore the version
- wikittyNew.setVersion(wikittyVersionLocal);
- proxyTarget.store(wikittyNew);
-
- String versionSaveTarget = wikittyNew.getVersion();
-
- WikittyLabelHelper.setLabels(wikittyNew, saveLabelOrigin);
- wikittyNew.setVersion(versionSaveTarget);
-
- // we re store on the origin to ensure wikitty version
-
- try {
- proxyOrigin.store(wikittyNew);
- } catch (Exception e) {
-
- // FIXME when a wikitty service store a
- // wikitty that he does'nt know
- // he set the version to 1.0
- e.printStackTrace();
- }
- }
-
- }
- /*
- * if option delete remove those who are on the target but not on origin
- */
- if (isDelete) {
-
- log.info("Remove from target deleted wikitty");
-
- for (String id : existOnlyOnTarget) {
-
- Wikitty w = proxyTarget.restore(id);
-
- WikittyLabelHelper.removeLabels(w, labelTarget);
-
- proxyTarget.store(w);
-
- }
- } else {
-
- log.info("Update existing wikitty");
- /*
- * case existing and update, update those which are on both location
- */
- for (String id : existInBoth) {
- Wikitty fromTarget = proxyTarget.restore(id);
- Wikitty fromOrigin = proxyOrigin.restore(id);
-
- String versionTarget = fromTarget.getVersion();
-
- String versionOrigin = fromOrigin.getVersion();
-
- // check version for update
-
- /*
- * we replace origin labels by target's labels if we udpate.
- */
- if (WikittyUtil
- .versionGreaterThan(versionOrigin, versionTarget)) {
- Set<String> setLabelTarget = WikittyLabelHelper
- .getLabels(fromTarget);
-
- Set<String> setLabelOrigin = WikittyLabelHelper
- .getLabels(fromOrigin);
-
- // save version before reset the label
- String versionLocalSave = fromOrigin.getVersion();
- // replace labels origins, by targets label
- WikittyLabelHelper.setLabels(fromOrigin, setLabelTarget);
- // restore the version
- fromOrigin.setVersion(versionLocalSave);
- // send modified origin to target wikitty service
- proxyTarget.store(fromOrigin);
- // re store on origin to ensure version is the same on both
-
- // save the version case re set labels increment version
- String saveVersion = fromOrigin.getVersion();
- // re set correctly labels
- WikittyLabelHelper.setLabels(fromOrigin, setLabelOrigin);
- // re set the version
- fromOrigin.setVersion(saveVersion);
-
- // re store the wikitty with the correct version
- // and labels
- proxyOrigin.store(fromOrigin);
- }
- }
-
- }// */
-
- }
-
- /**
- * Used to construct criteria on wikittypubdata and pubtext on the
- * wikittylabel extension
- *
- * @param label
- * the label criteria
- * @param isRecur
- * is recusion
- * @return the constructed criteria
- */
- static protected Criteria constructCriteriaLabelRecur(String label,
- boolean isRecur) {
-
- log.info("Construct criteria with label: " + label + " isRecur:"
- + isRecur);
-
- // Construct the criteria
- Criteria criteriaOnLabels;
- Search mainRequest = Search.query();
- Search subRoqu = mainRequest.or();
-
- // must have the type of wikittypubtext/wikittypubdata
- subRoqu.exteq(WikittyPubText.EXT_WIKITTYPUBTEXT).exteq(
- WikittyPubData.EXT_WIKITTYPUBDATA);
- if (isRecur) {
-
- // and extension with the name that containt the label (recursivity)
- criteriaOnLabels = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL)
- .sw(WikittyLabel.FQ_FIELD_WIKITTYLABEL_LABELS, label)
- .criteria();
-
- } else {
-
- // and extension with the name strictly equals to the label (no
- // recursivity)
- criteriaOnLabels = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL)
- .eq(WikittyLabel.FQ_FIELD_WIKITTYLABEL_LABELS, label)
- .criteria();
-
- }
-
- log.debug(criteriaOnLabels);
-
- return criteriaOnLabels;
-
- }
-
- /**
- * Use to setup correct url property in the application config and correct
- * component for the wikittyservice
- *
- * @param uri
- * of the targeted wikitty service
- */
- static protected ApplicationConfig setUpApplicationConfigServerConnector(
- URI uri) {
-
- log.info("Construct application config for uri: " + uri);
-
- // prepare new application config
- ApplicationConfig result = new ApplicationConfig();
-
- // transfert main properties to new application config
- result.setOptions(applicationConfig.getFlatOptions());
- String url = uri.toASCIIString();
-
- if (uri.getScheme().equals(FILE_URI_PREFIX)) {
-
- result.setOption(
- WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS
- .getKey(), WikittyPublicationFileSystem.class
- .getName());
- } else if (uri.getScheme().equals(CAJO_URI_PREFIX)) {
- result.setOption(
- WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS
- .getKey(),
- "org.nuiton.wikitty.services.WikittyServiceCajoClient");
-
- // remove fragment from the uri.
- url = new String(url.replaceAll(LABEL_REGEX, StringUtils.EMPTY));
-
- } else if (uri.getScheme().equals(HESSIAN_URI_PREFIX)) {
- result.setOption(
- WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS
- .getKey(),
- "org.nuiton.wikitty.services.WikittyServiceHessianClient");
- // remove fragment from the uri.
- url = new String(url.replaceAll(LABEL_REGEX, StringUtils.EMPTY));
- }
-
- // set protocol to http, no use finally
- /*
- * url = url.replaceFirst("["+uri.getScheme()+"]", "http");
- */
-
- log.info("set url "
- + url
- + " with component :"
- + result.getOption(WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS
- .getKey()));
-
- result.setOption(WikittyConfigOption.WIKITTY_SERVER_URL.getKey(), url);
-
- log.debug("Application config: " + result.getFlatOptions());
-
- return result;
-
- }
-
- static public void update(String label, String... uriFileSystem)
- throws Exception {
-
- // only difference between update and commit is the param's order
- // when calling synchronisation method
- commitUpdateDelegate(label, false, uriFileSystem);
-
- }
-
- static public void commit(String label, String... uriFileSystem)
- throws Exception {
-
- // only difference between update and commit is the param's order
- // when calling synchronisation method
- commitUpdateDelegate(label, true, uriFileSystem);
-
- }
-
- static protected void commitUpdateDelegate(String label, boolean isCommit,
- String... uriFileSystem) throws Exception {
-
- File currentDir = new File(FileUtil.getCurrentDirectory()
- .getAbsolutePath());
-
- if (isCommit) {
- log.info("Commit args.length:+" + uriFileSystem.length);
- } else {
- log.info("Update args.length:+" + uriFileSystem.length);
- }
-
- if (log.isDebugEnabled()) {
- for (String args : uriFileSystem) {
- log.debug(args);
- }
- log.debug("Current dir:" + currentDir);
- }
-
- /*
- * Alors c'est facile si on a un élément dans le param c'est que on
- * spécifie l'endroit du FS à updater/commit, ce qui veut dire que on
- * doit aller chercher ensuite dans le dossier donné l'adresse du
- * wikitty service. Notons que si il y a un élément ça doit forcément
- * être une uri avec le protocole file. après on appelle simplement la
- * méthode synchro avec l'ordre correct entre uritarget et uri origin.
- *
- * dans le cas ou ya pas d'argument ça veut dire que on doit
- * commit/update le dossier courant donc aller chercher dans
- * l'arborescence l'adresse du wikitty service.
- *
- * et pareil on va construire les adresses pour faire une synchro
- */
-
- // update is from wikitty service store to wikitty service File System
-
- String wikittyServiceInter = StringUtils.EMPTY;
- String wikittyServiceFileSystem = StringUtils.EMPTY;
-
- String labelInitial = StringUtils.EMPTY;
- PropertiesExtended homeProperty = null;
- // Check number of argument
- switch (uriFileSystem.length) {
- // if none, then the current dir have to be commit.
- case 0:
- // search for the home property dir that containt uri to the wikitty
- // service
- File homePropertyDir = WikittyPublicationFileSystem
- .searchWikittyPublicationHomePropertie(currentDir);
-
- homeProperty = WikittyPublicationFileSystem
- .getWikittyPublicationProperties(homePropertyDir,
- WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE);
-
- // load the wikitty service uri (distant one)
- wikittyServiceInter = homeProperty
- .getProperty(WIKITTY_SERVICE_INTERLOCUTEUR);
-
- // construct the current uri for wikitty service file system
- // search the current label
- PropertiesExtended metaPropertiesExtended = WikittyPublicationFileSystem
- .getWikittyPublicationProperties(currentDir,
- WikittyFileUtil.WIKITTY_FILE_META_PROPERTIES_FILE);
- String labelCurrent = metaPropertiesExtended
- .getProperty(WikittyPublicationFileSystem.META_CURRENT_LABEL);
-
- // construct uri of the wikitty publication file system
- wikittyServiceFileSystem = "file://"
- + homePropertyDir.getAbsolutePath() + LABEL_DELIM
- + labelCurrent;
- labelInitial = homeProperty.getProperty(LABEL_KEY);
-
- wikittyServiceInter += LABEL_DELIM + label
- + labelCurrent.replaceFirst(labelInitial, "");
-
- break;
- // if a param is set it mean that the uri of the File system is set
- case 1:
-
- wikittyServiceFileSystem = uriFileSystem[0];
- URI originUri = new URI(wikittyServiceFileSystem);
- // check if uri of wikitty publication file system is well formed,
- // must be a file "protocol"
- if (!originUri.getScheme().equals(FILE_URI_PREFIX)) {
- // Exception
- }
- // then search for the home property file to load the wikitty
- // service uri
- File workingDir = new File(originUri.getPath());
- homeProperty = WikittyPublicationFileSystem
- .getWikittyPublicationProperties(workingDir,
- WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE);
-
- wikittyServiceInter = (String) homeProperty
- .get(WIKITTY_SERVICE_INTERLOCUTEUR);
-
- labelInitial = homeProperty.getProperty(LABEL_KEY);
-
- wikittyServiceInter += LABEL_DELIM + label
- + originUri.getFragment().replaceFirst(labelInitial, "");
-
- break;
-
- // Exception, correct number of argument is 0 or 1
- default:
-
- // exception
- break;
- }
-
- if (log.isDebugEnabled()) {
-
- log.debug("homeProperty :" + homeProperty.getOrigin());
- for (Entry<Object, Object> ee : homeProperty.entrySet()) {
- log.debug(ee.getKey() + "=" + ee.getValue());
- }
-
- log.debug("wikitty Inter:" + wikittyServiceInter
- + " wikittyFileSystem" + wikittyServiceFileSystem);
- }
-
- // delegate to synchronisation
- // only difference between update and commit is the param's order
- if (isCommit) {
- synchronisation(wikittyServiceFileSystem, wikittyServiceInter);
- } else {
- synchronisation(wikittyServiceInter, wikittyServiceFileSystem);
- }
-
- }
-
- static public void usage() {
-
- System.out.println("");
-
- String usage = "Usage"
- + "\n"
- + "''wp sync [--norecursion] "
- + "[--delete|--existing] [URI origin] [URI target]''"
- + "\n \nwith URI :\n"
- + "file:///truc/machin/#label\n"
- + "hessian://www.adresse.com:8827/etc/etc#label\n"
- + "cajo://www.adresse.com:8827/etc/etc#label"
- + " \n\n or: \n"
- + "''wp [update|commit] [--norecursion] [--delete|--existing] [URI file]''";
- System.out.println(usage);
- }
-}
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-07-20 15:26:30 UTC (rev 1081)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -56,6 +56,10 @@
import org.nuiton.wikitty.entities.WikittyLabel;
import org.nuiton.wikitty.entities.WikittyLabelHelper;
import org.nuiton.wikitty.entities.WikittyLabelImpl;
+import org.nuiton.wikitty.publication.AbstractWikittyFileService;
+import org.nuiton.wikitty.publication.MimeTypePubHelper;
+import org.nuiton.wikitty.publication.PropertiesExtended;
+import org.nuiton.wikitty.publication.WikittyFileUtil;
import org.nuiton.wikitty.publication.entities.WikittyPubData;
import org.nuiton.wikitty.publication.entities.WikittyPubDataHelper;
import org.nuiton.wikitty.publication.entities.WikittyPubDataImpl;
@@ -66,7 +70,6 @@
import org.nuiton.wikitty.search.TreeNodeResult;
import org.nuiton.wikitty.services.WikittyEvent;
import org.nuiton.wikitty.services.WikittyListener;
-import org.nuiton.wikitty.publication.synchro.WikittyFileUtil;
public class WikittyPublicationFileSystem extends AbstractWikittyFileService {
@@ -194,30 +197,30 @@
homeFile, WIKITTY_FILE_SERVICE);
// the original label use to create if not exist
- if (!propertyWikittyService.containsKey(WikittyPublication.LABEL_KEY)) {
+ if (!propertyWikittyService.containsKey(WikittyPublicationSynchronize.LABEL_KEY)) {
log.debug("Writing home property label"
+ propertyWikittyService.getOrigin());
- propertyWikittyService.setProperty(WikittyPublication.LABEL_KEY,
+ propertyWikittyService.setProperty(WikittyPublicationSynchronize.LABEL_KEY,
this.label);
}
// the service use to update or commit
String uriService = app
- .getOption(WikittyPublication.WIKITTY_SERVICE_INTERLOCUTEUR);
+ .getOption(WikittyPublicationSynchronize.WIKITTY_SERVICE_INTERLOCUTEUR);
if (uriService !=null) {
log.debug("Writing home property service on:"
+ propertyWikittyService.getOrigin() + " uri" + uriService);
propertyWikittyService.setProperty(
- WikittyPublication.WIKITTY_SERVICE_INTERLOCUTEUR, uriService);
+ WikittyPublicationSynchronize.WIKITTY_SERVICE_INTERLOCUTEUR, uriService);
}
propertyWikittyService.store();
recursion = true;
- if (app.getOptions().containsKey(WikittyPublication.IS_RECURSION_OPTION)) {
+ if (app.getOptions().containsKey(WikittyPublicationSynchronize.IS_RECURSION_OPTION)) {
this.recursion = app
- .getOptionAsBoolean(WikittyPublication.IS_RECURSION_OPTION);
+ .getOptionAsBoolean(WikittyPublicationSynchronize.IS_RECURSION_OPTION);
}
// TODO mfotun-2011-04-28 add a support for filtered file with a
// property file
Copied: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationSynchronize.java (from rev 1079, trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java)
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationSynchronize.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationSynchronize.java 2011-07-21 08:38:06 UTC (rev 1082)
@@ -0,0 +1,680 @@
+/*
+ * #%L
+ * Wikitty :: publication
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2010 - 2011 CodeLutin mfortun
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.wikitty.publication.synchro;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.util.ArgumentsParserException;
+import org.nuiton.util.FileUtil;
+import org.nuiton.wikitty.WikittyConfigOption;
+import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.WikittyServiceFactory;
+import org.nuiton.wikitty.WikittyUtil;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyLabel;
+import org.nuiton.wikitty.entities.WikittyLabelHelper;
+import org.nuiton.wikitty.publication.PropertiesExtended;
+import org.nuiton.wikitty.publication.WikittyFileUtil;
+import org.nuiton.wikitty.publication.entities.WikittyPubData;
+import org.nuiton.wikitty.publication.entities.WikittyPubText;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.Search;
+
+/**
+ * Main class of the sync part of wikitty publication, this class is the entry
+ * point for sync operation. Existing, delete and update.
+ *
+ *
+ * @author mfortun
+ *
+ */
+public class WikittyPublicationSynchronize {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ final static private Log log = LogFactory.getLog(WikittyPublicationSynchronize.class);
+
+ /**
+ * Key for the other uri, usefull in the case of commit/update with a file
+ * system wikitty service.
+ */
+ static public String WIKITTY_SERVICE_INTERLOCUTEUR = "wikitty.service.interlocuteur";
+
+ static protected ApplicationConfig applicationConfig;
+
+ /**
+ * for recursion option
+ */
+ static public String IS_RECURSION_OPTION = "isRecur";
+ /**
+ * for delete option
+ */
+ static public String IS_DELETE_OPTION = "delete";
+ /**
+ * for existing option
+ */
+ static public String IS_EXISTING_OPTION = "existing";
+
+ /**
+ * Use to save the label by the wikitty publication file system
+ */
+ static public String LABEL_KEY = "working.label";
+
+ /**
+ * the string that mark the beginnning of the label
+ */
+ static public String LABEL_DELIM = "#";
+ /**
+ * regex to select the label part of the uri
+ */
+ static public String LABEL_REGEX = "\\#.*";
+
+ /**
+ * the prefix use in file url
+ */
+ static public String FILE_URI_PREFIX = "file";
+
+ /**
+ * the prefix use in cajo url
+ */
+ static public String CAJO_URI_PREFIX = "cajo";
+
+ /**
+ * the prefix use in hessian url
+ */
+ static public String HESSIAN_URI_PREFIX = "hessian";
+
+
+
+ /*
+ * Class don't have to be instantiate
+ */
+ private WikittyPublicationSynchronize() {
+
+ }
+
+ /**
+ * @param args
+ * @throws ArgumentsParserException
+ */
+ static public void main(String[] args) throws Exception {
+
+ applicationConfig = new ApplicationConfig();
+
+ /*
+ * TODO mfortun-2011-04-14 construct option def instance to initialize
+ * correctly application config
+ */
+
+ applicationConfig.setDefaultOption(IS_DELETE_OPTION, "false");
+ applicationConfig.setDefaultOption(IS_EXISTING_OPTION, "false");
+ applicationConfig.setDefaultOption(IS_RECURSION_OPTION, "true");
+
+ // allias for norecursion
+ applicationConfig.addAlias("--norecursion", "--option",
+ WikittyPublicationSynchronize.IS_RECURSION_OPTION, "false");
+
+ applicationConfig.addAlias("--delete", "--option", IS_DELETE_OPTION,
+ "true");
+
+ applicationConfig.addAlias("--existing", "--option",
+ IS_EXISTING_OPTION, "true");
+
+ // allias for all the action
+ applicationConfig.addAlias("wp sync", "--option", "sync");
+
+ applicationConfig.addAlias("wp commit", "--option", "commit");
+
+ applicationConfig.addAlias("wp update", "--option", "update");
+
+ applicationConfig
+ .addActionAlias("sync",
+ "org.nuiton.wikitty.publication.synchro.WikittyPublication#synchronisation");
+
+ applicationConfig
+ .addActionAlias("commit",
+ "org.nuiton.wikitty.publication.synchro.WikittyPublication#commit");
+
+ applicationConfig
+ .addActionAlias("update",
+ "org.nuiton.wikitty.publication.synchro.WikittyPublication#update");
+ // parsing
+ applicationConfig.parse(args);
+
+ // execution
+ applicationConfig.doAction(0);
+
+ }
+
+ static public void synchronisation(String origin, String target)
+ throws URISyntaxException {
+
+ boolean isRecur = applicationConfig
+ .getOptionAsBoolean(IS_RECURSION_OPTION);
+
+ boolean isDelete = applicationConfig
+ .getOptionAsBoolean(IS_DELETE_OPTION);
+ boolean isExisting = applicationConfig
+ .getOptionAsBoolean(IS_EXISTING_OPTION);
+ // update operation is the default operation
+ boolean isUpdate = !isDelete && !isExisting;
+
+ log.info("Sync uri origin: " + origin + " uri target: " + target
+ + " isRecur:" + isRecur + " isUpdate:" + isUpdate
+ + " isDelete:" + isDelete + "isExisting:" + isExisting);
+
+ URI uriOrigin = new URI(origin);
+
+ URI uriTarget = new URI(target);
+
+ /*
+ * necessary to have property correctly initialize in order to obtain
+ * the correct implementation of the wikitty service
+ */
+
+ // once on the service origin
+ applicationConfig.setOption(WIKITTY_SERVICE_INTERLOCUTEUR, new String(
+ target.replaceAll(LABEL_REGEX, StringUtils.EMPTY)));
+
+ ApplicationConfig temp1 = setUpApplicationConfigServerConnector(uriOrigin);
+
+ WikittyProxy proxyOrigin = new WikittyProxy(
+ WikittyServiceFactory.buildWikittyService(temp1));
+
+ // store the other uri in the application, if the service is a
+ // wikittypublication file system
+ // it can need it to store wikittyservice property
+ applicationConfig.setOption(WIKITTY_SERVICE_INTERLOCUTEUR, new String(
+ origin.replaceAll(LABEL_REGEX, StringUtils.EMPTY)));
+ // once on the service target
+ ApplicationConfig temp2 = setUpApplicationConfigServerConnector(uriTarget);
+
+ WikittyProxy proxyTarget = new WikittyProxy(
+ WikittyServiceFactory.buildWikittyService(temp2));
+
+ String labelOrigin = uriOrigin.getFragment();
+ String labelTarget = uriTarget.getFragment();
+
+ Criteria critOrigin = constructCriteriaLabelRecur(labelOrigin, isRecur);
+ Criteria critTarget = constructCriteriaLabelRecur(labelTarget, isRecur);
+
+ List<String> listOrigin = proxyOrigin.findAllIdByCriteria(critOrigin)
+ .getAll();
+ List<String> listTarget = proxyTarget.findAllIdByCriteria(critTarget)
+ .getAll();
+
+ // construct list of wikitty contained in both location
+ List<String> existInBoth = new ArrayList<String>();
+ existInBoth.addAll(listOrigin);
+ existInBoth.retainAll(listTarget);
+
+ // construct list of wikitty contained only in origin location
+ List<String> existOnlyOnOrigin = new ArrayList<String>();
+ existOnlyOnOrigin.addAll(listOrigin);
+ existOnlyOnOrigin.removeAll(listTarget);
+
+ // construct list of wikitty contained only in target location
+ List<String> existOnlyOnTarget = new ArrayList<String>();
+ existOnlyOnTarget.addAll(listTarget);
+ existOnlyOnTarget.removeAll(listOrigin);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Wikitty exist on both: " + existInBoth.size());
+ for (String ex : existInBoth) {
+ log.debug(ex);
+ }
+
+ log.debug("Wikitty exist only on origin: "
+ + existOnlyOnOrigin.size());
+ for (String ex : existOnlyOnOrigin) {
+ log.debug(ex);
+ }
+
+ log.debug("Wikitty exist only on target: "
+ + existOnlyOnTarget.size());
+ for (String ex : existOnlyOnTarget) {
+ log.debug(ex);
+ }
+ }
+
+ /*
+ * FIXME mfortun-2011-04-27 remove all that stuff for the safety of the
+ * version when a solution rise for the wikitty version
+ */
+
+ /*
+ * if option is update send wikitty that are not in the target.
+ */
+ if (isUpdate) {
+
+ log.info("Store on target new wikitty");
+
+ List<Wikitty> newWikitties = proxyOrigin.restore(existOnlyOnOrigin);
+
+ for (Wikitty wikittyNew : newWikitties) {
+
+ Set<String> saveLabelOrigin = WikittyLabelHelper
+ .getLabels(wikittyNew);
+
+ Set<String> targetLabels = new HashSet<String>();
+
+ // prepare set of target label
+ // we save all the label except the one corresponding
+ // to origin, determine by isRecur
+ for (String labels : saveLabelOrigin) {
+
+ if (isRecur && labels.startsWith(labelOrigin)) {
+ String finalLabelTarge = new String(labels.replace(
+ labelOrigin, labelTarget));
+ targetLabels.add(finalLabelTarge);
+ } else if (!isRecur && labels.equals(labelOrigin)) {
+ targetLabels.add(labelTarget);
+ } else {
+ targetLabels.add(labels);
+ }
+
+ }
+
+ // save the version before reset label
+ String wikittyVersionLocal = wikittyNew.getVersion();
+ WikittyLabelHelper.setLabels(wikittyNew, targetLabels);
+ // restore the version
+ wikittyNew.setVersion(wikittyVersionLocal);
+ proxyTarget.store(wikittyNew);
+
+ String versionSaveTarget = wikittyNew.getVersion();
+
+ WikittyLabelHelper.setLabels(wikittyNew, saveLabelOrigin);
+ wikittyNew.setVersion(versionSaveTarget);
+
+ // we re store on the origin to ensure wikitty version
+
+ try {
+ proxyOrigin.store(wikittyNew);
+ } catch (Exception e) {
+
+ // FIXME when a wikitty service store a
+ // wikitty that he does'nt know
+ // he set the version to 1.0
+ e.printStackTrace();
+ }
+ }
+
+ }
+ /*
+ * if option delete remove those who are on the target but not on origin
+ */
+ if (isDelete) {
+
+ log.info("Remove from target deleted wikitty");
+
+ for (String id : existOnlyOnTarget) {
+
+ Wikitty w = proxyTarget.restore(id);
+
+ WikittyLabelHelper.removeLabels(w, labelTarget);
+
+ proxyTarget.store(w);
+
+ }
+ } else {
+
+ log.info("Update existing wikitty");
+ /*
+ * case existing and update, update those which are on both location
+ */
+ for (String id : existInBoth) {
+ Wikitty fromTarget = proxyTarget.restore(id);
+ Wikitty fromOrigin = proxyOrigin.restore(id);
+
+ String versionTarget = fromTarget.getVersion();
+
+ String versionOrigin = fromOrigin.getVersion();
+
+ // check version for update
+
+ /*
+ * we replace origin labels by target's labels if we udpate.
+ */
+ if (WikittyUtil
+ .versionGreaterThan(versionOrigin, versionTarget)) {
+ Set<String> setLabelTarget = WikittyLabelHelper
+ .getLabels(fromTarget);
+
+ Set<String> setLabelOrigin = WikittyLabelHelper
+ .getLabels(fromOrigin);
+
+ // save version before reset the label
+ String versionLocalSave = fromOrigin.getVersion();
+ // replace labels origins, by targets label
+ WikittyLabelHelper.setLabels(fromOrigin, setLabelTarget);
+ // restore the version
+ fromOrigin.setVersion(versionLocalSave);
+ // send modified origin to target wikitty service
+ proxyTarget.store(fromOrigin);
+ // re store on origin to ensure version is the same on both
+
+ // save the version case re set labels increment version
+ String saveVersion = fromOrigin.getVersion();
+ // re set correctly labels
+ WikittyLabelHelper.setLabels(fromOrigin, setLabelOrigin);
+ // re set the version
+ fromOrigin.setVersion(saveVersion);
+
+ // re store the wikitty with the correct version
+ // and labels
+ proxyOrigin.store(fromOrigin);
+ }
+ }
+
+ }// */
+
+ }
+
+ /**
+ * Used to construct criteria on wikittypubdata and pubtext on the
+ * wikittylabel extension
+ *
+ * @param label
+ * the label criteria
+ * @param isRecur
+ * is recusion
+ * @return the constructed criteria
+ */
+ static protected Criteria constructCriteriaLabelRecur(String label,
+ boolean isRecur) {
+
+ log.info("Construct criteria with label: " + label + " isRecur:"
+ + isRecur);
+
+ // Construct the criteria
+ Criteria criteriaOnLabels;
+ Search mainRequest = Search.query();
+ Search subRoqu = mainRequest.or();
+
+ // must have the type of wikittypubtext/wikittypubdata
+ subRoqu.exteq(WikittyPubText.EXT_WIKITTYPUBTEXT).exteq(
+ WikittyPubData.EXT_WIKITTYPUBDATA);
+ if (isRecur) {
+
+ // and extension with the name that containt the label (recursivity)
+ criteriaOnLabels = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL)
+ .sw(WikittyLabel.FQ_FIELD_WIKITTYLABEL_LABELS, label)
+ .criteria();
+
+ } else {
+
+ // and extension with the name strictly equals to the label (no
+ // recursivity)
+ criteriaOnLabels = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL)
+ .eq(WikittyLabel.FQ_FIELD_WIKITTYLABEL_LABELS, label)
+ .criteria();
+
+ }
+
+ log.debug(criteriaOnLabels);
+
+ return criteriaOnLabels;
+
+ }
+
+ /**
+ * Use to setup correct url property in the application config and correct
+ * component for the wikittyservice
+ *
+ * @param uri
+ * of the targeted wikitty service
+ */
+ static protected ApplicationConfig setUpApplicationConfigServerConnector(
+ URI uri) {
+
+ log.info("Construct application config for uri: " + uri);
+
+ // prepare new application config
+ ApplicationConfig result = new ApplicationConfig();
+
+ // transfert main properties to new application config
+ result.setOptions(applicationConfig.getFlatOptions());
+ String url = uri.toASCIIString();
+
+ if (uri.getScheme().equals(FILE_URI_PREFIX)) {
+
+ result.setOption(
+ WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS
+ .getKey(), WikittyPublicationFileSystem.class
+ .getName());
+ } else if (uri.getScheme().equals(CAJO_URI_PREFIX)) {
+ result.setOption(
+ WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS
+ .getKey(),
+ "org.nuiton.wikitty.services.WikittyServiceCajoClient");
+
+ // remove fragment from the uri.
+ url = new String(url.replaceAll(LABEL_REGEX, StringUtils.EMPTY));
+
+ } else if (uri.getScheme().equals(HESSIAN_URI_PREFIX)) {
+ result.setOption(
+ WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS
+ .getKey(),
+ "org.nuiton.wikitty.services.WikittyServiceHessianClient");
+ // remove fragment from the uri.
+ url = new String(url.replaceAll(LABEL_REGEX, StringUtils.EMPTY));
+ }
+
+ // set protocol to http, no use finally
+ /*
+ * url = url.replaceFirst("["+uri.getScheme()+"]", "http");
+ */
+
+ log.info("set url "
+ + url
+ + " with component :"
+ + result.getOption(WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS
+ .getKey()));
+
+ result.setOption(WikittyConfigOption.WIKITTY_SERVER_URL.getKey(), url);
+
+ log.debug("Application config: " + result.getFlatOptions());
+
+ return result;
+
+ }
+
+ static public void update(String label, String... uriFileSystem)
+ throws Exception {
+
+ // only difference between update and commit is the param's order
+ // when calling synchronisation method
+ commitUpdateDelegate(label, false, uriFileSystem);
+
+ }
+
+ static public void commit(String label, String... uriFileSystem)
+ throws Exception {
+
+ // only difference between update and commit is the param's order
+ // when calling synchronisation method
+ commitUpdateDelegate(label, true, uriFileSystem);
+
+ }
+
+ static protected void commitUpdateDelegate(String label, boolean isCommit,
+ String... uriFileSystem) throws Exception {
+
+ File currentDir = new File(FileUtil.getCurrentDirectory()
+ .getAbsolutePath());
+
+ if (isCommit) {
+ log.info("Commit args.length:+" + uriFileSystem.length);
+ } else {
+ log.info("Update args.length:+" + uriFileSystem.length);
+ }
+
+ if (log.isDebugEnabled()) {
+ for (String args : uriFileSystem) {
+ log.debug(args);
+ }
+ log.debug("Current dir:" + currentDir);
+ }
+
+ /*
+ * Alors c'est facile si on a un élément dans le param c'est que on
+ * spécifie l'endroit du FS à updater/commit, ce qui veut dire que on
+ * doit aller chercher ensuite dans le dossier donné l'adresse du
+ * wikitty service. Notons que si il y a un élément ça doit forcément
+ * être une uri avec le protocole file. après on appelle simplement la
+ * méthode synchro avec l'ordre correct entre uritarget et uri origin.
+ *
+ * dans le cas ou ya pas d'argument ça veut dire que on doit
+ * commit/update le dossier courant donc aller chercher dans
+ * l'arborescence l'adresse du wikitty service.
+ *
+ * et pareil on va construire les adresses pour faire une synchro
+ */
+
+ // update is from wikitty service store to wikitty service File System
+
+ String wikittyServiceInter = StringUtils.EMPTY;
+ String wikittyServiceFileSystem = StringUtils.EMPTY;
+
+ String labelInitial = StringUtils.EMPTY;
+ PropertiesExtended homeProperty = null;
+ // Check number of argument
+ switch (uriFileSystem.length) {
+ // if none, then the current dir have to be commit.
+ case 0:
+ // search for the home property dir that containt uri to the wikitty
+ // service
+ File homePropertyDir = WikittyPublicationFileSystem
+ .searchWikittyPublicationHomePropertie(currentDir);
+
+ homeProperty = WikittyPublicationFileSystem
+ .getWikittyPublicationProperties(homePropertyDir,
+ WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE);
+
+ // load the wikitty service uri (distant one)
+ wikittyServiceInter = homeProperty
+ .getProperty(WIKITTY_SERVICE_INTERLOCUTEUR);
+
+ // construct the current uri for wikitty service file system
+ // search the current label
+ PropertiesExtended metaPropertiesExtended = WikittyPublicationFileSystem
+ .getWikittyPublicationProperties(currentDir,
+ WikittyFileUtil.WIKITTY_FILE_META_PROPERTIES_FILE);
+ String labelCurrent = metaPropertiesExtended
+ .getProperty(WikittyPublicationFileSystem.META_CURRENT_LABEL);
+
+ // construct uri of the wikitty publication file system
+ wikittyServiceFileSystem = "file://"
+ + homePropertyDir.getAbsolutePath() + LABEL_DELIM
+ + labelCurrent;
+ labelInitial = homeProperty.getProperty(LABEL_KEY);
+
+ wikittyServiceInter += LABEL_DELIM + label
+ + labelCurrent.replaceFirst(labelInitial, "");
+
+ break;
+ // if a param is set it mean that the uri of the File system is set
+ case 1:
+
+ wikittyServiceFileSystem = uriFileSystem[0];
+ URI originUri = new URI(wikittyServiceFileSystem);
+ // check if uri of wikitty publication file system is well formed,
+ // must be a file "protocol"
+ if (!originUri.getScheme().equals(FILE_URI_PREFIX)) {
+ // Exception
+ }
+ // then search for the home property file to load the wikitty
+ // service uri
+ File workingDir = new File(originUri.getPath());
+ homeProperty = WikittyPublicationFileSystem
+ .getWikittyPublicationProperties(workingDir,
+ WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE);
+
+ wikittyServiceInter = (String) homeProperty
+ .get(WIKITTY_SERVICE_INTERLOCUTEUR);
+
+ labelInitial = homeProperty.getProperty(LABEL_KEY);
+
+ wikittyServiceInter += LABEL_DELIM + label
+ + originUri.getFragment().replaceFirst(labelInitial, "");
+
+ break;
+
+ // Exception, correct number of argument is 0 or 1
+ default:
+
+ // exception
+ break;
+ }
+
+ if (log.isDebugEnabled()) {
+
+ log.debug("homeProperty :" + homeProperty.getOrigin());
+ for (Entry<Object, Object> ee : homeProperty.entrySet()) {
+ log.debug(ee.getKey() + "=" + ee.getValue());
+ }
+
+ log.debug("wikitty Inter:" + wikittyServiceInter
+ + " wikittyFileSystem" + wikittyServiceFileSystem);
+ }
+
+ // delegate to synchronisation
+ // only difference between update and commit is the param's order
+ if (isCommit) {
+ synchronisation(wikittyServiceFileSystem, wikittyServiceInter);
+ } else {
+ synchronisation(wikittyServiceInter, wikittyServiceFileSystem);
+ }
+
+ }
+
+ static public void usage() {
+
+ System.out.println("");
+
+ String usage = "Usage"
+ + "\n"
+ + "''wp sync [--norecursion] "
+ + "[--delete|--existing] [URI origin] [URI target]''"
+ + "\n \nwith URI :\n"
+ + "file:///truc/machin/#label\n"
+ + "hessian://www.adresse.com:8827/etc/etc#label\n"
+ + "cajo://www.adresse.com:8827/etc/etc#label"
+ + " \n\n or: \n"
+ + "''wp [update|commit] [--norecursion] [--delete|--existing] [URI file]''";
+ System.out.println(usage);
+ }
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationSynchronize.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/wikitty-publication/src/main/resources/struts.xml
===================================================================
--- trunk/wikitty-publication/src/main/resources/struts.xml 2011-07-20 15:26:30 UTC (rev 1081)
+++ trunk/wikitty-publication/src/main/resources/struts.xml 2011-07-21 08:38:06 UTC (rev 1082)
@@ -28,7 +28,7 @@
<package name="loginArea" extends="publicArea">
<interceptors>
<interceptor name="logout"
- class="org.nuiton.wikitty.publication.LogoutInterceptor" />
+ class="org.nuiton.wikitty.publication.interceptor.LogoutInterceptor" />
<interceptor-stack name="loginAreaStack">
<interceptor-ref name="logout" />
<interceptor-ref name="publicAreaStack" />
@@ -41,7 +41,7 @@
<package name="restrictedArea" extends="publicArea">
<interceptors>
<interceptor name="login"
- class="org.nuiton.wikitty.publication.LoginInterceptor">
+ class="org.nuiton.wikitty.publication.interceptor.LoginInterceptor">
<param name="error">/login_input.action</param>
</interceptor>
<interceptor-stack name="restrictedAreaStack">
Added: trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-jar.properties
===================================================================
--- trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-jar.properties (rev 0)
+++ trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-jar.properties 2011-07-21 08:38:06 UTC (rev 1082)
@@ -0,0 +1,29 @@
+###
+# #%L
+# Wikitty :: publication
+#
+# $Id: wikitty-publication-ws-default.properties 823 2011-04-20 14:45:47Z mfortun $
+# $HeadURL: http://svn.nuiton.org/svn/wikitty/trunk/wikitty-publication/src/main/resour… $
+# %%
+# Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin
+# %%
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Lesser Public License for more details.
+#
+# You should have received a copy of the GNU General Lesser Public
+# License along with this program. If not, see
+# <http://www.gnu.org/licenses/lgpl-3.0.html>.
+# #L%
+###
+
+
+wikitty.WikittyService.components=org.nuiton.wikitty.publication.externalize.WikittyServiceJarLoader
+wikitty.publication.repository.jar=/home/Manou/testWP/pub-externalized.jar
+
Property changes on: trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-jar.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
1
0
Author: mfortun
Date: 2011-07-20 17:26:30 +0200 (Wed, 20 Jul 2011)
New Revision: 1081
Url: http://nuiton.org/repositories/revision/wikitty/1081
Log:
* add a solution for UI improvement inside wikitty publication
Added:
trunk/wikitty-publication/src/site/rst/publication-ui.rst
Added: trunk/wikitty-publication/src/site/rst/publication-ui.rst
===================================================================
--- trunk/wikitty-publication/src/site/rst/publication-ui.rst (rev 0)
+++ trunk/wikitty-publication/src/site/rst/publication-ui.rst 2011-07-20 15:26:30 UTC (rev 1081)
@@ -0,0 +1,78 @@
+Wikitty Publication ui
+----------------------
+@author: Manoël Fortun
+
+But
+===
+
+Pour le moment wikitty publication et ses script engine ne permettent pas de
+faire d'interface graphique, on peut seulement écrire du code qui sera exécuté
+par le moteur.
+
+Le but de cette partie est donc l'ajout de la possibilité de faire des
+interfaces graphique dans wikitty publication afin de réellement pouvoir faire
+plus que l'affichage du résultat de l'évaluation d'un script, pouvoir atteindre
+l'objectif de wikitty publication qui est la possibilité de développer des
+applications web complète.
+
+
+Existant
+========
+
+Avec le script engine on peut définir le type de retour de l'évaluation du
+script, mais comme celui ci sera finalement affiché dans une page web, pour
+avoir des interfaces il faut que le résultat soit en html.
+
+On retrouve dans les wikittyPubText des choses comme ça:
+
+var result =
+""+
+" <div class='menu'>\n"+
+wpEval.doAction(wpContext, "WikiMenu")+
+" </div>\n"+
+" <h1>Bonjour Les Lutins,</h1>\n"+
+" Bienvenue sur le Wikitty Wiki\n";
+
+wpContext.setContentType("text/html");
+result;
+
+Le html écrit dans des variables qui seront renvoyé en tant que résultat du
+sript, et on doit préciser le contentType du résultat pour que celui si soit
+correctement interprété.
+
+A titre d'exemple dans xwiki quand on veut rajouter des éléments UI, on les
+écrit en html, mais c'est différent puisque dans xwiki on peut avoir plusieurs
+langage par "page" qui sont interprétés localement, ce que l'on peut pas faire
+dans wikitty publication, du moins pas avec le fonctionnement actuel.
+
+
+Solution proposée
+=================
+
+La solution la plus simple serait d'autoriser le html directement dans les
+WikittyPubText, voir avoir un nouveau wikittyPub pour le html. Mais ce n'est
+pas suffisant comme solution, on perd la possibilité d'avoir du code
+dans ces wikittyPubText là.
+
+Il faut finalement un nouveau script engine pour le html, ce qui implique que
+dans le code html on pourra insérer des invocations direct à des éléments mis
+dans les bindings.
+
+Par exemple:
+
+
+<div class='menu'>
+wpEval.doAction(wpContext, "WikiMenu")+
+</div>
+<h1>Bonjour Les Lutins,</h1>
+Bienvenue sur le Wikitty Wiki
+
+<img src="wpContext.makeUrl("/raw/Logo")"/>
+
+Cette solution à l’intérêt d'être relativement simple et de permettre la
+création de page naturellement, puisqu'il n'y a aucune différence de traitement
+tout passe par "eval".
+
+On gagne toutes les possibilités du Html pour le rendu, avec la possibilité
+de javascript et css, javascript qui peut être inséré dans la page ou évalué
+en tant que code.
1
0