Update of /var/cvs/src/org/mmbase/module/builders
In directory james.mmbase.org:/tmp/cvs-serv7265/src/org/mmbase/module/builders

Modified Files:
        AbstractServletBuilder.java 
Log Message:
move some code from ReferredATtcahments to AbstractServletBuilder. This allows 
for the sue of url fields to store references to binary files, rather than the 
files themselves


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/module/builders


Index: AbstractServletBuilder.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/module/builders/AbstractServletBuilder.java,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -b -r1.53 -r1.54
--- AbstractServletBuilder.java 25 Feb 2008 12:35:05 -0000      1.53
+++ AbstractServletBuilder.java 29 Jul 2008 08:38:53 -0000      1.54
@@ -30,13 +30,15 @@
  *
  *
  * @author Michiel Meeuwissen
- * @version $Id: AbstractServletBuilder.java,v 1.53 2008/02/25 12:35:05 
michiel Exp $
+ * @version $Id: AbstractServletBuilder.java,v 1.54 2008/07/29 08:38:53 pierre 
Exp $
  * @since   MMBase-1.6
  */
 public abstract class AbstractServletBuilder extends MMObjectBuilder {
 
     private static final Logger log = 
Logging.getLoggerInstance(AbstractServletBuilder.class);
 
+    public static final String PROPERTY_EXTERNAL_URL_FIELD = 
"externalUrlField";
+
     public static final String FIELD_MIMETYPE   = "mimetype";
     public static final String FIELD_FILENAME   = "filename";
     public static final String FIELD_HANDLE     = "handle";
@@ -49,13 +51,9 @@
         new Parameter.Wrapper(MMObjectBuilder.GUI_PARAMETERS) // example, does 
not make too much sense :-)
     };
 
-
     public final static Parameter[] FORMAT_PARAMETERS   = {};
     public final static Parameter[] MIMETYPE_PARAMETERS = {};
 
-
-
-
     /**
      * In this string the path to the servlet is stored.
      */
@@ -110,10 +108,27 @@
     abstract protected String getDefaultPath();
 
     /**
+     * If set, this points out a field in the builder that optionally contains
+     * a url to an external (binary) source, which is then used as the stored
+     * attachment (instead of accessing the database).
+     */
+    protected String externalUrlField = null;
+
+    /**
+     * Read 'externalUrlField' property
+     */
+    public boolean init() {
+        String property = getInitParameter(PROPERTY_EXTERNAL_URL_FIELD);
+        if (property != null) {
+            externalUrlField = property;
+        }
+        return super.init();
+    }
+
+    /**
      * @param association e.g. 'images' or 'attachments'
      * @param root        Path to root of appliciation (perhaps relative).
      */
-
     private String getServletPathWithAssociation(String association, String 
root) {
         if (MMBaseContext.isInitialized()) {
             javax.servlet.ServletContext sx = 
MMBaseContext.getServletContext();
@@ -248,13 +263,16 @@
         }
         return result;
     }
+
     public boolean commit(MMObjectNode node) {
         Collection<String> changed = node.getChanged();
         if (log.isDebugEnabled()) {
             log.debug("Committing node " + node.getNumber() + " memory: " + 
SizeOf.getByteSize(node) + " fields " + changed);
         }
 
-        if (changed.contains(FIELD_HANDLE)) {
+        if (changed.contains(FIELD_HANDLE) ||
+            (externalUrlField != null && changed.contains(externalUrlField))
+           ) {
             // set those fields to null, which are not changed too:
             Collection<String> cp = new ArrayList<String>();
             cp.addAll(getHandleFields());
@@ -460,6 +478,15 @@
                 }
 
                 public String getFunctionValue(Node node, Parameters a) {
+                    // verify if the object is stored externally (in which case
+                    // its url has been filled in)
+                    // if so, return the url of the external source
+                    if (AbstractServletBuilder.this.externalUrlField != null ) 
{
+                        String url = node.getStringValue(externalUrlField);
+                        if (url != null && !url.equals("")) {
+                           return url;
+                        }
+                    }
                     StringBuilder servlet = getServletPath(a);
 
                     String session = getSession(a, node.getNumber());
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to