org.mmbase.module.builders
Class AbstractServletBuilder

Package class diagram package AbstractServletBuilder
java.lang.Object
  extended by org.mmbase.util.functions.FunctionProvider
      extended by org.mmbase.module.core.MMTable
          extended by org.mmbase.module.core.MMObjectBuilder
              extended by org.mmbase.module.builders.AbstractServletBuilder
All Implemented Interfaces:
EventListener, NodeEventListener, RelationEventListener

public abstract class AbstractServletBuilder
extends MMObjectBuilder

Some builders are associated with a servlet. Think of images and attachments. There is some common functionality for those kind of builders, which is collected here.

Since:
MMBase-1.6
Version:
$Id: AbstractServletBuilder.java 45336 2011-02-21 13:53:21Z michiel $
Author:
Michiel Meeuwissen

Field Summary
protected  String externalUrlField
          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).
static String FIELD_FILENAME
           
static String FIELD_HANDLE
           
static String FIELD_MIMETYPE
           
static Parameter[] FORMAT_PARAMETERS
           
static Parameter[] GUI_PARAMETERS
          Can be used to construct a List for executeFunction argument (new Parameters(GUI_ARGUMENTS))
protected static Pattern legalizeFileName
           
static Parameter[] MIMETYPE_PARAMETERS
           
static String PROPERTY_EXTERNAL_URL_FIELD
           
protected  boolean usesBridgeServlet
          If this builder is association with a bridge servlet.
 
Fields inherited from class org.mmbase.module.core.MMObjectBuilder
AGE_PARAMETERS, broadCastChanges, DEFAULT_ALINEA, DEFAULT_EOL, description, descriptions, EVENT_TYPE_LOCAL, EVENT_TYPE_REMOTE, FIELD_NUMBER, FIELD_OBJECT_TYPE, FIELD_OWNER, fields, genericBlobCache, getFunctionsFunction, GUI_INDICATOR, guiFunction, infoFunction, internalVersion, nodeCache, oType, pluralNames, searchAge, singularNames, SYSTEM_OWNER, TEMPNODE_DEFAULT_SIZE, TMP_FIELD_EXISTS, TMP_FIELD_NUMBER, virtual, WRAP_PARAMETERS, wrapFunction
 
Fields inherited from class org.mmbase.module.core.MMTable
maxNodesFromQuery, mmb, storageConnector, tableName
 
Fields inherited from class org.mmbase.util.functions.FunctionProvider
functions, getFunctions
 
Constructor Summary
AbstractServletBuilder()
           
 
Method Summary
protected  boolean addFileName(MMObjectNode node, String servlet)
          Adds a filename to the path to a servlet, unless this does not make sense (not filename can be determined) or it was explicitely set not to, using the servlet context init parameter 'mmbase.servlet.<association>addfilename.
protected  void checkHandle(MMObjectNode node)
          Tries to fill all fields which are dependend on the 'handle' field.
 boolean commit(MMObjectNode node)
          Commit changes to this node to the storage layer.
protected  Object executeFunction(MMObjectNode node, String function, List<?> args)
          Overrides the executeFunction of MMObjectBuilder with a function to get the servletpath associated with this builder.
protected abstract  String getAssociation()
          This functions should return a string identifying where it is for.
 InputStream getBinary(MMObjectNode node)
           
protected  String getDefaultFileName()
           
protected abstract  String getDefaultPath()
          If no servlet path can be found via the association (if the servlet did not 'associate' itself with something, like servdb), then the getServletPath function will fall back to this.
 StringBuilder getFileName(MMObjectNode node, StringBuilder buf)
           
 StringBuilder getFileName(Node node, StringBuilder buf)
           
 String getGUIIndicator(MMObjectNode node, Parameters pars)
          A complicated default implementation for GUI.
 String getGUIIndicator(String field, MMObjectNode node)
          This is final, because getSGUIIndicator has to be overridden in stead
protected abstract  Set<String> getHandleFields()
          Returns the fields which tell something about the 'handle' field, and can be calculated from it.
protected  String getMimeType(MMObjectNode node)
          Returns the Mime-type associated with this node
protected  String getServletPath()
           
protected  String getServletPath(String root)
          Get a servlet path.
protected  String getSession(Parameters a, int nodeNumber)
           
protected abstract  String getSGUIIndicator(MMObjectNode node, Parameters a)
          'Servlet' builders need a way to transform security to the servlet, in the gui functions, so they have to implement the 'SGUIIndicators'
