1 17 package org.alfresco.web.ui.repo.component.template; 18 19 import java.util.Date ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 import org.alfresco.repo.template.DateCompareMethod; 24 import org.alfresco.repo.template.HasAspectMethod; 25 import org.alfresco.repo.template.I18NMessageMethod; 26 import org.alfresco.service.ServiceRegistry; 27 import org.alfresco.service.cmr.repository.NodeRef; 28 import org.alfresco.service.cmr.repository.TemplateImageResolver; 29 import org.alfresco.service.cmr.repository.TemplateNode; 30 import org.alfresco.web.app.Application; 31 import org.alfresco.web.bean.repository.Repository; 32 import org.alfresco.web.bean.repository.User; 33 import org.alfresco.web.ui.common.Utils; 34 35 42 public class DefaultModelHelper 43 { 44 47 private DefaultModelHelper() 48 { 49 } 50 51 61 public static Map buildDefaultModel(ServiceRegistry services, User user) 62 { 63 if (services == null) 64 { 65 throw new IllegalArgumentException ("ServiceRegistry is mandatory."); 66 } 67 if (user == null) 68 { 69 throw new IllegalArgumentException ("Current User is mandatory."); 70 } 71 72 Map root = new HashMap (16, 1.0f); 74 75 NodeRef companyRootRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId()); 77 TemplateNode companyRootNode = new TemplateNode(companyRootRef, services, imageResolver); 78 root.put("companyhome", companyRootNode); 79 80 NodeRef userRootRef = new NodeRef(Repository.getStoreRef(), user.getHomeSpaceId()); 82 TemplateNode userRootNode = new TemplateNode(userRootRef, services, imageResolver); 83 root.put("userhome", userRootNode); 84 85 root.put("person", new TemplateNode(user.getPerson(), services, imageResolver)); 87 88 root.put("date", new Date ()); 90 91 root.put("hasAspect", new HasAspectMethod()); 93 root.put("message", new I18NMessageMethod()); 94 root.put("dateCompare", new DateCompareMethod()); 95 96 return root; 97 } 98 99 100 public static TemplateImageResolver imageResolver = new TemplateImageResolver() 101 { 102 public String resolveImagePathForName(String filename, boolean small) 103 { 104 return Utils.getFileTypeImage(filename, small); 105 } 106 }; 107 } 108 | Popular Tags |