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
- 1653 discussions
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
r1080 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize
by mfortun@users.nuiton.org 18 Jul '11
by mfortun@users.nuiton.org 18 Jul '11
18 Jul '11
Author: mfortun
Date: 2011-07-18 12:00:30 +0200 (Mon, 18 Jul 2011)
New Revision: 1080
Url: http://nuiton.org/repositories/revision/wikitty/1080
Log:
* correct copy/paste error
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyServiceJarLoader.java
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-13 13:59:54 UTC (rev 1079)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyServiceJarLoader.java 2011-07-18 10:00:30 UTC (rev 1080)
@@ -75,9 +75,9 @@
wikittyJarRepository = new JarFile(jarLocation);
JarEntry metaEntry = wikittyJarRepository
+ .getJarEntry(WikittyFileUtil.WIKITTY_FILE_META_PROPERTIES_FILE);
+ JarEntry idEntry = wikittyJarRepository
.getJarEntry(WikittyFileUtil.WIKITTY_ID_PROPERTIES_FILE);
- JarEntry idEntry = wikittyJarRepository
- .getJarEntry(WikittyFileUtil.WIKITTY_FILE_META_PROPERTIES_FILE);
wikittyIndex = new Properties();
wikittyIndex.load(wikittyJarRepository.getInputStream(idEntry));
1
0
r1079 - in trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication: . action externalize synchro
by mfortun@users.nuiton.org 13 Jul '11
by mfortun@users.nuiton.org 13 Jul '11
13 Jul '11
Author: mfortun
Date: 2011-07-13 15:59:54 +0200 (Wed, 13 Jul 2011)
New Revision: 1079
Url: http://nuiton.org/repositories/revision/wikitty/1079
Log:
* clean import
* change local value to static constant
* new class for cross-cutting constant
Added:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationConstant.java
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationConfig.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationActionEval.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/JarUtil.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/WikittyPublication.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
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-12 15:29:48 UTC (rev 1078)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationConfig.java 2011-07-13 13:59:54 UTC (rev 1079)
@@ -54,7 +54,7 @@
public enum Option implements ApplicationConfig.OptionDef {
CONFIG_FILE(ApplicationConfig.CONFIG_FILE_NAME,
_("wikitty-publication.config.configFileName.description"),
- "wikitty-publication-ws-default.properties", String.class, false,
+ "wikitty-publication-ws-jar.properties", String.class, false,
false);
Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationConstant.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationConstant.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationConstant.java 2011-07-13 13:59:54 UTC (rev 1079)
@@ -0,0 +1,29 @@
+package org.nuiton.wikitty.publication;
+
+public class WikittyPublicationConstant {
+
+ /*
+ * Variable relative to scriping/binding
+ */
+ /** variable contenant l'instance de la classe ActionEval */
+ static final public String EVAL_VAR = "wpEval";
+ /** variable name use to put context in script and jsp */
+ static final public String CONTEXT_VAR = "wpContext";
+ /** contient la liste des arguments mandatory non encore utilise */
+ static final public String SUBCONTEXT_VAR = "wpSubContext";
+ /**
+ * contient le nom de la page WikittyPubText (ex: Wiki) ou la requete ayant
+ * permis de trouver la page (ex: MyScript.name=df)
+ */
+ static final public String PAGE_NAME_VAR = "wpPage";
+ /**
+ * contient le wikitty utilise comme script
+ */
+ static final public String WIKITTY_VAR = "wpWikitty";
+
+
+
+
+
+
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationConstant.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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-12 15:29:48 UTC (rev 1078)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationActionEval.java 2011-07-13 13:59:54 UTC (rev 1079)
@@ -20,6 +20,7 @@
import org.nuiton.wikitty.WikittyService;
import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.publication.WikittyPublicationConfig;
+import org.nuiton.wikitty.publication.WikittyPublicationConstant;
import org.nuiton.wikitty.publication.entities.WikittyPubText;
import org.nuiton.wikitty.publication.entities.WikittyPubTextCompiled;
import org.nuiton.wikitty.publication.entities.WikittyPubTextCompiledHelper;
@@ -44,22 +45,6 @@
protected HttpServletRequest request;
protected InputStream inputStream;
- /** variable contenant l'instance de la classe ActionEval */
- static final public String EVAL_VAR = "wpEval";
- /** variable name use to put context in script and jsp */
- static final public String CONTEXT_VAR = "wpContext";
- /** contient la liste des arguments mandatory non encore utilise */
- static final public String SUBCONTEXT_VAR = "wpSubContext";
- /**
- * contient le nom de la page WikittyPubText (ex: Wiki) ou la requete ayant
- * permis de trouver la page (ex: MyScript.name=df)
- */
- static final public String PAGE_NAME_VAR = "wpPage";
- /**
- * contient le wikitty utilise comme script
- */
- static final public String WIKITTY_VAR = "wpWikitty";
-
@Override
public void setServletResponse(HttpServletResponse arg0) {
this.response = arg0;
@@ -113,13 +98,13 @@
if (content == null) {
result = getError(context);
} else {
-
+
/*
- * if wikitty pub text compiled we load the class corresponding
- * to the byte code contained.
- * And then invoke the eval method on it
+ * if wikitty pub text compiled we load the class
+ * corresponding to the byte code contained. And then invoke
+ * the eval method on it
*/
- String name= WikittyPubTextHelper.getName(w);
+ String name = WikittyPubTextHelper.getName(w);
// supprime de subcontext ce qui a ete utilise dans cette
// methode
@@ -127,22 +112,26 @@
subContext.size()));
Map<String, Object> bindings = new HashMap<String, Object>();
- bindings.put(PAGE_NAME_VAR, criteria.getName());
- bindings.put(CONTEXT_VAR, context);
- bindings.put(SUBCONTEXT_VAR, subContext);
- bindings.put(WIKITTY_VAR, w);
- bindings.put(EVAL_VAR, this);
+ bindings.put(WikittyPublicationConstant.PAGE_NAME_VAR,
+ criteria.getName());
+ bindings.put(WikittyPublicationConstant.CONTEXT_VAR,
+ context);
+ bindings.put(WikittyPublicationConstant.SUBCONTEXT_VAR,
+ subContext);
+ bindings.put(WikittyPublicationConstant.WIKITTY_VAR, w);
+ bindings.put(WikittyPublicationConstant.EVAL_VAR, this);
WikittyPublicationClassLoader classloader = new WikittyPublicationClassLoader();
- Class<? extends AbstractDecoredClass> clazz = (Class<? extends AbstractDecoredClass>) classloader.addClass(name, content);
+ Class<? extends AbstractDecoredClass> clazz = (Class<? extends AbstractDecoredClass>) classloader
+ .addClass(name, content);
try {
result = clazz.newInstance().eval(bindings);
} catch (Exception e) {
// TODO Mfortun-2011-07-08 really handle exception
e.printStackTrace();
- result = getError(context);
+ result = getError(context);
}
}
@@ -161,11 +150,14 @@
subContext.size()));
Map<String, Object> bindings = new HashMap<String, Object>();
- bindings.put(PAGE_NAME_VAR, criteria.getName());
- bindings.put(CONTEXT_VAR, context);
- bindings.put(SUBCONTEXT_VAR, subContext);
- bindings.put(WIKITTY_VAR, w);
- bindings.put(EVAL_VAR, this);
+ bindings.put(WikittyPublicationConstant.PAGE_NAME_VAR,
+ criteria.getName());
+ bindings.put(WikittyPublicationConstant.CONTEXT_VAR,
+ context);
+ bindings.put(WikittyPublicationConstant.SUBCONTEXT_VAR,
+ subContext);
+ bindings.put(WikittyPublicationConstant.WIKITTY_VAR, w);
+ bindings.put(WikittyPublicationConstant.EVAL_VAR, this);
result = ScriptEvaluator.eval(null, criteria.getName(),
content, mimetype, bindings);
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/JarUtil.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/JarUtil.java 2011-07-12 15:29:48 UTC (rev 1078)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/JarUtil.java 2011-07-13 13:59:54 UTC (rev 1079)
@@ -7,12 +7,15 @@
import org.nuiton.util.StringUtil;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
@@ -581,4 +584,45 @@
}
return s;
}
+
+ public static String getStringContent(JarFile jar, JarEntry jarEntry)
+ throws IOException {
+ BufferedReader buffer = new BufferedReader(new InputStreamReader(
+ jar.getInputStream(jarEntry)));
+
+ StringBuffer result = new StringBuffer();
+ char[] cbuf = new char[2000];
+
+ int nb = buffer.read(cbuf);
+ while (nb != -1) {
+ result.append(cbuf, 0, nb);
+ nb = buffer.read(cbuf);
+ }
+ buffer.close();
+ return result.toString();
+
+ }
+
+ public static byte[] getByteContent(JarFile jar, JarEntry jarEnt)
+ throws IOException {
+
+ ByteArrayOutputStream content;
+ // Extract this to a byte utils ?
+ InputStream in = new BufferedInputStream(jar.getInputStream(jarEnt));
+ try {
+ content = new ByteArrayOutputStream();
+ BufferedOutputStream tmp = new BufferedOutputStream(content);
+ try {
+ for (int b = in.read(); b != -1; b = in.read()) {
+ tmp.write(b);
+ }
+ } finally {
+ tmp.close();
+ }
+ } finally {
+ in.close();
+ }
+ return content.toByteArray();
+ }
+
}
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-12 15:29:48 UTC (rev 1078)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyPublicationExternalize.java 2011-07-13 13:59:54 UTC (rev 1079)
@@ -5,6 +5,7 @@
import java.io.PrintWriter;
import java.util.Set;
import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
import org.nuiton.util.ApplicationConfig;
import org.nuiton.util.ArgumentsParserException;
import org.nuiton.util.FileUtil;
@@ -14,7 +15,7 @@
import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.entities.WikittyLabel;
import org.nuiton.wikitty.entities.WikittyLabelHelper;
-import org.nuiton.wikitty.publication.action.PublicationActionEval;
+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;
@@ -22,6 +23,7 @@
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.WikittyPublicationFileSystem;
import org.nuiton.wikitty.search.Criteria;
import org.nuiton.wikitty.search.PagedResult;
@@ -36,16 +38,16 @@
*/
public class WikittyPublicationExternalize {
- public static String TEMPORARY_FILE_NAME = "tempBeforeJar";
- public static String DEFAULT_JAR_NAME = "pub-externalized";
+ static public String TEMPORARY_FILE_NAME = "tempBeforeJar";
+ static public String DEFAULT_JAR_NAME = "pub-externalized";
- public static String VERSION_SUFFIX = ".version";
- public static String EXTENSION_SUFFIX = ".extension";
-
- public static String SOURCE_EXTENSION = ".java";
- public static String COMPILED_EXTENSION = ".class";
- public static String PATH_SEPARATOR="path.separator";
+ static public String VERSION_SUFFIX = ".version";
+ static public String EXTENSION_SUFFIX = ".extension";
+ static public String SOURCE_EXTENSION = ".java";
+ static public String COMPILED_EXTENSION = ".class";
+ static public String PATH_SEPARATOR_PROPERTIE_KEY = "path.separator";
+
/*
* Class don't have to be instantiate
*/
@@ -64,13 +66,12 @@
// construct the url for local repo
File currentFile = new File(".");
- // currentFile = new
- // File(currentFile.getAbsolutePath()).getParentFile();
- currentFile = new File("/home/Manou/testWP");
+ currentFile = new File(currentFile.getAbsolutePath()).getParentFile();
+ // currentFile = new File("/home/User/testWP");
String Label = currentFile.getName();
- String urlFileSystem = "file:///home/Manou/testWP#wp";
- // String urlFileSystem = currentFile.getParent() + "#" + Label;
+ // String urlFileSystem = "file:///home/User/testWP#wp";
+ String urlFileSystem = currentFile.getParent() + WikittyPublication.LABEL_DELIM + Label;
appconfig.setOption(WikittyConfigOption.WIKITTY_SERVER_URL.getKey(),
urlFileSystem);
@@ -100,13 +101,12 @@
PropertiesExtended metaProperties = new PropertiesExtended(
filePropertiesMeta);
-
- metaProperties.setProperty(PATH_SEPARATOR, File.separator);
+ metaProperties.setProperty(PATH_SEPARATOR_PROPERTIE_KEY, File.separator);
// iterate wikitty
// - write file
// - write property
// - write
-
+
/*
* Format des propriétés:
*
@@ -147,36 +147,33 @@
extension = WikittyPubTextHelper.getFileExtension(wikit);
String content = WikittyPubTextHelper.getContent(wikit);
-
- // TODO 2011-07-08 change this later or not, java source will be
+ // TODO 2011-07-08 change this later or not, java source will be
// erase by the second file.
// Write original file
- wikittyFile = new File(
- tempDirectory.getAbsolutePath()+File.separator+
- labelPath + name + "." + extension);
+ wikittyFile = new File(tempDirectory.getAbsolutePath()
+ + File.separator + labelPath + name + "." + extension);
wikittyFile.createNewFile();
- FileUtil.writeString(wikittyFile,content );
+ FileUtil.writeString(wikittyFile, content);
-
- WikittyPubText currentPubText= new WikittyPubTextImpl(wikit);
-
-
- File javaFile = new File(tempDirectory.getAbsolutePath()+File.separator+
- labelPath + name + SOURCE_EXTENSION);
+ WikittyPubText currentPubText = new WikittyPubTextImpl(wikit);
+
+ File javaFile = new File(tempDirectory.getAbsolutePath()
+ + File.separator + labelPath + name + SOURCE_EXTENSION);
javaFile.createNewFile();
String codeClass = getCode(currentPubText);
FileUtil.writeString(javaFile, codeClass);
-
- File classDirectory = new File(tempDirectory.getAbsolutePath()+File.separator+
- labelPath );//+ name + COMPILED_EXTENSION);
- //classFile.createNewFile();
+ File classDirectory = new File(tempDirectory.getAbsolutePath()
+ + File.separator + labelPath);// + name +
+ // COMPILED_EXTENSION);
+ // classFile.createNewFile();
+
PrintWriter writer = new PrintWriter(System.out);
- // compile
- CompileHelper.compile(tempDirectory, javaFile, classDirectory,writer );
-
-
+ // compile
+ CompileHelper.compile(tempDirectory, javaFile, classDirectory,
+ writer);
+
// write properties
idProperties.put(id, labelPath + name);
metaProperties.put(id + EXTENSION_SUFFIX,
@@ -189,9 +186,8 @@
name = WikittyPubDataHelper.getName(wikit);
// write file on the temporary directory
- wikittyFile = new File(
- tempDirectory.getAbsolutePath()+File.separator+
- labelPath + name + "." + extension);
+ wikittyFile = new File(tempDirectory.getAbsolutePath()
+ + File.separator + labelPath + name + "." + extension);
wikittyFile.createNewFile();
FileUtil.byteToFile(content, wikittyFile);
@@ -216,94 +212,97 @@
/*
* Algo fonctionnement
*
- * done:
- * Selectionner tout les wikitty sur le file system qui sont dans le dossier
- * courant, en servant d'un wikitty publication fileSystem.
+ * done: Selectionner tout les wikitty sur le file system qui sont dans le
+ * dossier courant, en servant d'un wikitty publication fileSystem.
*
- * done:
- * On va créer un dossier pour le jar "tempJar" pour chaque wikitty en
+ * done: On va créer un dossier pour le jar "tempJar" pour chaque wikitty en
* fonction du type: -wikittyPubData: on va l'écrire sous son label le
* fichier dans le dossier tempJar et on va le référencer dans l'index
* central du dossier
*
- * stay:
- * -WikittyPubText: .on va écrire le pub text sous son label le fichier
- * correspondant .on va décorer le contenu du wikittyPubText avec les
- * éléments script engine etc, on va écrire le .java correspondant .ensuite
- * on va compiler le java et écrire le .class correspondant .on écrit les
- * metadata et les élément d'index du wikitty pour le retrouver
+ * stay: -WikittyPubText: .on va écrire le pub text sous son label le
+ * fichier correspondant .on va décorer le contenu du wikittyPubText avec
+ * les éléments script engine etc, on va écrire le .java correspondant
+ * .ensuite on va compiler le java et écrire le .class correspondant .on
+ * écrit les metadata et les élément d'index du wikitty pour le retrouver
*
*
*
- * done:
- * Une fois tout les wikitty traité on va packager le dossier tempJar en jar
- * et on va supprimer le dossier tempJar
+ * done: Une fois tout les wikitty traité on va packager le dossier tempJar
+ * en jar et on va supprimer le dossier tempJar
*/
-
-
- public static String getCode(WikittyPubText wikitty){
- String content =wikitty.getContent();
+ public static String getCode(WikittyPubText wikitty) {
+ String content = wikitty.getContent();
String mimeType = wikitty.getMimeType();
- String className=wikitty.getName();//+"PublicationClass";
- String classContent = "";
-
- //Set<String> labels = (Set<String>) wikitty.getField(WikittyLabel.EXT_WIKITTYLABEL, WikittyLabel.FIELD_WIKITTYLABEL_LABELS);
- //classContent += "package org.nuiton.wikitty.publication;" ;
- //classContent += "package "+ labels.toArray()[0].toString() +";";
+ String className = wikitty.getName();// +"PublicationClass";
+ String classContent = StringUtils.EMPTY;
+
+ // Set<String> labels = (Set<String>)
+ // wikitty.getField(WikittyLabel.EXT_WIKITTYLABEL,
+ // WikittyLabel.FIELD_WIKITTYLABEL_LABELS);
+ // classContent += "package org.nuiton.wikitty.publication;" ;
+ // classContent += "package "+ labels.toArray()[0].toString() +";";
classContent += "import org.apache.commons.logging.Log;";
classContent += "import org.apache.commons.logging.LogFactory;";
classContent += "import org.nuiton.wikitty.ScriptEvaluator;";
- classContent += "import "+ AbstractDecoredClass.class.getName() + ";";
+ classContent += "import " + AbstractDecoredClass.class.getName() + ";";
classContent += "import org.nuiton.wikitty.entities.*;";
classContent += "import org.nuiton.wikitty.publication.entities.*;";
classContent += "import org.nuiton.wikitty.publication.action.*;";
classContent += "import java.util.*;";
-
- classContent += "public class " + className + " extends " + AbstractDecoredClass.class.getSimpleName() + " {";
-
-
+
+ classContent += "public class " + className + " extends "
+ + AbstractDecoredClass.class.getSimpleName() + " {";
+
classContent += "public Object eval(Map<String, Object> bindings ) throws Exception {";
-
-
-
-
+
// TODO mfortun-2011-07-08 write a better "filter" must isolate specific
// mime type that correspond to precompilable langague
- if (mimeType!="java"){
+ if (mimeType != "java") {
classContent += "Object result = null;";
- classContent += "String content = \""+StringEscapeUtils.escapeJava(content) +"\";";
- classContent += "String mimeType = \""+StringEscapeUtils.escapeJava(mimeType) +"\";";
- classContent += "String criteriaName= \""+ Element.ELT_ID+":"+wikitty.getWikittyId()+"\";";
- classContent +=" result = ScriptEvaluator.eval(null, criteriaName, content, mimeType, bindings);";
+ classContent += "String content = \""
+ + StringEscapeUtils.escapeJava(content) + "\";";
+ classContent += "String mimeType = \""
+ + StringEscapeUtils.escapeJava(mimeType) + "\";";
+ classContent += "String criteriaName= \"" + Element.ELT_ID + ":"
+ + wikitty.getWikittyId() + "\";";
+ classContent += " result = ScriptEvaluator.eval(null, criteriaName, content, mimeType, bindings);";
classContent += "return result;";
} else {
-
+
/*
* Iterate on element that must be in the context and write
*
- * classContent = "+type+" "+name+" = bindings.get(\""+name+"\");";
+ * classContent = "+type+" "+name+" = bindings.get(\""+name+"\");";
*
* ?
- *
*/
// contruct variables that can be used inside the java code.
- classContent = "PublicationContext "+PublicationActionEval.CONTEXT_VAR+" = bindings.get(\""+PublicationActionEval.CONTEXT_VAR+"\");";
- classContent = "PublicationActionEval "+PublicationActionEval.EVAL_VAR+" = bindings.get(\""+PublicationActionEval.EVAL_VAR+"\");";
- classContent = "String "+PublicationActionEval.PAGE_NAME_VAR+" = bindings.get(\""+PublicationActionEval.PAGE_NAME_VAR+"\");";
- classContent = "List<String> "+PublicationActionEval.SUBCONTEXT_VAR+" = bindings.get(\""+PublicationActionEval.SUBCONTEXT_VAR+"\");";
- classContent = "Wikitty "+PublicationActionEval.WIKITTY_VAR+" = bindings.get(\""+PublicationActionEval.WIKITTY_VAR+"\");";
-
+ classContent = "PublicationContext "
+ + WikittyPublicationConstant.CONTEXT_VAR + " = bindings.get(\""
+ + WikittyPublicationConstant.CONTEXT_VAR + "\");";
+ classContent = "WikittyPublicationConstant "
+ + WikittyPublicationConstant.EVAL_VAR + " = bindings.get(\""
+ + WikittyPublicationConstant.EVAL_VAR + "\");";
+ classContent = "String " + WikittyPublicationConstant.PAGE_NAME_VAR
+ + " = bindings.get(\""
+ + WikittyPublicationConstant.PAGE_NAME_VAR + "\");";
+ classContent = "List<String> "
+ + WikittyPublicationConstant.SUBCONTEXT_VAR
+ + " = bindings.get(\""
+ + WikittyPublicationConstant.SUBCONTEXT_VAR + "\");";
+ classContent = "Wikitty " + WikittyPublicationConstant.WIKITTY_VAR
+ + " = bindings.get(\"" + WikittyPublicationConstant.WIKITTY_VAR
+ + "\");";
+
classContent += content;
-
+
}
-
+
classContent += "\n}\n}\n";
return classContent;
}
-
-
-
-
+
}
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-12 15:29:48 UTC (rev 1078)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyServiceJarLoader.java 2011-07-13 13:59:54 UTC (rev 1079)
@@ -1,13 +1,7 @@
package org.nuiton.wikitty.publication.externalize;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
@@ -18,9 +12,6 @@
import java.util.jar.JarFile;
import org.nuiton.util.ApplicationConfig;
import org.nuiton.util.StringUtil;
-import org.nuiton.wikitty.WikittyConfigOption;
-import org.nuiton.wikitty.WikittyProxy;
-import org.nuiton.wikitty.WikittyServiceFactory;
import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.entities.WikittyExtension;
import org.nuiton.wikitty.entities.WikittyImpl;
@@ -38,9 +29,9 @@
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.PagedResult;
import org.nuiton.wikitty.search.TreeNodeResult;
import org.nuiton.wikitty.services.WikittyEvent;
import org.nuiton.wikitty.services.WikittyListener;
@@ -61,38 +52,32 @@
protected Properties wikittyMetadata;
/*
- * Implementer :
+ * static public void main(String[] args) {
*
- * restore findByCriteria findAllByCriteria
+ * ApplicationConfig config = new ApplicationConfig();
+ * config.setOption(JAR_LOCATION_KEY,
+ * "/home/User/testWP/pub-externalized.jar"); config.setOption(
+ * WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS.getKey(),
+ * WikittyServiceJarLoader.class.getName()); WikittyProxy proxy = new
+ * WikittyProxy( WikittyServiceFactory.buildWikittyService(config));
+ *
+ * System.out.println(proxy
+ * .restore("e443dbbe-b461-41bd-b5b6-b612e964cb0d"));
+ *
+ * }
*/
- static public void main(String[] args) {
-
- ApplicationConfig config = new ApplicationConfig();
- config.setOption(JAR_LOCATION_KEY,
- "/home/Manou/testWP/pub-externalized.jar");
- config.setOption(
- WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS.getKey(),
- WikittyServiceJarLoader.class.getName());
- WikittyProxy proxy = new WikittyProxy(
- WikittyServiceFactory.buildWikittyService(config));
-
- System.out.println(proxy
- .restore("e443dbbe-b461-41bd-b5b6-b612e964cb0d"));
-
- }
-
public WikittyServiceJarLoader(ApplicationConfig config) {
try {
-
+
File jarLocation = new File(config.getOption(JAR_LOCATION_KEY));
wikittyJarRepository = new JarFile(jarLocation);
JarEntry metaEntry = wikittyJarRepository
- .getJarEntry("meta.properties");
+ .getJarEntry(WikittyFileUtil.WIKITTY_ID_PROPERTIES_FILE);
JarEntry idEntry = wikittyJarRepository
- .getJarEntry("ids.properties");
+ .getJarEntry(WikittyFileUtil.WIKITTY_FILE_META_PROPERTIES_FILE);
wikittyIndex = new Properties();
wikittyIndex.load(wikittyJarRepository.getInputStream(idEntry));
@@ -101,7 +86,6 @@
wikittyMetadata
.load(wikittyJarRepository.getInputStream(metaEntry));
-
} catch (IOException e) {
// TODO mfortun-2011-07-11 realy handle exception
e.printStackTrace();
@@ -165,13 +149,12 @@
public boolean canRead(String securityToken, String wikittyId) {
return exists(securityToken, wikittyId);
}
-
@Override
public boolean exists(String securityToken, String wikittyId) {
return exists(wikittyId);
}
-
+
protected boolean exists(String wikittyId) {
return wikittyIndex.containsKey(wikittyId);
}
@@ -207,8 +190,8 @@
result.add(WikittyPubText.EXT_WIKITTYPUBTEXT);
result.add(WikittyPubTextCompiled.EXT_WIKITTYPUBTEXTCOMPILED);
result.add(WikittyLabel.EXT_WIKITTYLABEL);
-
- return result;
+
+ return result;
}
@Override
@@ -278,22 +261,16 @@
}
-
-
-
-
-
@Override
protected Map<String, Wikitty> getAllWikitties() {
Map<String, Wikitty> result = new HashMap<String, Wikitty>();
-
- for (Object oId: wikittyIndex.keySet()){
- String id= oId.toString();
+
+ for (Object oId : wikittyIndex.keySet()) {
+ String id = oId.toString();
result.put(id, restore(id));
}
- return result;
+ return result;
}
-
@Override
public WikittyEvent deleteTree(String securityToken, String treeNodeId) {
@@ -329,9 +306,6 @@
}
-
-
-
protected Wikitty restore(String wikittyId) {
Wikitty wikit = null;
@@ -358,7 +332,7 @@
// set labels computate name
String sep = wikittyMetadata
- .getProperty(WikittyPublicationExternalize.PATH_SEPARATOR);
+ .getProperty(WikittyPublicationExternalize.PATH_SEPARATOR_PROPERTIE_KEY);
String[] namPath = StringUtil.split(path, sep);
String wikittyName = namPath[namPath.length - 1];
@@ -372,8 +346,6 @@
WikittyLabelHelper.addLabels(wikit, label);
-
-
if (mimeHelper.isPubTextExtension(fileExtension)) {
// wikitty pub text compiled
wikit.addExtension(WikittyPubTextImpl.extensions);
@@ -389,10 +361,10 @@
JarEntry wikittyclass = wikittyJarRepository.getJarEntry(path
+ WikittyPublicationExternalize.COMPILED_EXTENSION);
- WikittyPubTextHelper.setContent(wikit,
- this.getStringContent(wikittyJared));
- WikittyPubTextCompiledHelper.setByteCode(wikit,
- this.getByteContent(wikittyclass));
+ WikittyPubTextHelper.setContent(wikit, JarUtil
+ .getStringContent(wikittyJarRepository, wikittyJared));
+ WikittyPubTextCompiledHelper.setByteCode(wikit, JarUtil
+ .getByteContent(wikittyJarRepository, wikittyclass));
} else {
// wikitty pub data
@@ -403,8 +375,8 @@
WikittyPubDataHelper.setName(wikit, wikittyName);
WikittyPubDataHelper.setFileExtension(wikit, fileExtension);
- WikittyPubDataHelper.setContent(wikit,
- this.getByteContent(wikittyJared));
+ WikittyPubDataHelper.setContent(wikit, JarUtil.getByteContent(
+ wikittyJarRepository, wikittyJared));
}
} catch (Exception e) {
@@ -414,45 +386,5 @@
return wikit;
}
-
-
- public String getStringContent(JarEntry jarEntry) throws IOException {
- BufferedReader buffer = new BufferedReader(new InputStreamReader(
- wikittyJarRepository.getInputStream(jarEntry)));
- StringBuffer result = new StringBuffer();
- char[] cbuf = new char[2000];
-
- int nb = buffer.read(cbuf);
- while (nb != -1) {
- result.append(cbuf, 0, nb);
- nb = buffer.read(cbuf);
- }
- buffer.close();
- return result.toString();
-
- }
-
- public byte[] getByteContent(JarEntry jarEnt) throws IOException {
-
- ByteArrayOutputStream content;
- // Extract this to a byte utils ?
- InputStream in = new BufferedInputStream(
- wikittyJarRepository.getInputStream(jarEnt));
- try {
- content = new ByteArrayOutputStream();
- BufferedOutputStream tmp = new BufferedOutputStream(content);
- try {
- for (int b = in.read(); b != -1; b = in.read()) {
- tmp.write(b);
- }
- } finally {
- tmp.close();
- }
- } finally {
- in.close();
- }
- return content.toByteArray();
- }
-
}
Modified: 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-12 15:29:48 UTC (rev 1078)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-07-13 13:59:54 UTC (rev 1079)
@@ -32,6 +32,8 @@
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;
@@ -62,8 +64,6 @@
/** 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.
@@ -91,9 +91,31 @@
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
*/
@@ -182,7 +204,7 @@
// once on the service origin
applicationConfig.setOption(WIKITTY_SERVICE_INTERLOCUTEUR, new String(
- target.replaceAll("\\#.*", "")));
+ target.replaceAll(LABEL_REGEX, StringUtils.EMPTY)));
ApplicationConfig temp1 = setUpApplicationConfigServerConnector(uriOrigin);
@@ -193,7 +215,7 @@
// wikittypublication file system
// it can need it to store wikittyservice property
applicationConfig.setOption(WIKITTY_SERVICE_INTERLOCUTEUR, new String(
- origin.replaceAll("\\#.*", "")));
+ origin.replaceAll(LABEL_REGEX, StringUtils.EMPTY)));
// once on the service target
ApplicationConfig temp2 = setUpApplicationConfigServerConnector(uriTarget);
@@ -445,28 +467,28 @@
result.setOptions(applicationConfig.getFlatOptions());
String url = uri.toASCIIString();
- if (uri.getScheme().equals("file")) {
+ if (uri.getScheme().equals(FILE_URI_PREFIX)) {
result.setOption(
WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS
- .getKey(),
- WikittyPublicationFileSystem.class.getName());
- } else if (uri.getScheme().equals("cajo")) {
+ .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("\\#.*", ""));
+ url = new String(url.replaceAll(LABEL_REGEX, StringUtils.EMPTY));
- } else if (uri.getScheme().equals("hessian")) {
+ } 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("\\#.*", ""));
+ url = new String(url.replaceAll(LABEL_REGEX, StringUtils.EMPTY));
}
// set protocol to http, no use finally
@@ -474,8 +496,11 @@
* url = url.replaceFirst("["+uri.getScheme()+"]", "http");
*/
- log.info("set url " + url + " with component :"
- + result.getOption("wikitty.WikittyService.components"));
+ log.info("set url "
+ + url
+ + " with component :"
+ + result.getOption(WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS
+ .getKey()));
result.setOption(WikittyConfigOption.WIKITTY_SERVER_URL.getKey(), url);
@@ -539,10 +564,10 @@
// update is from wikitty service store to wikitty service File System
- String wikittyServiceInter = "";
- String wikittyServiceFileSystem = "";
+ String wikittyServiceInter = StringUtils.EMPTY;
+ String wikittyServiceFileSystem = StringUtils.EMPTY;
- String labelInitial = "";
+ String labelInitial = StringUtils.EMPTY;
PropertiesExtended homeProperty = null;
// Check number of argument
switch (uriFileSystem.length) {
@@ -564,18 +589,18 @@
// construct the current uri for wikitty service file system
// search the current label
PropertiesExtended metaPropertiesExtended = WikittyPublicationFileSystem
- .getWikittyPublicationProperties(
- currentDir,
+ .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() + "#" + labelCurrent;
+ + homePropertyDir.getAbsolutePath() + LABEL_DELIM
+ + labelCurrent;
labelInitial = homeProperty.getProperty(LABEL_KEY);
- wikittyServiceInter += "#" + label
+ wikittyServiceInter += LABEL_DELIM + label
+ labelCurrent.replaceFirst(labelInitial, "");
break;
@@ -586,7 +611,7 @@
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")) {
+ if (!originUri.getScheme().equals(FILE_URI_PREFIX)) {
// Exception
}
// then search for the home property file to load the wikitty
@@ -601,7 +626,7 @@
labelInitial = homeProperty.getProperty(LABEL_KEY);
- wikittyServiceInter += "#" + label
+ wikittyServiceInter += LABEL_DELIM + label
+ originUri.getFragment().replaceFirst(labelInitial, "");
break;
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-12 15:29:48 UTC (rev 1078)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-07-13 13:59:54 UTC (rev 1079)
@@ -77,6 +77,7 @@
static public String WIKITTYLABEL_SEPARATOR = ".";
+
/**
* The working directory of the wikitty service
*/
1
0
r1078 - in trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication: externalize synchro
by mfortun@users.nuiton.org 12 Jul '11
by mfortun@users.nuiton.org 12 Jul '11
12 Jul '11
Author: mfortun
Date: 2011-07-12 17:29:48 +0200 (Tue, 12 Jul 2011)
New Revision: 1078
Url: http://nuiton.org/repositories/revision/wikitty/1078
Log:
* add some documentation
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/AbstractDecoredClass.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyPublicationClassLoader.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/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/WikittyFileUtil.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/AbstractDecoredClass.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/AbstractDecoredClass.java 2011-07-12 09:34:27 UTC (rev 1077)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/AbstractDecoredClass.java 2011-07-12 15:29:48 UTC (rev 1078)
@@ -2,6 +2,18 @@
import java.util.Map;
+
+/**
+ * Abstract class for the skeleton and signature for wikittyPubText content
+ * transform and compile as Java class.
+ *
+ * This class allow the evaluator engine to call the eval method to return
+ * the result of the compiled code from the wikitty pub text content.
+ *
+ *
+ * @author mfortun
+ *
+ */
public abstract class AbstractDecoredClass {
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyPublicationClassLoader.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyPublicationClassLoader.java 2011-07-12 09:34:27 UTC (rev 1077)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyPublicationClassLoader.java 2011-07-12 15:29:48 UTC (rev 1078)
@@ -1,11 +1,24 @@
package org.nuiton.wikitty.publication.externalize;
+
+/**
+ * A simple classloader extension to allow adding java class with bytecode
+ * @author mfortun
+ *
+ */
public class WikittyPublicationClassLoader extends ClassLoader {
public WikittyPublicationClassLoader() {
super(WikittyPublicationClassLoader.class.getClassLoader());
}
+
+ /**
+ * use to add a class inside the class path from bytecode
+ * @param name the name of the class
+ * @param b the bytecode of the class
+ * @return the class loaded
+ */
public Class<?> addClass(String name, byte[] b) {
int off = 0;
int len = b.length;
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-12 09:34:27 UTC (rev 1077)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyServiceJarLoader.java 2011-07-12 15:29:48 UTC (rev 1078)
@@ -24,10 +24,14 @@
import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.entities.WikittyExtension;
import org.nuiton.wikitty.entities.WikittyImpl;
+import org.nuiton.wikitty.entities.WikittyLabel;
import org.nuiton.wikitty.entities.WikittyLabelHelper;
import org.nuiton.wikitty.entities.WikittyLabelImpl;
+import org.nuiton.wikitty.publication.entities.WikittyPubData;
import org.nuiton.wikitty.publication.entities.WikittyPubDataHelper;
import org.nuiton.wikitty.publication.entities.WikittyPubDataImpl;
+import org.nuiton.wikitty.publication.entities.WikittyPubText;
+import org.nuiton.wikitty.publication.entities.WikittyPubTextCompiled;
import org.nuiton.wikitty.publication.entities.WikittyPubTextCompiledHelper;
import org.nuiton.wikitty.publication.entities.WikittyPubTextCompiledImpl;
import org.nuiton.wikitty.publication.entities.WikittyPubTextHelper;
@@ -197,10 +201,14 @@
@Override
public List<String> getAllExtensionIds(String securityToken) {
- // TODO mfortun
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
+ List<String> result = new LinkedList<String>();
+ result.add(WikittyPubData.EXT_WIKITTYPUBDATA);
+ result.add(WikittyPubText.EXT_WIKITTYPUBTEXT);
+ result.add(WikittyPubTextCompiled.EXT_WIKITTYPUBTEXTCOMPILED);
+ result.add(WikittyLabel.EXT_WIKITTYLABEL);
+
+ return result;
}
@Override
Modified: 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-12 09:34:27 UTC (rev 1077)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/AbstractWikittyFileService.java 2011-07-12 15:29:48 UTC (rev 1078)
@@ -37,6 +37,16 @@
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{
@@ -45,6 +55,16 @@
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
@@ -429,10 +449,7 @@
}
}
-
- protected abstract Map<String, Wikitty> getAllWikitties();
-
-
+
@Override
public List<PagedResult<String>> findAllByCriteria(String securityToken,
List<Criteria> criteria) {
Modified: 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-12 09:34:27 UTC (rev 1077)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/MimeTypePubHelper.java 2011-07-12 15:29:48 UTC (rev 1078)
@@ -114,14 +114,17 @@
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
*
Modified: 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-12 09:34:27 UTC (rev 1077)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyFileUtil.java 2011-07-12 15:29:48 UTC (rev 1078)
@@ -8,6 +8,14 @@
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 {
/**
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-12 09:34:27 UTC (rev 1077)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-07-12 15:29:48 UTC (rev 1078)
@@ -34,6 +34,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -52,6 +53,7 @@
import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.entities.WikittyExtension;
import org.nuiton.wikitty.entities.WikittyImpl;
+import org.nuiton.wikitty.entities.WikittyLabel;
import org.nuiton.wikitty.entities.WikittyLabelHelper;
import org.nuiton.wikitty.entities.WikittyLabelImpl;
import org.nuiton.wikitty.publication.entities.WikittyPubData;
@@ -488,10 +490,14 @@
@Override
public List<String> getAllExtensionIds(String securityToken) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
+ List<String> result = new LinkedList<String>();
+ result.add(WikittyPubData.EXT_WIKITTYPUBDATA);
+ result.add(WikittyPubText.EXT_WIKITTYPUBTEXT);
+ //result.add(WikittyPubTextCompiled.EXT_WIKITTYPUBTEXTCOMPILED);
+ result.add(WikittyLabel.EXT_WIKITTYLABEL);
+
+ return result;
}
@Override
@@ -853,7 +859,7 @@
log.debug("restore wikitty id:" + id + " file: " + fileId);
Wikitty result = new WikittyImpl(id);
-
+
result.addExtension(WikittyLabelImpl.extensionWikittyLabel);
// preparation for mime research and file research
1
0
r1077 - in trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication: externalize synchro
by mfortun@users.nuiton.org 12 Jul '11
by mfortun@users.nuiton.org 12 Jul '11
12 Jul '11
Author: mfortun
Date: 2011-07-12 11:34:27 +0200 (Tue, 12 Jul 2011)
New Revision: 1077
Url: http://nuiton.org/repositories/revision/wikitty/1077
Log:
* add new method for mimeTypeHelper
* fix some import
* correct restore for wikitty save as jar
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/WikittyServiceJarLoader.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/WikittyPublicationFileSystem.java
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-12 08:46:28 UTC (rev 1076)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyPublicationExternalize.java 2011-07-12 09:34:27 UTC (rev 1077)
@@ -3,7 +3,6 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.ArrayList;
import java.util.Set;
import org.apache.commons.lang.StringEscapeUtils;
import org.nuiton.util.ApplicationConfig;
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-12 08:46:28 UTC (rev 1076)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/externalize/WikittyServiceJarLoader.java 2011-07-12 09:34:27 UTC (rev 1077)
@@ -80,6 +80,7 @@
public WikittyServiceJarLoader(ApplicationConfig config) {
try {
+
File jarLocation = new File(config.getOption(JAR_LOCATION_KEY));
wikittyJarRepository = new JarFile(jarLocation);
@@ -363,7 +364,9 @@
WikittyLabelHelper.addLabels(wikit, label);
- if (mimeHelper.isPubTextMime(fileExtension)) {
+
+
+ if (mimeHelper.isPubTextExtension(fileExtension)) {
// wikitty pub text compiled
wikit.addExtension(WikittyPubTextImpl.extensions);
wikit.addExtension(WikittyPubTextCompiledImpl.extensionWikittyPubTextCompiled);
Modified: 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-12 08:46:28 UTC (rev 1076)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/AbstractWikittyFileService.java 2011-07-12 09:34:27 UTC (rev 1077)
@@ -1,6 +1,6 @@
package org.nuiton.wikitty.publication.synchro;
-import java.io.File;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -11,11 +11,8 @@
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.util.FileUtil;
-import org.nuiton.util.StringUtil;
import org.nuiton.wikitty.WikittyException;
import org.nuiton.wikitty.WikittyService;
import org.nuiton.wikitty.WikittyUtil;
Modified: 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-12 08:46:28 UTC (rev 1076)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/MimeTypePubHelper.java 2011-07-12 09:34:27 UTC (rev 1077)
@@ -63,6 +63,7 @@
mimePubText.add("application/javascript");
mapExtensionMime.put("wp", "application/javascript");
+ mapExtensionMime.put("js", "application/javascript");
mapExtensionMime.put("jpg", "image/jpeg");
mapExtensionMime.put("png", "image/png");
}
@@ -112,7 +113,15 @@
public boolean isPubTextMime(String mimeType) {
return mimePubText.contains(mimeType);
}
+
+
+ public boolean isPubTextExtension(String extension) {
+ return isPubTextMime(getMimeForExtension(extension));
+ }
+
+
+
/**
* Add a mimeType corresponding to a WikittyPubText
*
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-12 08:46:28 UTC (rev 1076)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-07-12 09:34:27 UTC (rev 1077)
@@ -34,12 +34,10 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import java.util.Map.Entry;
import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.bidimap.DualHashBidiMap;
import org.apache.commons.logging.Log;
@@ -63,9 +61,7 @@
import org.nuiton.wikitty.publication.entities.WikittyPubTextHelper;
import org.nuiton.wikitty.publication.entities.WikittyPubTextImpl;
import org.nuiton.wikitty.search.Criteria;
-import org.nuiton.wikitty.search.PagedResult;
import org.nuiton.wikitty.search.TreeNodeResult;
-import org.nuiton.wikitty.search.operators.Restriction;
import org.nuiton.wikitty.services.WikittyEvent;
import org.nuiton.wikitty.services.WikittyListener;
import org.nuiton.wikitty.publication.synchro.WikittyFileUtil;
1
0