protected  String getSuperGUIIndicator(String field, MMObjectNode node)
          Gets the GUI indicator of the super class of this class, to avoid circular references in descendants, which will occur if they want to call super.getGUIIndicator().
 boolean init()
          Read 'externalUrlField' property
 int insert(String owner, MMObjectNode node)
          Insert a new object (content provided) in the cloud, including an entry for the object alias (if provided).
 
Methods inherited from class org.mmbase.module.core.MMObjectBuilder
addEventListener, addField, addLocalObserver, addRemoteObserver, broadcastChanges, checkAddTmpField, clearBlobCache, create, createAlias, createAlias, createIfNotExists, delete, equals, equals, executeFunction, fieldLocalChanged, getAncestors, getBlobCache, getClassName, getConfigFile, getConfigResource, getDataTypeCollector, getDBState, getDBType, getDefaultTeaser, getDefaultUrl, getDescendants, getDescription, getDescription, getDescriptions, getEmptyNode, getField, getFieldNames, getFields, getFields, getFunction, getFunctionParameters, getFunctions, getGUIIndicator, getHTML, getInitParameter, getInitParameters, getInitParameters, getInternalVersion, getList, getLocaleGUIIndicator, getLocaleGUIIndicator, getMachineName, getMaintainer, getNewNode, getNewTmpNode, getNextField, getNextField, getNode, getNode, getNode, getNodeFromCache, getNodeGUIIndicator, getNumber, getObjectType, getObjectValue, getParentBuilder, getPluralName, getPluralName, getPluralNames, getRelations_main, getSearchAge, getShort, getShortedByte, getShortedInputStream, getShortedText, getSingularName, getSingularName, getSingularNames, getSmartPath, getTmpNode, getURLEncode, getValue, getVersion, getWAP, getXMLPath, hasField, hashCode, hashCode, hostname_function, insert, isExtensionOf, isNodeCached, isNull, isVirtual, loadInitParameters, newFunctionInstance, nodeLocalChanged, nodeRemoteChanged, notify, notify, preCommit, process, removeEventListener, removeField, removeLocalObserver, removeNode, removeRelations, removeRemoteObserver, removeSyncNodes, replace, safeCache, sendFieldChangeSignal, setDefaults, setDescription, setDescriptions, setFields, setInitParameter, setMaintainer, setPluralNames, setSearchAge, setSingularNames, setUniqueValue, setUniqueValue, setValue, setValue, setVersion, setXMLPath, shutdown, testValidData, toString, toString, update, updateFields, wrap
 
Methods inherited from class org.mmbase.module.core.MMTable
count, count, created, getFullTableName, getMMBase, getNode, getNodes, getNodes, getNodes, getNodeType, getStorageConnector, getTableName, search, searchVector, setMMBase, setTableName, size
 
Methods inherited from class org.mmbase.util.functions.FunctionProvider
addFunction, createParameters, getFunction, getFunctions, getFunctionValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_EXTERNAL_URL_FIELD

public static final String PROPERTY_EXTERNAL_URL_FIELD
See Also:
Constant Field Values

FIELD_MIMETYPE

public static final String FIELD_MIMETYPE
See Also:
Constant Field Values

FIELD_FILENAME

public static final String FIELD_FILENAME
See Also:
Constant Field Values

FIELD_HANDLE

public static final String FIELD_HANDLE
See Also:
Constant Field Values

GUI_PARAMETERS

public static final Parameter[] GUI_PARAMETERS
Can be used to construct a List for executeFunction argument (new Parameters(GUI_ARGUMENTS))


FORMAT_PARAMETERS

public static final Parameter[] FORMAT_PARAMETERS

MIMETYPE_PARAMETERS

public static final Parameter[] MIMETYPE_PARAMETERS

usesBridgeServlet

protected boolean usesBridgeServlet
If this builder is association with a bridge servlet. If not, it should not put the 'session=' in the url to the servlet (because the serlvet probably is servdb, which does not understand that).


externalUrlField

protected String externalUrlField
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).


legalizeFileName

protected static final Pattern legalizeFileName
Constructor Detail

AbstractServletBuilder

public AbstractServletBuilder()
Method Detail

getAssociation

protected abstract String getAssociation()
This functions should return a string identifying where it is for. This is used when communicating with MMBaseServlet, to find the right servlet. For example 'images' or 'attachments'.


