Update of
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action
In directory
james.mmbase.org:/tmp/cvs-serv9403/applications/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action
Modified Files:
CreateNodeAction.java AbstractNodeAction.java
Log Message:
work in progress
See also:
http://cvs.mmbase.org/viewcvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action
Index: CreateNodeAction.java
===================================================================
RCS file:
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action/CreateNodeAction.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- CreateNodeAction.java 8 Sep 2008 16:52:10 -0000 1.3
+++ CreateNodeAction.java 8 Oct 2008 08:28:57 -0000 1.4
@@ -26,10 +26,17 @@
private static final Logger log =
Logging.getLoggerInstance(CreateNodeAction.class);
private String nodeType;
+ private String nodeAsParam = "";
+
public final void setNodeType(String nodemanger) {
this.nodeType = nodemanger;
}
+ public final void setNodeAsParam(String paramName){
+ nodeAsParam = paramName;
+ }
+
+
public final String getNodenType() {
return this.nodeType;
}
@@ -55,6 +62,13 @@
}
}
+ @Override
+ protected void processNode(Transaction transaction) {
+ if(getNode() != null && ! StringUtils.isBlank(nodeAsParam)){
+ addParam(nodeAsParam, getNode().getNumber()+"");
+ }
+ }
+
/**
* This is the default implementation for creating new nodes. Override
this
* if the node manager has to be derived in a different way.
@@ -67,7 +81,7 @@
}
if (StringUtils.isBlank(nodeType)) {
log.debug("Can not create node manager instance: name
field is empty");
- addGlobalError("error.property.required", new String[]
{ "nodemanager", CreateNodeAction.class.getName() });
+ addGlobalError("error.property.required", new String[]
{ "nodeType", CreateNodeAction.class.getName() });
return null;
} else if (transaction.hasNodeManager(nodeType)) {
NodeManager nodeManager =
transaction.getNodeManager(nodeType);
Index: AbstractNodeAction.java
===================================================================
RCS file:
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action/AbstractNodeAction.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- AbstractNodeAction.java 22 Sep 2008 14:33:46 -0000 1.4
+++ AbstractNodeAction.java 8 Oct 2008 08:28:57 -0000 1.5
@@ -8,15 +8,17 @@
import javax.servlet.http.HttpServletRequest;
-import org.apache.commons.collections15.Factory;
+
import org.apache.commons.collections15.FactoryUtils;
import org.apache.commons.collections15.MapUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.mmbase.applications.vprowizards.spring.FieldError;
import org.mmbase.applications.vprowizards.spring.GlobalError;
import org.mmbase.applications.vprowizards.spring.ResultContainer;
import org.mmbase.applications.vprowizards.spring.cache.CacheFlushHint;
import org.mmbase.applications.vprowizards.spring.util.DateTime;
+import org.mmbase.applications.vprowizards.spring.util.HTMLFilterUtils;
import org.mmbase.bridge.Node;
import org.mmbase.bridge.NodeList;
import org.mmbase.bridge.NodeManager;
@@ -34,13 +36,19 @@
public abstract class AbstractNodeAction extends Action {
private Map<String, String> fields = new HashMap<String, String>();
-// private Map<String, DateTime> dateFields = new HashMap<String,
DateTime>();
- private Map<String, DateTime> dateFields =
- MapUtils.lazyMap(new HashMap<String, DateTime>(),
FactoryUtils.instantiateFactory(DateTime.class));
+ // private Map<String, DateTime> dateFields = new HashMap<String,
DateTime>();
+ private Map<String, DateTime> dateFields = MapUtils.lazyMap(new
HashMap<String, DateTime>(), FactoryUtils
+ .instantiateFactory(DateTime.class));
private String id = null;
private MultipartFile file = null;
private static org.mmbase.util.logging.Logger log =
Logging.getLoggerInstance(AbstractNodeAction.class);
+ /**
+ *This property can contain a set of comma-separated fields that will be
filtered by
+ * [EMAIL PROTECTED] HTMLFilterUtils#filter(String)}
+ */
+ private String htmlFields = "";
+
private Node node;
private boolean nodeChanged = false;
@@ -61,6 +69,9 @@
* [EMAIL PROTECTED] #addCachFlushHint(CacheFlushHint)} to add hints
* </ul>
* When the id is set on this action, the node is added to the idmap.
+ *
+ * @throws
+ * @throws XNIException
*/
@Override
public final void process(ResultContainer resultContainer) {
@@ -106,12 +117,80 @@
processNode(resultContainer.getTransaction());
}
+ //now check for html fields, and filter them if need be.
+ if(!StringUtils.isBlank(htmlFields)){
+ String[] htmlFieldArray = htmlFields.split("\\s*,\\s*");
+ for(String fieldName : htmlFieldArray){
+ checkField(fieldName);
+ }
+ //if this created an error, nonexisting fields are set.
+ if (resultContainer.hasFieldErrors()) {
+ return;
+ }
+ //filter the field values.
+ for(String fieldName: htmlFieldArray){
+ try {
+ log.debug("HTML filtering field " + fieldName );
+
node.setStringValue(fieldName,HTMLFilterUtils.filter(node.getStringValue(fieldName)));
+ } catch (Exception e) {
+ String msg = "Something went wrong filtering field
"+fieldName+" with the HTML filter: "+e.getMessage();
+ log.error(msg, e);
+ throw new RuntimeException(msg, e);
+ }
+ }
+ }
+
// even with a null node it can be necessary to create
a cache flush hint
// for instance when a node was deleted.
createCacheFlushHints();
}
}
+ public void setHtmlField(String htmlField) {
+ if(!StringUtils.isBlank(htmlFields)){
+ htmlFields = htmlFields + ",";
+ }
+ htmlFields = htmlFields + htmlField;
+ }
+
+ public Map<String, DateTime> getDateFields() {
+ return dateFields;
+ }
+
+ public void setDateFields(Map<String, DateTime> dateFields) {
+ this.dateFields = dateFields;
+ }
+
+ public Map<String, String> getFields() {
+ return fields;
+ }
+
+ public void setFields(Map<String, String> fields) {
+ this.fields = fields;
+ }
+
+ public MultipartFile getFile() {
+ return file;
+ }
+
+ public void setFile(MultipartFile file) {
+ this.file = file;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ log.info("** id is set to " + id);
+ this.id = id;
+ }
+
+ @Override
+ public String toString() {
+ return new ReflectionToStringBuilder(this).toString();
+ }
+
/**
* This template method determines if it is an error when the node is
null. Override this for concrete actions that
* actually don't need a node always.
@@ -156,7 +235,7 @@
* @param resultContainer
*/
protected void processNode(Transaction transaction) {
- };
+ }
protected final Locale getLocale() {
return resultContainer.getLocale();
@@ -256,10 +335,96 @@
protected abstract void createCacheFlushHints();
/**
+ * Check if a relation is possible from the given source to the given
destination with the given relation manager.
+ *
+ * @param relationManager
+ * @return
+ */
+ protected final boolean checkTypeRel(RelationManager relationManager, Node
sourceNode, Node destinationNode) {
+ NodeManager typerelManager =
relationManager.getCloud().getNodeManager("typerel");
+ String constraints = String.format("snumber=%s AND dnumber=%s AND
rnumber=%s", ""
+ + sourceNode.getNodeManager().getNumber(), "" +
destinationNode.getNodeManager().getNumber(), ""
+ + relationManager.getNumber());
+ NodeList nl = typerelManager.getList(constraints, null, null);
+ if (nl.size() == 0) {
+ log.warn(String.format(
+ "could not find typerel record with these constraints:
'%s', where snumber type is %s"
+ + " and dnumber type is %s and rnumber type is
%s", constraints, sourceNode
+ .getNodeManager().getName(),
destinationNode.getNodeManager().getName(), relationManager
+ .getName()));
+ addGlobalError("error.create.relation.typerel", new String[] {
sourceNode.getNodeManager().getName(),
+ destinationNode.getNodeManager().getName(),
relationManager.getName() });
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * can the current owner create a node of this type? set global error when
fail.
+ *
+ * @param nodeManager
+ * @return true when allowed.
+ */
+ protected final boolean mayWrite(NodeManager nodeManager) {
+ if (nodeManager == null) {
+ throw new NullPointerException("argument nodeManager is null");
+ }
+ boolean mayWrite = nodeManager.mayWrite();
+ if (!mayWrite) {
+ addGlobalError("error.authorization.write", new String[] {
nodeManager.getName() });
+ }
+ return mayWrite;
+ }
+
+ /**
+ * can the current owner create a node of this type? set global error when
fail.
+ *
+ * @param nodeManager
+ * @return true when allowed.
+ */
+ protected final boolean mayCreate(NodeManager nodeManager) {
+ if (nodeManager == null) {
+ throw new NullPointerException("argument nodeManager is null");
+ }
+ boolean mayCreate = nodeManager.mayCreateNode();
+ if (!mayCreate) {
+ addGlobalError("error.authorization.create", new String[] {
nodeManager.getName() });
+ }
+ return mayCreate;
+ }
+
+ /**
+ * can the current owner delete this node? set global error when fail.
+ *
+ * @param nodeManager
+ * @return true when allowed.
+ */
+ protected final boolean mayDelete(Node node) {
+ if (node == null) {
+ throw new NullPointerException("argument node is null");
+ }
+ boolean mayDelete = node.mayDelete();
+ if (!mayDelete) {
+ addGlobalError("error.authorization.delete", new String[] {
node.getNumber() + "",
+ node.getNodeManager().getName() });
+ }
+ return mayDelete;
+ }
+
+ protected final boolean hasErrors() {
+ return (resultContainer.hasGlobalErrors() ||
resultContainer.hasFieldErrors());
+ }
+
+ /**
* Check if all the fields set for this node action actually exist in
the nodemanager.
*/
private void checkBasicFields() {
for (String field : fields.keySet()) {
+ checkField(field);
+ }
+ }
+
+ private void checkField(String field) {
if (!node.getNodeManager().hasField(field)) {
log.warn(String.format(
"You try to set field '%s' on a
node of type '%s', but the nodetype does not have this field",
@@ -268,7 +433,6 @@
node.getNodeManager().getName()
});
}
}
- }
/**
* Set the fields, dateFields and file on the given node. Errors are
created when fields are not part of the present
@@ -328,9 +492,9 @@
* tries to set a number of other fields on the node (if they
exist):<br>
* <ul>
* <li>filename : the original file name (not the path)</li>
- * <li>filesize </li>
- * <li>size </li>
- * <li>mimetype </li>
+ * <li>filesize</li>
+ * <li>size</li>
+ * <li>mimetype</li>
* </ul>
* Current limitations are:
* <ul>
@@ -389,127 +553,7 @@
}
}
- /*
- * these are the setter methods for the data binding.
- */
-
- public Map<String, DateTime> getDateFields() {
- return dateFields;
- }
-
- public void setDateFields(Map<String, DateTime> dateFields) {
- this.dateFields = dateFields;
- }
-
- public Map<String, String> getFields() {
- return fields;
- }
-
- public void setFields(Map<String, String> fields) {
- this.fields = fields;
- }
-
- public MultipartFile getFile() {
- return file;
- }
-
- public void setFile(MultipartFile file) {
- this.file = file;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- log.info("** id is set to " + id);
- this.id = id;
- }
-
- /**
- * Check if a relation is possible from the given source to the given
destination with the given relation manager.
- *
- * @param relationManager
- * @return
- */
- protected final boolean checkTypeRel(RelationManager relationManager,
Node sourceNode, Node destinationNode) {
- NodeManager typerelManager =
relationManager.getCloud().getNodeManager("typerel");
- String constraints = String.format("snumber=%s AND dnumber=%s
AND rnumber=%s", ""
- + sourceNode.getNodeManager().getNumber(), "" +
destinationNode.getNodeManager().getNumber(), ""
- + relationManager.getNumber());
- NodeList nl = typerelManager.getList(constraints, null, null);
- if (nl.size() == 0) {
- log.warn(String.format("could not find typerel record
with these constraints: '%s', where snumber type is %s"
- + " and dnumber type is %s and rnumber
type is %s",
- constraints,
sourceNode.getNodeManager().getName(),
-
destinationNode.getNodeManager().getName(),
- relationManager.getName()));
- addGlobalError("error.create.relation.typerel", new
String[] { sourceNode.getNodeManager().getName(),
-
destinationNode.getNodeManager().getName(), relationManager.getName() });
- return false;
- }
- return true;
- }
-
- /**
- * can the current owner create a node of this type? set global error
when fail.
- *
- * @param nodeManager
- * @return true when allowed.
- */
- protected final boolean mayWrite(NodeManager nodeManager) {
- if (nodeManager == null) {
- throw new NullPointerException("argument nodeManager is
null");
- }
- boolean mayWrite = nodeManager.mayWrite();
- if (!mayWrite) {
- addGlobalError("error.authorization.write", new
String[] { nodeManager.getName() });
- }
- return mayWrite;
- }
-
- /**
- * can the current owner create a node of this type? set global error
when fail.
- *
- * @param nodeManager
- * @return true when allowed.
- */
- protected final boolean mayCreate(NodeManager nodeManager) {
- if (nodeManager == null) {
- throw new NullPointerException("argument nodeManager is
null");
+ protected final void addParam(String name, String value){
+ resultContainer.addParamToReturnURL(name, value);
}
- boolean mayCreate = nodeManager.mayCreateNode();
- if (!mayCreate) {
- addGlobalError("error.authorization.create", new
String[] { nodeManager.getName() });
- }
- return mayCreate;
- }
-
- /**
- * can the current owner delete this node? set global error when fail.
- *
- * @param nodeManager
- * @return true when allowed.
- */
- protected final boolean mayDelete(Node node) {
- if (node == null) {
- throw new NullPointerException("argument node is null");
- }
- boolean mayDelete = node.mayDelete();
- if (!mayDelete) {
- addGlobalError("error.authorization.delete", new
String[] { node.getNumber() + "",
- node.getNodeManager().getName() });
- }
- return mayDelete;
- }
-
- protected final boolean hasErrors() {
- return (resultContainer.hasGlobalErrors() ||
resultContainer.hasFieldErrors());
- }
-
- @Override
- public String toString() {
- return new ReflectionToStringBuilder(this).toString();
- }
-
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs