1 18 package org.alfresco.web.bean.wizard; 19 20 import java.io.Serializable ; 21 import java.util.HashMap ; 22 import java.util.Map ; 23 24 import javax.faces.context.FacesContext; 25 26 import org.alfresco.model.ContentModel; 27 import org.alfresco.model.ForumModel; 28 import org.alfresco.service.cmr.model.FileInfo; 29 import org.alfresco.service.cmr.repository.ContentService; 30 import org.alfresco.service.cmr.repository.ContentWriter; 31 import org.alfresco.service.cmr.repository.NodeRef; 32 import org.alfresco.service.namespace.QName; 33 import org.alfresco.web.app.AlfrescoNavigationHandler; 34 import org.alfresco.web.bean.ForumsBean; 35 import org.alfresco.web.bean.repository.Repository; 36 import org.alfresco.web.ui.common.Utils; 37 import org.apache.commons.logging.Log; 38 import org.apache.commons.logging.LogFactory; 39 40 45 public class NewTopicWizard extends NewSpaceWizard 46 { 47 private static final Log logger = LogFactory.getLog(NewTopicWizard.class); 48 49 protected String message; 50 51 protected ContentService contentService; 52 53 58 public String getMessage() 59 { 60 return this.message; 61 } 62 63 68 public void setMessage(String message) 69 { 70 this.message = message; 71 } 72 73 76 public void setContentService(ContentService contentService) 77 { 78 this.contentService = contentService; 79 } 80 81 84 public void init() 85 { 86 super.init(); 87 88 this.spaceType = ForumModel.TYPE_TOPIC.toString(); 89 this.message = null; 90 } 91 92 95 @Override 96 protected void performCustomProcessing(FacesContext context) throws Exception 97 { 98 if (this.editMode == false) 99 { 100 NodeRef containerNodeRef = this.createdNode; 102 103 String fileName = ForumsBean.createPostFileName(); 105 106 FileInfo fileInfo = this.fileFolderService.create(containerNodeRef, 107 fileName, ForumModel.TYPE_POST); 108 NodeRef postNodeRef = fileInfo.getNodeRef(); 109 110 if (logger.isDebugEnabled()) 111 logger.debug("Created post node with filename: " + fileName); 112 113 Map <QName, Serializable > titledProps = new HashMap <QName, Serializable >(3, 1.0f); 115 titledProps.put(ContentModel.PROP_TITLE, fileName); 116 this.nodeService.addAspect(postNodeRef, ContentModel.ASPECT_TITLED, titledProps); 117 118 if (logger.isDebugEnabled()) 119 logger.debug("Added titled aspect with properties: " + titledProps); 120 121 Map <QName, Serializable > editProps = new HashMap <QName, Serializable >(1, 1.0f); 122 editProps.put(ContentModel.PROP_EDITINLINE, true); 123 this.nodeService.addAspect(postNodeRef, ContentModel.ASPECT_INLINEEDITABLE, editProps); 124 125 if (logger.isDebugEnabled()) 126 logger.debug("Added inlineeditable aspect with properties: " + editProps); 127 128 ContentWriter writer = contentService.getWriter(postNodeRef, ContentModel.PROP_CONTENT, true); 130 writer.setMimetype(Repository.getMimeTypeForFileName(context, fileName)); 132 writer.setEncoding("UTF-8"); 133 writer.putContent(Utils.replaceLineBreaks(this.message)); 134 } 135 } 136 137 140 @Override 141 public String finish() 142 { 143 String outcome = super.finish(); 144 145 if (outcome != null) 147 { 148 outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME; 149 150 if (this.editMode == false) 151 { 152 this.browseBean.clickSpace(this.createdNode); 156 157 outcome = outcome + AlfrescoNavigationHandler.DIALOG_SEPARATOR + "showTopic"; 158 } 159 } 160 161 return outcome; 162 } 163 164 167 @Override 168 public String cancel() 169 { 170 super.cancel(); 171 172 return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME; 173 } 174 } 175 | Popular Tags |