| From | Sent On | Attachments |
|---|---|---|
| joshna | Dec 3, 2007 2:29 am | .java, .jsp |
| Karthik Sudarshan | Dec 3, 2007 2:55 am |
| Subject: | Re: Code diffs for templateCreation | |
|---|---|---|
| From: | Karthik Sudarshan (kart...@gmail.com) | |
| Date: | Dec 3, 2007 2:55:46 am | |
| List: | net.java.dev.mirage.dev | |
Hi Joshna,
Please see inline.
On Dec 3, 2007 4:00 PM, joshna <Josh...@sun.com> wrote:
Hi
Templating feature is added to ccd portlet.Following are the new files
createTemplate.jsp TemplateBean.java
Now the user can create templates during ContentType creation and assign it to the content.
Thanks K.Joshna Index:
mirage-jcr-impl/ocm-impl/src/java/com/sun/portal/cms/mirage/ocm/utils/Constants.java ===================================================================
---
mirage-jcr-impl/ocm-impl/src/java/com/sun/portal/cms/mirage/ocm/utils/Constants.java (revision 59) +++
mirage-jcr-impl/ocm-impl/src/java/com/sun/portal/cms/mirage/ocm/utils/Constants.java (working copy) @@ -1,6 +1,6 @@ -/* +/* * CDDL HEADER START * The contents of this file are subject to the terms - * of the Common Development and Distribution License + * of the Common Development and Distribution License * (the License). You may not use this file except in * compliance with the License. * @@ -9,16 +9,16 @@ * See the License for the specific language governing * permission and limitations under the License. * - * When distributing Covered Code, include this CDDL - * Header Notice in each file and include the License file - * at legal/CDDLv1.0.txt.
+ * When distributing Covered Code, include this CDDL + * Header Notice in each file and include the License file + * at legal/CDDLv1.0.txt. * If applicable, add the following below the CDDL Header, * with the fields enclosed by brackets [] replaced by - * your own identifying information: + * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * [Name of File] [ver.__] [Date] - * + * * Copyright 2006 Sun Microsystems Inc. All Rights Reserved * CDDL HEADER END */ @@ -27,17 +27,18 @@
/** * This interface contains constants thats are used by the CMS framework. - * + * * @author prakash */ public interface Constants { - public static final String CMS_LOGGER_CONFIG_FILE = "CMSLoggerConfig.properties"; - public static final String LOG_FILE_LOCATION = "logFileLocation"; - public static final String LOG_LEVEL = "logLevel"; + public static final String CMS_LOGGER_CONFIG_FILE = "CMSLoggerConfig.properties"; + public static final String LOG_FILE_LOCATION = "logFileLocation"; + public static final String LOG_LEVEL = "logLevel"; public static final String CMSCONTENTNAME = "cms_arg_content_name"; - public static final String CREATEDCONTENT = "createdContent"; + public static final String CREATEDCONTENT = "createdContent"; public static final String SELECTEDCONTENT = "selectedContent"; public static final String SELECTED_VERSION = "selectedVersion"; + public static final String CREATED_CONTENT_TYPE="createdContentType"; public static final String CONTENTNAMELABEL = "Enter a name for this content "; public static final String CMS_GUEST_USER = "__CmsGuestUser0123456789"; public static final String USER = "user";
Index:
mirage-portlets/customContentDefinitions/src/conf/com/sun/portal/cms/portlet/ccd/resources/messages.properties ===================================================================
---
mirage-portlets/customContentDefinitions/src/conf/com/sun/portal/cms/portlet/ccd/resources/messages.properties (revision 59) +++
mirage-portlets/customContentDefinitions/src/conf/com/sun/portal/cms/portlet/ccd/resources/messages.properties (working copy) @@ -56,4 +56,14 @@ #listVersions.jsp properties versionNames=Version Names createdBy=Created By -versionListHeading=Version list for content : \ No newline at end of file +versionListHeading=Version list for content : + +#createTemplate.jsp properties + +templateName=Template Name +
Index:
mirage-portlets/customContentDefinitions/src/java/com/sun/portal/cms/portlet/ccd/beans/ContentTypeBean.java ===================================================================
---
mirage-portlets/customContentDefinitions/src/java/com/sun/portal/cms/portlet/ccd/beans/ContentTypeBean.java (revision 59) +++
mirage-portlets/customContentDefinitions/src/java/com/sun/portal/cms/portlet/ccd/beans/ContentTypeBean.java (working copy) @@ -36,6 +36,7 @@ import com.sun.portal.cms.mirage.ocm.service.custom.impl.ContentTypeServiceImpl; import com.sun.portal.cms.mirage.constants.custom.DataTypeConsts; import com.sun.portal.cms.mirage.constants.custom.DisplayTypeConsts; +import com.sun.portal.cms.mirage.ocm.utils.Constants; import com.sun.portal.cms.mirage.model.core.User; import com.sun.portal.cms.portlet.ccd.utils.ErrorConsts; import com.sun.portal.cms.portlet.ccd.utils.FacesUtil; @@ -86,6 +87,8 @@
private ContentTypeService contentTypeService;
+ private ContentType contentType; + private User user;
/** Creates a new instance of ContentTypeBean */ @@ -223,6 +226,14 @@ public void setNoOfRows(int noOfRows) { this.noOfRows = noOfRows; } + + public ContentType getContentType(){ + return this.contentType; + } + + public void setContentType(ContentType contentType){ + this.contentType=contentType; + }
private List<SelectItem> generateDataTypeOptions() { List<SelectItem> options = new ArrayList<SelectItem>(); @@ -360,15 +371,16 @@
public String createContentType() throws Exception{
- String result = "docTypeCreated"; + String result = "createTemplate";
- ContentType contentType = new ContentType(contentTypeName, workflowAssociated, fieldList, + contentType = new ContentType(contentTypeName, workflowAssociated, fieldList, workflow, true, versionable);
try { contentTypeService.createContentType(contentType); resetFields(); contentTypes = contentTypeService.getAvailableContentTypes(user); + FacesUtil.setSessionAttribute(Constants.CREATED_CONTENT_TYPE,contentType); } catch (Exception e) { e.printStackTrace(); result = "docTypeCreationFailed"; Index: mirage-portlets/customContentDefinitions/web/index.jsp =================================================================== --- mirage-portlets/customContentDefinitions/web/index.jsp (revision 59) +++ mirage-portlets/customContentDefinitions/web/index.jsp (working copy) @@ -79,6 +79,9 @@ <h:commandLink action="#{contentCreation.changeContentType}"> <f:param name="contentTypeSelected" value="#{contentTypeInstance.contentTypeName}" /> <h:graphicImage alt="Create Content Based on this Definition #{contentTypeInstance.contentTypeName}" url="/images/create.png" /> + </h:commandLink> + <h:commandLink value="Template" action="#{templateBean.listTemplates}"> + <f:param name="contentTypeSelected" value="#{contentTypeInstance.contentTypeName}" />
It would be better if you can use contentTypeUUID here instead of contentTypeName, as with the introduction of categories, contentTypeName will not be unique across the repository.
</h:commandLink> </h:column> </h:dataTable> Index: mirage-portlets/customContentDefinitions/web/WEB-INF/faces- config.xml ===================================================================
--- mirage-portlets/customContentDefinitions/web/WEB-INF/faces-config.xml (revision 59) +++ mirage-portlets/customContentDefinitions/web/WEB-INF/faces-config.xml (working copy) @@ -30,8 +30,8 @@ <to-view-id>/createContentType.jsp</to-view-id> </navigation-case> <navigation-case> - <from-outcome>docTypeCreated</from-outcome> - <to-view-id>/index.jsp</to-view-id> + <from-outcome>createTemplate</from-outcome> + <to-view-id>/createTemplate.jsp</to-view-id> </navigation-case> <navigation-case> <from-outcome>docTypeCreationFailed</from-outcome> @@ -86,6 +86,11 @@ <navigation-rule> <from-view-id>/index.jsp</from-view-id> <navigation-case> + <from-outcome>template</from-outcome> + <to-view-id>/listTemplates.jsp</to-view-id> + </navigation-case> + + <navigation-case> <from-outcome>docTypeDeleted</from-outcome> <to-view-id>/index.jsp</to-view-id> </navigation-case> @@ -170,6 +175,15 @@ <to-view-id>/index.jsp</to-view-id> </navigation-case> </navigation-rule> + + <navigation-rule> + <from-view-id>/createTemplate.jsp</from-view-id> + <navigation-case> + <from-outcome>templateCreated</from-outcome> + <to-view-id>/index.jsp</to-view-id> + </navigation-case> + </navigation-rule> +
<managed-bean> <managed-bean-name>contentType</managed-bean-name> @@ -188,5 +202,10 @@
<managed-bean-class> com.sun.portal.cms.portlet.ccd.beans.ContentVersionBean </managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> - + <managed-bean> + <managed-bean-name>templateBean</managed-bean-name> + <managed-bean-class>com.sun.portal.cms.portlet.ccd.beans.TemplateBean </managed-bean-class> + <managed-bean-scope>session</managed-bean-scope> + </managed-bean> + </faces-config>
/* * TemplateBean.java * * Created on November 30, 2007, 3:11 PM * * To change this template, choose Tools | Template Manager * and open the template in the edi.tor. */
Please change this and add the CDDL text here.
package com.sun.portal.cms.portlet.ccd.beans;
import com.sun.portal.cms.mirage.model.custom.ContentType; import com.sun.portal.cms.mirage.ocm.utils.Constants; import com.sun.portal.cms.mirage.service.custom.ContentTypeService; import com.sun.portal.cms.mirage.ocm.service.custom.impl.ContentTypeServiceImpl; import com.sun.portal.cms.mirage.model.core.User; import com.sun.portal.cms.mirage.model.custom.Template; import com.sun.portal.cms.portlet.ccd.utils.FacesUtil; import com.sun.portal.cms.mirage.ocm.repository.SessionProvider; import java.util.List; import javax.jcr.Session; import javax.portlet.PortletSession;
/** * * @author admin */ public class TemplateBean {
private Session jcrSession;
private String templateName;
private String templateMarkup;
private String templateUuid;
private int firstRowIndex = 0;
private int noOfRows = 5;
private String contentTypeName;
private String username;
private ContentTypeService contentTypeService;
private ContentType currentContentType;
private Template template;
private List<Template> templates;
/** Creates a new instance of TemplateBean */ public TemplateBean()throws Exception { PortletSession pSession = FacesUtil.getSession(); jcrSession = SessionProvider.getJCRSession(pSession); contentTypeService = new ContentTypeServiceImpl(jcrSession); currentContentType=(ContentType)pSession.getAttribute( Constants.CREATED_CONTENT_TYPE,PortletSession.APPLICATION_SCOPE); System.out.println("print current ContentType"+currentContentType);
Remove the System.out.println() statement here and further below.
}
public void setCurrentContentType(ContentType currentContentType){ this.currentContentType=currentContentType; }
public ContentType getCurrentContentType(){ return this.currentContentType; }
public void setTemplateName(String templateName){ this.templateName=templateName; }
public String getTemplateName(){ return this.templateName; }
public void setTemplateMarkup(String templateMarkup){ this.templateMarkup=templateMarkup; }
public String getTemplateMarkup(){ return this.templateMarkup; }
public List<Template> getTemplates(){ return this.templates; }
public int getFirstRowIndex() { return firstRowIndex; }
public void setFirstRowIndex(int firstRowIndex) { this.firstRowIndex = firstRowIndex; }
public int getNoOfRows() { return noOfRows; }
public void setNoOfRows(int noOfRows) { this.noOfRows = noOfRows; }
public String listTemplates(){ username = FacesUtil.getLoggedUserName(); contentTypeName = FacesUtil.getRequestParameter ("contentTypeSelected"); System.out.println("print contentTypeName"+contentTypeName); try{ if (contentTypeName != null && contentTypeName.length() > 0) { User user = new User(username); currentContentType = contentTypeService.getContentType (contentTypeName,user); templates=currentContentType.getTemplates(); System.out.println("print templates"+templates);
} }catch(Exception e){ FacesUtil.addMessage(e.getMessage(),e.getMessage()); } return "template"; }
public String saveTemplate()throws Exception{ try{ template =new Template(templateName,templateMarkup); System.out.println("print contentType"+currentContentType); contentTypeService.addTemplateToContentType (template,currentContentType); System.out.println("print templates"+currentContentType.getTemplates());
}catch(Exception e){ FacesUtil.addMessage(e.getMessage(), e.getMessage()); return "templateCreationFailed"; } return "templateCreated"; }
public String editTemplate()throws Exception{ username = FacesUtil.getLoggedUserName(); templateUuid = FacesUtil.getRequestParameter("templateSelected"); template = contentTypeService.getTemplateWithUUID(templateUuid); templateName=template.getName(); templateMarkup=template.getTemplateMarkup(); return "createTemplate"; }
public String saveNewVersion()throws Exception{ username = FacesUtil.getLoggedUserName(); Template newTemplate = new Template(templateName,templateMarkup); User user = new User(username); contentTypeService.saveNewVersionOfTemplate (newTemplate,currentContentType,user); return "template";
}
public String scrollFirst() { firstRowIndex = 0; return "success"; }
public String scrollPrevious() { firstRowIndex -= noOfRows; if (firstRowIndex < 0) { firstRowIndex = 0; } return "success"; }
public String scrollNext() { firstRowIndex += noOfRows; if (firstRowIndex >= templates.size()) { //Show the last set of rows scrollLast(); } return "success"; }
public String scrollLast() { firstRowIndex = templates.size() - templates.size() % noOfRows; return "success"; }
public boolean getBackDisabled() { return firstRowIndex == 0; }
public boolean getForwardDisabled() { if (templates == null) { return true; } return firstRowIndex >= templates.size() - noOfRows; }
}
Add CDDL header for the JSP. -Karthik
<%@ page contentType="text/html;charset=windows-1252"%> <%@ page import=" java.util.*" %> <%@ page import="java.util.Iterator" %> <%@ page import=" javax.portlet.*" %> <%@ page import=" com.sun.portal.cms.mirage.model.custom.ContentType" %> <%@ page import=" com.sun.portal.cms.mirage.model.custom.FormField" %> <%@ page import=" com.sun.portal.cms.mirage.ocm.utils.Constants" %> <%@ taglib uri=" http://java.sun.com/portlet" prefix="portlet" %> <%@ taglib uri=" http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri=" http://java.sun.com/jsf/core" prefix="f"%> <%String xinhapath= renderResponse.encodeURL(renderRequest.getContextPath()+"/xinha/XinhaCore.js");%>
-- The mistake people make while designing completely foolproof systems is underestimating the ingenuity of complete fools.






.java, .jsp