1 23 24 package org.infoglue.cms.applications.workflowtool.actions.examples; 25 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.List ; 29 import java.util.Map ; 30 31 import javax.servlet.http.HttpServletRequest ; 32 33 import org.dom4j.Document; 34 import org.dom4j.Element; 35 import org.exolab.castor.jdo.Database; 36 import org.exolab.castor.jdo.PersistenceException; 37 import org.exolab.castor.jdo.TransactionNotInProgressException; 38 import org.infoglue.cms.controllers.kernel.impl.simple.CastorDatabaseService; 39 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy; 40 import org.infoglue.cms.controllers.kernel.impl.simple.ContentStateController; 41 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController; 42 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController; 43 import org.infoglue.cms.entities.content.Content; 44 import org.infoglue.cms.entities.content.ContentVO; 45 import org.infoglue.cms.entities.content.ContentVersion; 46 import org.infoglue.cms.entities.content.ContentVersionVO; 47 import org.infoglue.cms.entities.management.Language; 48 import org.infoglue.cms.security.InfoGluePrincipal; 49 import org.infoglue.cms.util.CmsPropertyHandler; 50 import org.infoglue.cms.util.ConstraintExceptionBuffer; 51 import org.infoglue.cms.util.dom.DOMBuilder; 52 import org.infoglue.cms.util.workflow.CustomWorkflowAction; 53 import org.infoglue.deliver.controllers.kernel.impl.simple.ExtranetController; 54 55 import com.opensymphony.module.propertyset.PropertySet; 56 import com.opensymphony.workflow.WorkflowException; 57 58 public class CreateNews implements CustomWorkflowAction 59 { 60 public CreateNews() 61 { 62 } 63 64 65 public void invokeAction(String callerUserName, HttpServletRequest request, Map args, PropertySet ps) throws WorkflowException 66 { 67 System.out.println("Inside CreateNews.invokeAction"); 68 System.out.println("callerUserName:" + callerUserName); 69 70 89 InfoGluePrincipal infoGluePrincipal = (InfoGluePrincipal)request.getSession().getAttribute("org.infoglue.cms.security.user"); 90 if(infoGluePrincipal == null) 91 { 92 try 93 { 94 Map arguments = new HashMap (); 95 arguments.put("j_username", CmsPropertyHandler.getAnonymousUser()); 96 arguments.put("j_password", CmsPropertyHandler.getAnonymousPassword()); 97 98 infoGluePrincipal = (InfoGluePrincipal) ExtranetController.getController().getAuthenticatedPrincipal(arguments); 99 } 100 catch (Exception e2) 101 { 102 e2.printStackTrace(); 103 } 104 } 105 106 Integer parentContentId = new Integer (ps.getString("parentContentId")); 107 Integer contentTypeDefinitionId = new Integer (ps.getString("contentTypeDefinitionId")); 108 Integer repositoryId = new Integer (ps.getString("repositoryId")); 109 110 Integer languageId = new Integer (1); 111 if(ps.getString("languageId") != null && !ps.getString("languageId").equalsIgnoreCase("")) 112 languageId = new Integer (ps.getString("languageId")); 113 114 String name = ps.getString("name"); 115 String title = ps.getString("title"); 116 String navigationTitle = ps.getString("navigationTitle"); 117 String leadIn = ps.getString("leadIn"); 118 String fullText = ps.getString("fullText"); 119 120 System.out.println("name:" + name); 121 System.out.println("title:" + title); 122 System.out.println("navigationTitle:" + navigationTitle); 123 System.out.println("leadIn:" + leadIn); 124 System.out.println("fullText:" + fullText); 125 126 ContentVO contentVO = new ContentVO(); 127 contentVO.setName(name); 128 contentVO.setIsBranch(new Boolean (false)); 129 contentVO.setCreatorName(infoGluePrincipal.getName()); 130 131 Database db = null; 132 133 try 134 { 135 db = CastorDatabaseService.getDatabase(); 136 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 137 138 db.begin(); 139 140 Content newContent = ContentControllerProxy.getContentController().create(db, parentContentId, contentTypeDefinitionId, repositoryId, contentVO); 141 142 DOMBuilder domBuilder = new DOMBuilder(); 143 Document document = domBuilder.createDocument(); 144 145 Element rootElement = domBuilder.addElement(document, "article"); 146 domBuilder.addAttribute(rootElement, "xmlns", "x-schema:ArticleSchema.xml"); 147 Element attributesElement = domBuilder.addElement(rootElement, "attributes"); 148 149 Element titleElement = domBuilder.addElement(attributesElement, "Title"); 150 domBuilder.addCDATAElement(titleElement, title); 151 152 Element navTitleElement = domBuilder.addElement(attributesElement, "NavigationTitle"); 153 domBuilder.addCDATAElement(navTitleElement, navigationTitle); 154 155 Element leadElement = domBuilder.addElement(attributesElement, "Leadin"); 156 domBuilder.addCDATAElement(leadElement, leadIn); 157 158 Element leftColumnElement = domBuilder.addElement(attributesElement, "FullText"); 159 domBuilder.addCDATAElement(leftColumnElement, fullText); 160 161 String versionValue = document.asXML(); 162 System.out.println("versionValue:" + versionValue); 163 164 ContentVersionVO newContentVersionVO = new ContentVersionVO(); 165 newContentVersionVO.setVersionComment("Generated"); 166 newContentVersionVO.setVersionModifier(infoGluePrincipal.getName()); 167 newContentVersionVO.setVersionValue(versionValue); 168 169 Language language = LanguageController.getController().getLanguageWithId(languageId, db); 170 ContentVersion newContentVersion = ContentVersionController.getContentVersionController().create(newContent, language, newContentVersionVO, null, db); 171 172 db.commit(); 173 174 db.begin(); 175 176 List events = new ArrayList (); 177 ContentVersion publishContentVersion = ContentStateController.changeState(newContentVersion.getContentVersionId(), ContentVersionVO.PUBLISH_STATE, "Auto", true, infoGluePrincipal, newContent.getId(), events); 178 179 db.commit(); 180 } 181 catch (Exception e) 182 { 183 try 184 { 185 db.rollback(); 186 } 187 catch (TransactionNotInProgressException e1) 188 { 189 e1.printStackTrace(); 190 } 191 e.printStackTrace(); 192 throw new WorkflowException(e); 193 } 194 finally 195 { 196 try 197 { 198 db.close(); 199 } 200 catch (PersistenceException e1) 201 { 202 e1.printStackTrace(); 203 } 204 } 205 } 206 207 } 208 | Popular Tags |