r1085 - in trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts: . component
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; } - + }
participants (1)
-
mfortun@users.nuiton.org