Author: xlawrence
Date: Tue May 15 16:31:37 2007
New Revision: 17314
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D17314&repname=
=3Djahia
Log:
support for multipart requests
Modified:
branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/taglibs/form/FormC=
ontentMapperHandlerTag.java
Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/taglibs/form=
/FormContentMapperHandlerTag.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/taglibs/form/FormContentMapperHandlerTag.ja=
va&rev=3D17314&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/taglibs/form/FormC=
ontentMapperHandlerTag.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/taglibs/form/FormC=
ontentMapperHandlerTag.java Tue May 15 16:31:37 2007
@@ -14,13 +14,8 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied=
. =
* See the License for the specific language governing permissions and =
* limitations under the License.
- */package org.jahia.taglibs.form;
-
-import java.util.Enumeration;
-
-import javax.servlet.ServletRequest;
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.tagext.BodyTagSupport;
+ */
+package org.jahia.taglibs.form;
=
import org.jahia.data.JahiaData;
import org.jahia.data.beans.ContainerListBean;
@@ -32,6 +27,8 @@
import org.jahia.data.fields.JahiaFieldDefinition;
import org.jahia.exceptions.JahiaException;
import org.jahia.hibernate.model.JahiaAclEntry;
+import org.jahia.params.ProcessingContext;
+import org.jahia.params.ParamBean;
import org.jahia.registries.ServicesRegistry;
import org.jahia.services.acl.JahiaBaseACL;
import org.jahia.services.containers.ContentContainer;
@@ -40,6 +37,12 @@
import org.jahia.services.usermanager.JahiaUser;
import org.jahia.services.usermanager.JahiaUserManagerService;
import org.jahia.services.workflow.WorkflowService;
+import org.jahia.tools.files.FileUpload;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+import java.util.Enumeration;
=
/**
* <p>Title: Form handler that maps to Content objects </p>
@@ -47,78 +50,76 @@
* submission to a container to be added in a container list.</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: Jahia Ltd</p>
+ *
* @author Serge Huber
* @version 1.0
- *
- *
* @jsp:tag name=3D"formContentMapperHandler" body-content=3D"empty"
* description=3D"Processes a submitted form and maps the parameters to fi=
elds in a container and adds the container
* to the specified container list.
- *
+ * <p/>
* <p><attriInfo>In the example below, the formContentMapperHandler tag de=
fines the mapping between the submitToTestContainerList form and
* its associated container list testContainerList. The attribute 'submitM=
arker' specifies which form on the page to link to
* and 'listName' the associated container list. Its value can be set to a=
ny <input> tag of the form with a
* unique name (to the page) such as submitToTestContainerList in this cas=
e. If the 'submitMarker' attribute is undefined,
* the form will not be processed.
- *
- *<p>Given the fields in the submitToTestContainerList form, the formConte=
ntMapperHandler tag expects to find the fields named
+ * <p/>
+ * <p>Given the fields in the submitToTestContainerList form, the formCont=
entMapperHandler tag expects to find the fields named
* title, content and bookformat in the container list testContainerList =
on the current page.
* If this isn't the case, an error is generated.
- *
+ * <p/>
* <p><b>Example :</b>
- * <p>
- ...<br>
- <content:declareContainerList name=3D\"testContainerList\" title=
=3D\"Content Container list\"><br>
- <content:declareContainer><br>
- <content:declareField name=3D\"title\" t=
itle=3D\"Title\" type=3D\"SmallText\" value=3D\"Lord of the Flies\"/><br>
- <content:declareField name=3D\"bookforma=
t\" title=3D\"BookFormat\" type=3D\"SharedSmallText\" /><br>
- <content:declareField name=3D\"content\"=
title=3D\"Content\" type=3D\"BigText\" /><br>
- </content:declareContainer><br>
- </content:declareContainerList><br>
- <%<br>
- ...<br>
- String bypassUrl =3D jParams.composePageUrl(jData.page().getID()=
);<br>
- ...<br>
- %><br>
- </head><br>
- <body><br>
- ...<br>
- <br>
- <h1>Add container with form</h1><br>
- <br>
- <content:containerList name=3D\"testContainerList\" id=3D\"testC=
ontainerList\"><br>
- <br>
- <content:container id=3D\"testContainer\"><br>
- <h2><content:textField name=3D\"title\" defaul=
tValue=3D\"\"/><br>
- <content:textField name=3D\"bookformat\" defaultValue=3D\"\"/>=
;</h2><br>
- <content:bigTextField name=3D\"content\" defaultValu=
e=3D\"\"/><br>
- <br/><br>
- </content:container><br>
- <br>
- <hr/><br>
- <br>
- </content:containerList><br>
- <br>
- <content:formContentMapperHandler listName=3D\"testContainerList=
\" submitMarker=3D\"submitToTestContainerList\" /><br>
- <form action=3D\"<%=3DbypassUrl%>\" name=3D\"submitToConta=
inerList\" method=3D\"post\"><br>
- <input type=3D\"text\" name=3D\"title\" value=3D\"Lord of th=
e Flies\"/><br/><br>
- <input type=3D\"text\" name=3D\"bookformat\"/><br/>=
<br>
- <textarea name=3D\"content\"></textarea><br/><br>
- <input type=3D\"submit\" name=3D\"submitToTestContainerList\" valu=
e=3D\"Submit\"/><br>
- </form><br>
- ...<br>
-
-
- *
- *
+ * <p/>
+ * ...<br>
+ * <content:declareContainerList name=3D\"testContainerList\" tit=
le=3D\"Content Container list\"><br>
+ * <content:declareContainer><br>
+ * <content:declareField name=3D\"title\"=
title=3D\"Title\" type=3D\"SmallText\" value=3D\"Lord of the Flies\"/><=
br>
+ * <content:declareField name=3D\"bookfor=
mat\" title=3D\"BookFormat\" type=3D\"SharedSmallText\" /><br>
+ * <content:declareField name=3D\"content=
\" title=3D\"Content\" type=3D\"BigText\" /><br>
+ * </content:declareContainer><br>
+ * </content:declareContainerList><br>
+ * <%<br>
+ * ...<br>
+ * String bypassUrl =3D jParams.composePageUrl(jData.page().getID=
());<br>
+ * ...<br>
+ * %><br>
+ * </head><br>
+ * <body><br>
+ * ...<br>
+ * <br>
+ * <h1>Add container with form</h1><br>
+ * <br>
+ * <content:containerList name=3D\"testContainerList\" id=3D\"tes=
tContainerList\"><br>
+ * <br>
+ * <content:container id=3D\"testContainer\"><br>
+ * <h2><content:textField name=3D\"title\" defa=
ultValue=3D\"\"/><br>
+ * <content:textField name=3D\"bookformat\" defaultValue=3D\"\"/&=
gt;</h2><br>
+ * <content:bigTextField name=3D\"content\" defaultVa=
lue=3D\"\"/><br>
+ * <br/><br>
+ * </content:container><br>
+ * <br>
+ * <hr/><br>
+ * <br>
+ * </content:containerList><br>
+ * <br>
+ * <content:formContentMapperHandler listName=3D\"testContainerLi=
st\" submitMarker=3D\"submitToTestContainerList\" /><br>
+ * <form action=3D\"<%=3DbypassUrl%>\" name=3D\"submitToCon=
tainerList\" method=3D\"post\"><br>
+ * <input type=3D\"text\" name=3D\"title\" value=3D\"Lord of =
the Flies\"/><br/><br>
+ * <input type=3D\"text\" name=3D\"bookformat\"/><br/&g=
t;<br>
+ * <textarea name=3D\"content\"></textarea><br/><br>
+ * <input type=3D\"submit\" name=3D\"submitToTestContainerList\" value=
=3D\"Submit\"/><br>
+ * </form><br>
+ * ...<br>
+ * <p/>
+ * <p/>
+ * <p/>
+ * <p/>
* </attriInfo>"
- *
*/
=
public class FormContentMapperHandlerTag extends BodyTagSupport {
=
private static org.apache.log4j.Logger logger =3D
- org.apache.log4j.Logger.getLogger(FormContentMapperHandlerTag.clas=
s);
+ org.apache.log4j.Logger.getLogger(FormContentMapperHandlerTag.=
class);
=
private boolean immediatePublication =3D false;
private String listName =3D null;
@@ -127,150 +128,155 @@
private String submitMarker =3D null;
=
/**
- * @jsp:attribute name=3D"immediatePublication" required=3D"false" rt=
exprvalue=3D"true" type=3D"Boolean"
- * description=3D"This attribute specifies whether user-submitted con=
tainers should be immediately
- * validated or left in staging mode.
- * <p><attriInfo> The default value is 'false' i.e. it is saved in th=
e staging mode
- * only. The language is not specified so the content is automatical=
ly added in the browser's current
- * language. If necessary, you can get around this by declaring the f=
ields as shared type in the
- * container (i.e. type=3D\"SharedSmallText\") so that the value will=
be independent of the browser's language.
- * </attriInfo>"
+ * @jsp:attribute name=3D"immediatePublication" required=3D"false" rte=
xprvalue=3D"true" type=3D"Boolean"
+ * description=3D"This attribute specifies whether user-submitted cont=
ainers should be immediately
+ * validated or left in staging mode.
+ * <p><attriInfo> The default value is 'false' i.e. it is saved in the=
staging mode
+ * only. The language is not specified so the content is automaticall=
y added in the browser's current
+ * language. If necessary, you can get around this by declaring the fi=
elds as shared type in the
+ * container (i.e. type=3D\"SharedSmallText\") so that the value will =
be independent of the browser's language.
+ * </attriInfo>"
*/
- public boolean isImmediatePublication () {
+ public boolean isImmediatePublication() {
return immediatePublication;
}
=
- public void setImmediatePublication (boolean immediatePublication) {
+ public void setImmediatePublication(boolean immediatePublication) {
this.immediatePublication =3D immediatePublication;
}
=
/**
- * @jsp:attribute name=3D"listName" required=3D"false" rtexprvalue=3D=
"true"
- * description=3D"the name of the container list where to create and =
store user-submitted containers.
- * <p><attriInfo>
- * </attriInfo>"
+ * @jsp:attribute name=3D"listName" required=3D"false" rtexprvalue=3D"=
true"
+ * description=3D"the name of the container list where to create and s=
tore user-submitted containers.
+ * <p><attriInfo>
+ * </attriInfo>"
*/
- public String getListName () {
+ public String getListName() {
return listName;
}
=
- public void setListName (String listName) {
+ public void setListName(String listName) {
this.listName =3D listName;
}
=
/**
- * @jsp:attribute name=3D"storeAsUserName" required=3D"false" rtexprv=
alue=3D"true"
- * description=3D"give ACL rights to stored containers to the specifi=
ed user only.
- *
- * <p><attriInfo>By default, the ACL on the stored containers will gi=
ve Read/Write and Admin rights to user Guest,
- * it is wise to restrict this level of access to only a single user.
- * </attriInfo>"
+ * @jsp:attribute name=3D"storeAsUserName" required=3D"false" rtexprva=
lue=3D"true"
+ * description=3D"give ACL rights to stored containers to the specifie=
d user only.
+ * <p/>
+ * <p><attriInfo>By default, the ACL on the stored containers will giv=
e Read/Write and Admin rights to user Guest,
+ * it is wise to restrict this level of access to only a single user.
+ * </attriInfo>"
*/
- public String getStoreAsUserName () {
+ public String getStoreAsUserName() {
return storeAsUserName;
}
=
- public void setStoreAsUserName (String storeAsUserName) {
+ public void setStoreAsUserName(String storeAsUserName) {
this.storeAsUserName =3D storeAsUserName;
}
=
/**
- * @jsp:attribute name=3D"storeAsGroupName" required=3D"false" rtexpr=
value=3D"true" type=3D"Boolean"
- * description=3D"give ACL rights to stored containers to the specifi=
ed user only.
- * <p><attriInfo>
- * </attriInfo>"
+ * @jsp:attribute name=3D"storeAsGroupName" required=3D"false" rtexprv=
alue=3D"true" type=3D"Boolean"
+ * description=3D"give ACL rights to stored containers to the specifie=
d user only.
+ * <p><attriInfo>
+ * </attriInfo>"
*/
- public String getStoreAsGroupName () {
+ public String getStoreAsGroupName() {
return storeAsGroupName;
}
=
- public void setStoreAsGroupName (String storeAsGroupName) {
+ public void setStoreAsGroupName(String storeAsGroupName) {
this.storeAsGroupName =3D storeAsGroupName;
}
=
/**
- * @jsp:attribute name=3D"submitMarker" required=3D"false" rtexprvalu=
e=3D"true" type=3D"Boolean"
- * description=3D"The attribute submitMarker specifies which form on=
the page to link to.
- * <p><attriInfo>Its value can be set to any <input> tag of the=
form with a unique name (to the page).
- * </attriInfo>"
+ * @jsp:attribute name=3D"submitMarker" required=3D"false" rtexprvalue=
=3D"true" type=3D"Boolean"
+ * description=3D"The attribute submitMarker specifies which form on =
the page to link to.
+ * <p><attriInfo>Its value can be set to any <input> tag of the =
form with a unique name (to the page).
+ * </attriInfo>"
*/
- public String getSubmitMarker () {
+ public String getSubmitMarker() {
return submitMarker;
}
=
- public void setSubmitMarker (String submitMarker) {
+ public void setSubmitMarker(String submitMarker) {
this.submitMarker =3D submitMarker;
}
=
- private void storeForm (JahiaContainerList containerList,
- JahiaData jData)
- throws JahiaException {
- if (containerList !=3D null && containerList.getID() =3D=3D 0) {
+ private void storeForm(final JahiaContainerList containerList,
+ final JahiaData jData)
+ throws JahiaException {
+ if (containerList =3D=3D null) {
+ logger.warn("storeForm -> null containerList passed.... Exitin=
g");
+ return;
+ }
+ if (containerList.getID() =3D=3D 0) {
// first let's resolve parent ACL ID
- int parentAclID =3D 0;
+ final int parentAclID;
if (containerList.getParentEntryID() !=3D 0) {
ContentContainer contentContainer =3D ContentContainer.
- getContainer(containerList.getParentEntryID());
+ getContainer(containerList.getParentEntryID());
parentAclID =3D contentContainer.getAclID();
} else {
parentAclID =3D jData.getProcessingContext().getPage().get=
AclID();
}
=
ServicesRegistry.getInstance().getJahiaContainersService().
- saveContainerListInfo(containerList, parentAclID,
- jData.getProcessingContext());
- JahiaBaseACL acl =3D containerList.getACL();
- JahiaAclEntry aclEntry =3D new JahiaAclEntry(7, 0); // READ & =
WRITE & ADMIN, 0 =3D ACL YES
- JahiaUser guest =3D ServicesRegistry.getInstance().
- getJahiaUserManagerService().
- lookupUser(jData.getProcessingContext().getS=
iteID(),
- storeAsUserName);
- JahiaGroup guestGroup =3D ServicesRegistry.getInstance().
- getJahiaGroupManagerService().
- lookupGroup(jData.getProcessingContext=
().getSiteID(),
- storeAsGroupName);
+ saveContainerListInfo(containerList, parentAclID,
+ jData.getProcessingContext());
+ final JahiaBaseACL acl =3D containerList.getACL();
+ final JahiaAclEntry aclEntry =3D new JahiaAclEntry(7, 0); // R=
EAD & WRITE & ADMIN, 0 =3D ACL YES
+ final JahiaUser guest =3D ServicesRegistry.getInstance().
+ getJahiaUserManagerService().
+ lookupUser(jData.getProcessingContext().getSiteID(),
+ storeAsUserName);
+ final JahiaGroup guestGroup =3D ServicesRegistry.getInstance().
+ getJahiaGroupManagerService().
+ lookupGroup(jData.getProcessingContext().getSiteID(),
+ storeAsGroupName);
=
acl.setUserEntry(guest, aclEntry);
acl.setGroupEntry(guestGroup, aclEntry);
}
- JahiaContainer container =3D new JahiaContainer(0,
- jData.getProcessingContext().getJahiaID(),
- jData.getProcessingContext().getPageID(),
- containerList.getID(),
- 0, /* rank */
- containerList.getAclID(),
- containerList.getctndefid(),
- 0, 2);
- JahiaContainerDefinition containerDef =3D container.getDefinition(=
);
+ final JahiaContainer container =3D new JahiaContainer(0,
+ jData.getProcessingContext().getJahiaID(),
+ jData.getProcessingContext().getPageID(),
+ containerList.getID(),
+ 0, /* rank */
+ containerList.getAclID(),
+ containerList.getctndefid(),
+ 0, 2);
+ final JahiaContainerDefinition containerDef =3D container.getDefin=
ition();
ServicesRegistry.getInstance().getJahiaContainersService().
- saveContainer(container, containerList.getID(), jData.getProce=
ssingContext());
+ saveContainer(container, containerList.getID(), jData.getP=
rocessingContext());
container.setLanguageCode(jData.getProcessingContext().getLocale()=
.toString());
container.fieldsStructureCheck(jData.getProcessingContext());
=
- Enumeration fieldDefEnum =3D containerDef.getStructure(null,
- jData.getProcessingContext().getPage().getPageTemplateID(),
- JahiaContainerStructure.JAHIA_FIELD);
+ final Enumeration fieldDefEnum =3D containerDef.getStructure(null,
+ jData.getProcessingContext().getPage().getPageTemplateID(),
+ JahiaContainerStructure.JAHIA_FIELD);
while (fieldDefEnum.hasMoreElements()) {
- JahiaContainerStructure curStructureElem =3D (JahiaContainerSt=
ructure)
- fieldDefEnum.nextElement();
- JahiaFieldDefinition curFieldDef =3D (JahiaFieldDefinition)
- curStructureElem.getObjectD=
ef();
- String curFieldName =3D curFieldDef.getName();
- String[] curFieldValues =3D jData.getProcessingContext().getPa=
rameterValues(
- curFieldName);
- JahiaField curField =3D container.getField(curFieldName);
- StringBuffer curFieldValueBuf =3D new StringBuffer();
+ final JahiaContainerStructure curStructureElem =3D (JahiaConta=
inerStructure) fieldDefEnum.nextElement();
+ final JahiaFieldDefinition curFieldDef =3D (JahiaFieldDefiniti=
on) curStructureElem.getObjectDef();
+ final String curFieldName =3D curFieldDef.getName();
+
+ final String[] curFieldValues;
+
+ curFieldValues =3D jData.getProcessingContext().getParameterVa=
lues(curFieldName);
+
+ final JahiaField curField =3D container.getField(curFieldName);
+ final StringBuffer curFieldValueBuf =3D new StringBuffer();
if (curFieldValues !=3D null) {
- for (int i=3D0; i < curFieldValues.length; i++) {
+ for (int i =3D 0; i < curFieldValues.length; i++) {
curFieldValueBuf.append(curFieldValues[i]);
if (i < (curFieldValues.length - 1)) {
curFieldValueBuf.append("$$$");
}
}
}
- String curFieldValue =3D curFieldValueBuf.toString();
- if ( (curFieldValues !=3D null) && (!"".equals(curFieldValue))=
&&
- (curField !=3D null)) {
+ final String curFieldValue =3D curFieldValueBuf.toString();
+ if ((curFieldValues !=3D null) && (!"".equals(curFieldValue)) =
&&
+ (curField !=3D null)) {
curField.setValue(curFieldValue);
curField.setObject(curFieldValue);
curField.save(jData.getProcessingContext());
@@ -287,15 +293,25 @@
ServicesRegistry.getInstance().getJahiaEventService().fireAggregat=
edEvents();
}
=
- public int doStartTag () {
+ public int doStartTag() {
// Form submit handling
=
- ServletRequest request =3D pageContext.getRequest();
- JahiaData jData =3D (JahiaData) request.getAttribute(
- "org.jahia.data.JahiaData");
+ HttpServletRequest request =3D (HttpServletRequest) pageContext.ge=
tRequest();
+ JahiaData jData =3D (JahiaData) request.getAttribute("org.jahia.da=
ta.JahiaData");
+
+ final String submitMarkerParam;
+ if (ProcessingContext.isMultipartRequest(request)) {
+ final FileUpload fupload =3D ((ParamBean) jData.getProcessingC=
ontext()).getFileUpload();
+ final String[] values =3D fupload.getParameterValues(getSubmit=
Marker());
+ if (values !=3D null && values.length > 0) {
+ submitMarkerParam =3D fupload.getParameterValues(getSubmit=
Marker())[0];
+ } else {
+ submitMarkerParam =3D null;
+ }
+ } else {
+ submitMarkerParam =3D request.getParameter(getSubmitMarker());
+ }
=
- String submitMarkerParam =3D jData.getProcessingContext().getParam=
eter(
- getSubmitMarker());
if (submitMarkerParam =3D=3D null) {
// this means we do not process the form as the submit marker =
is
// not present in the request.
@@ -303,28 +319,26 @@
}
=
if (getListName() !=3D null) {
- ContainerListBean containerListBean =3D (ContainerListBean)
- pageContext.findAttribut=
e(
- getListName());
+ ContainerListBean containerListBean =3D (ContainerListBean) pa=
geContext.findAttribute(getListName());
if (containerListBean =3D=3D null) {
logger.error(
- "Couldn't find any ContainerListBean object in context=
name=3D[" +
- getListName() + "]");
+ "Couldn't find any ContainerListBean object in con=
text name=3D[" +
+ getListName() + "]");
return SKIP_BODY;
}
try {
storeForm(containerListBean.getJahiaContainerList(), jData=
);
} catch (JahiaException je) {
logger.error(
- "Error while processing form content mapper handler:",=
je);
+ "Error while processing form content mapper handle=
r:", je);
}
}
=
return SKIP_BODY;
}
=
- public int doEndTag ()
- throws JspException {
+ public int doEndTag()
+ throws JspException {
// let's reinitialize the tag variables to allow tag object reuse =
in
// pooling.
immediatePublication =3D false;
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list