getDefaultPath

protected abstract String getDefaultPath()
If no servlet path can be found via the association (if the servlet did not 'associate' itself with something, like servdb), then the getServletPath function will fall back to this. For example 'img.db' or 'attachment.db'.


init

public boolean init()
Read 'externalUrlField' property

Overrides:
init in class MMObjectBuilder
Returns:
true if init was completed, false if uncompleted.
See Also:
MMObjectBuilder.create()

getServletPath

protected String getServletPath(String root)
Get a servlet path. Takes away the ? and the * which possibly are present in the servlet-mappings. You can put the argument(s) directly after this string.

Parameters:
root - The path to the application's root.

getServletPath

protected String getServletPath()

getMimeType

protected String getMimeType(MMObjectNode node)
Returns the Mime-type associated with this node


checkHandle

protected void checkHandle(MMObjectNode node)
Tries to fill all fields which are dependend on the 'handle' field. They will be filled automaticly if not still null.


getHandleFields

protected abstract Set<String> getHandleFields()
Returns the fields which tell something about the 'handle' field, and can be calculated from it.


insert

public int insert(String owner,
                  MMObjectNode node)
Description copied from class: MMObjectBuilder
Insert a new object (content provided) in the cloud, including an entry for the object alias (if provided). This method indirectly calls MMObjectBuilder.preCommit(MMObjectNode).

Overrides:
insert in class MMObjectBuilder
Parameters:
owner - The administrator creating the node
node - The object to insert. The object need be of the same type as the current builder.
Returns:
An int value which is the new object's unique number, -1 if the insert failed.

commit

public boolean commit(MMObjectNode node)
Description copied from class: MMObjectBuilder
Commit changes to this node to the storage layer. This method indirectly calls MMObjectBuilder.preCommit(MMObjectNode). Use only to commit changes - for adding node, use MMObjectBuilder.insert(String, MMObjectNode).

Overrides:
commit in class MMObjectBuilder
Parameters:
node - The node to be committed
Returns:
true if commit successful

getSGUIIndicator

protected abstract String getSGUIIndicator(MMObjectNode node,
                                           Parameters a)
'Servlet' builders need a way to transform security to the servlet, in the gui functions, so they have to implement the 'SGUIIndicators'


getSuperGUIIndicator

protected final String getSuperGUIIndicator(String field,
                                            MMObjectNode node)
Gets the GUI indicator of the super class of this class, to avoid circular references in descendants, which will occur if they want to call super.getGUIIndicator().


getGUIIndicator

public final String getGUIIndicator(MMObjectNode node,
                                    Parameters pars)
Description copied from class: MMObjectBuilder
A complicated default implementation for GUI.

Overrides:
getGUIIndicator in class MMObjectBuilder

getGUIIndicator

public final String getGUIIndicator(String field,
                                    MMObjectNode node)
This is final, because getSGUIIndicator has to be overridden in stead

Overrides:
getGUIIndicator in class MMObjectBuilder
Parameters:
field - the name field of the field to display
node - The node to display
Returns:
the display of the node's field as a String, null if not specified

getDefaultFileName

protected String getDefaultFileName()
Since:
MMBase-1.8

getFileName

public StringBuilder getFileName(MMObjectNode node,
                                 StringBuilder buf)
Since:
MMBase-1.8

getFileName

public StringBuilder getFileName(Node node,
                                 StringBuilder buf)
Since:
MMBase-1.9.6

addFileName

protected boolean addFileName(MMObjectNode node,
                              String servlet)
Adds a filename to the path to a servlet, unless this does not make sense (not filename can be determined) or it was explicitely set not to, using the servlet context init parameter 'mmbase.servlet.<association>addfilename.

Since:
MMBase-1.8

getSession

protected String getSession(Parameters a,
                            int nodeNumber)
Since:
MMBase-1.8.1

executeFunction

protected Object executeFunction(MMObjectNode node,
                                 String function,
                                 List<?> args)
Overrides the executeFunction of MMObjectBuilder with a function to get the servletpath associated with this builder. The field can optionally be the number field to obtain a full path to the served object.

Overrides:
executeFunction in class MMObjectBuilder
See Also:
MMObjectBuilder.executeFunction(MMObjectNode, String, java.util.List)

getBinary

public InputStream getBinary(MMObjectNode node)
Since:
MMBase-1.9.2


MMBase2 Core 2.0-SNAPSHOT - 2013-11-29T11:08