r1008 - trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts
Author: mfortun Date: 2011-06-29 18:03:04 +0200 (Wed, 29 Jun 2011) New Revision: 1008 Url: http://nuiton.org/repositories/revision/wikitty/1008 Log: * really implement method to know from a fieldname (wikittyext.fieldname) is allow in the form Modified: trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/WikittyFieldHandler.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-06-29 14:54:50 UTC (rev 1007) +++ trunk/wikitty-struts/src/main/java/org/nuiton/wikitty/struts/WikittyFieldHandler.java 2011-06-29 16:03:04 UTC (rev 1008) @@ -16,22 +16,25 @@ import org.nuiton.wikitty.entities.Wikitty; import org.nuiton.wikitty.entities.WikittyExtension; - public class WikittyFieldHandler { /** to use log facility, just put in your code: log.info(\"...\"); */ final static private Log log = LogFactory.getLog(WikittyFieldHandler.class); - - + protected Wikitty wikitty; protected WikittyProxy proxy; protected String include = ""; protected String exclude = ""; protected String order = ""; - + protected Boolean orderBefore; protected Set<String> fieldAdded; - + + protected Map<String, List<String>> excludeMap; + protected Map<String, List<String>> includeMap; + // if include is enable it change how to construct result + protected boolean includeEnable = false; + public Set<String> getFieldAdded() { return fieldAdded; } @@ -58,8 +61,8 @@ public void setOrderBefore(Boolean orderBefore) { this.orderBefore = orderBefore; - } - + } + public WikittyProxy getProxy() { return proxy; } @@ -74,6 +77,10 @@ public void setInclude(String include) { this.include = include; + // recalculate include map + // delegate construction of map + includeMap = constructIncludeExcludeMap(include); + includeEnable = includeMap.size() != 0; } public String getExclude() { @@ -82,6 +89,9 @@ public void setExclude(String exclude) { this.exclude = exclude; + // recalculate exclude map + // delegate construction of map + excludeMap = constructIncludeExcludeMap(exclude); } public String getOrder() { @@ -92,7 +102,6 @@ this.order = order; } - public Collection<ExtensionFieldStrutsBean> getWikittyField() { Map<String, ExtensionFieldStrutsBean> mapField = new HashMap<String, ExtensionFieldStrutsBean>(); @@ -105,12 +114,6 @@ * included and excluded, it will not appear in the result */ - // delegate construction of map - Map<String, List<String>> excludeMap = constructIncludeExcludeMap(exclude); - Map<String, List<String>> includeMap = constructIncludeExcludeMap(include); - // if include is enable it change how to construct result - boolean includeEnable = includeMap.size() != 0; - for (WikittyExtension ext : wikitty.getExtensions()) { String extName = ext.getName(); @@ -121,8 +124,8 @@ if ((excludeMap.containsKey(extName) && excludeMap.get(extName) .contains("*")) || (includeEnable && !includeMap.containsKey(extName))) { - log.debug("extension: "+extName + " Skipped"); - + log.debug("extension: " + extName + " Skipped"); + continue; } @@ -137,8 +140,10 @@ if ((excludeMap.containsKey(extName) && excludeMap.get(extName) .contains(fieldName)) || (includeEnable && !includeMap.get(extName).contains( - fieldName)) || fieldAdded.contains(extName+"."+fieldName)) { - log.debug("field: "+extName+"."+fieldName + " Skipped"); + fieldName)) + || fieldAdded.contains(extName + "." + fieldName)) { + log.debug("field: " + extName + "." + fieldName + + " Skipped"); continue; } @@ -149,7 +154,6 @@ temp.setLabel(temp.getName()); temp.setValue(""); - // set the field type. switch (fieldType.getType()) { case BINARY: @@ -167,10 +171,10 @@ Object valueObject = wikitty.getFieldAsObject( ext.getName(), fieldName); String valueString = ""; - + if (valueObject != null) { valueString = String.valueOf(valueObject); - } + } temp.setValue(valueString); @@ -186,25 +190,22 @@ } } - log.debug("Add field : " + temp ); + log.debug("Add field : " + temp); mapField.put(temp.getName(), temp); } } - /* - * save the field that will be write - * only if write befeore is selected because that mean that this - * method will be called two times when write the openning template - * of the wikitty field and when it close the wikitty field + * save the field that will be write only if write befeore is selected + * because that mean that this method will be called two times when + * write the openning template of the wikitty field and when it close + * the wikitty field */ - if( orderBefore ){ - log.debug("Order before select, add field to addedfield set: " + if (orderBefore) { + log.debug("Order before select, add field to addedfield set: " + mapField.keySet()); fieldAdded.addAll(mapField.keySet()); } - - String[] fieldOrder = StringUtil.split(order, ","); @@ -224,6 +225,7 @@ } } + orderedResult.addAll(mapField.values()); return orderedResult; } @@ -264,13 +266,39 @@ } return result; } - + public void addAddedField(String field) { - log.debug("Field added : " +field); + log.debug("Field added : " + field); fieldAdded.add(field); } - + public boolean isIncluded(String fieldname) { + + String[] fields = StringUtil.split(fieldname, "."); + + if (fields.length != 2) { + // TODO mfortun-2011-06-29 exception + } + String extName = fields[0]; + String fieldName = fields[1]; + + + // check if field is specifically exluded or if all the extention is + boolean excluded = excludeMap.containsKey(extName) + && (excludeMap.get(extName).contains(fieldName) || excludeMap + .get(extName).contains("*")); + + // check if field is specifically included or if all the extention is + boolean included = includeEnable + && includeMap.containsKey(extName) + && !(includeMap.get(extName).contains(fieldName) || includeMap + .get(extName).contains("*")); + // check if field allready added + boolean added = fieldAdded.contains(fieldname); + if (excluded || included || added) { + return false; + } + return true; } }
participants (1)
-
mfortun@users.nuiton.org