1 18 package org.jahia.utils; 19 20 21 import java.util.HashMap ; 22 23 import org.jahia.data.containers.JahiaContainer; 24 import org.jahia.data.containers.JahiaContainerList; 25 import org.jahia.data.fields.JahiaField; 26 import org.jahia.data.fields.LoadFlags; 27 import org.jahia.exceptions.JahiaException; 28 import org.jahia.params.ParamBean; 29 import org.jahia.registries.ServicesRegistry; 30 import org.jahia.services.pages.JahiaPage; 31 import org.jahia.services.pages.JahiaPageDefinition; 32 import org.jahia.services.version.EntryLoadRequest; 33 34 35 41 42 43 public class JahiaObjectTool 44 { 45 46 private static JahiaObjectTool theObject = null; 47 48 private static final String MSG_INTERNAL_ERROR = new String ("Object Tool internal error"); 49 50 public static final int FIELD_TYPE = 1; 51 public static final int CONTAINER_TYPE = 2; 52 public static final int CONTAINERLIST_TYPE = 3; 53 public static final int PAGE_TYPE = 4; 54 public static final int ACL_TYPE = 5; 55 public static final int APPLICATION_TYPE = 6; 56 public static final int SERVER_TYPE = 7; 57 public static final int TEMPLATE_TYPE = 8; 58 59 63 public static synchronized JahiaObjectTool getInstance() 64 { 65 if (theObject == null) { 66 theObject = new JahiaObjectTool(); 67 } 68 return theObject; 69 } 71 72 73 81 public String getObjectName( int objectType, int objectID, ParamBean jParams ) 82 throws JahiaException 83 { 84 ServicesRegistry sReg = ServicesRegistry.getInstance(); 85 EntryLoadRequest loadRequest = new EntryLoadRequest(EntryLoadRequest.STAGING_WORKFLOW_STATE, 0, jParams.getEntryLoadRequest().getLocales()); 86 87 switch(objectType) { 88 case CONTAINERLIST_TYPE: 89 return sReg.getJahiaContainersService().loadContainerListInfo(objectID).getDefinition().getName(); 90 case CONTAINER_TYPE: 91 JahiaContainer jahiaContainer = sReg.getJahiaContainersService().loadContainerInfo(objectID,jParams.getEntryLoadRequest()); 92 if (jahiaContainer == null) { 93 jahiaContainer = sReg.getJahiaContainersService().loadContainerInfo(objectID,EntryLoadRequest.STAGED); 94 } 95 if (jahiaContainer != null) { 96 return jahiaContainer.getDefinition().getName(); 97 } else { 98 return "container [" + objectID + "]"; 99 } 100 case PAGE_TYPE: 101 JahiaPage page = sReg.getJahiaPageService().lookupPage(objectID, 102 loadRequest, jParams.getOperationMode(), jParams.getUser(), 103 true); 104 if (page != null) 105 return page.getTitle(); 106 else 107 return "page [" + objectID + "]"; 108 case FIELD_TYPE: 109 JahiaField f =sReg.getJahiaFieldService().loadField(objectID,LoadFlags.NOTHING, jParams, jParams.getEntryLoadRequest()); 110 if ( f!= null ){ 111 return f.getDefinition().getName(); 112 } else { 113 return ("field [" + objectID + "]"); 114 } 115 case APPLICATION_TYPE: 116 return sReg.getJahiaApplicationsManagerService().getApplication(objectID).getName(); 117 case TEMPLATE_TYPE: 118 return sReg.getJahiaPageTemplateService().lookupPageTemplate(objectID).getName(); 119 case SERVER_TYPE: 120 return "Jahia Server"; 121 default: 122 throw new JahiaException (MSG_INTERNAL_ERROR, 123 "Incompatible Object Type passed to JahiaObjectTool.getObjectName(objectType, objectID)", 124 JahiaException.SERVICE_ERROR, 125 JahiaException.CRITICAL_SEVERITY); 126 } 127 } 129 130 131 138 public String getObjectName( int objectType, HashMap engineMap ) 139 throws JahiaException 140 { 141 switch(objectType) { 142 case CONTAINERLIST_TYPE: return ((JahiaContainerList) engineMap.get( "theContainerList" )).getDefinition().getName(); 143 case CONTAINER_TYPE: return ((JahiaContainer) engineMap.get( "theContainer" )).getDefinition().getName(); 144 case PAGE_TYPE: return ((JahiaPage) engineMap.get( "thePage" )).getTitle(); 145 case FIELD_TYPE: return ((JahiaField) engineMap.get( "theField" )).getDefinition().getName(); 146 case TEMPLATE_TYPE: return ((JahiaPageDefinition) engineMap.get( "theTemplate" )).getName(); 147 148 149 default: throw new JahiaException (MSG_INTERNAL_ERROR, 150 "Incompatible Object Type passed to JahiaObjectTool.getObjectName(objectType, engineMap)", 151 JahiaException.SERVICE_ERROR, 152 JahiaException.CRITICAL_SEVERITY); 153 } 154 } 156 157 164 public String getObjectTypeName( int objectType ) 165 throws JahiaException 166 { 167 switch(objectType) { 168 169 case CONTAINERLIST_TYPE: return "containerlist"; 170 case CONTAINER_TYPE: return "container"; 171 case PAGE_TYPE: return "page"; 172 case FIELD_TYPE: return "field"; 173 case TEMPLATE_TYPE: return "template"; 174 175 default: throw new JahiaException (MSG_INTERNAL_ERROR, 176 "Incompatible Object Type passed to JahiaObjectTool.getObjectName(objectType)", 177 JahiaException.SERVICE_ERROR, 178 JahiaException.CRITICAL_SEVERITY); 179 } 180 } 181 182 183 190 public int getObjectID( int objectType, HashMap engineMap ) 191 throws JahiaException 192 { 193 switch(objectType) { 194 195 case CONTAINERLIST_TYPE: return ((JahiaContainerList) engineMap.get( "theContainerList" )).getID(); 196 case CONTAINER_TYPE: return ((JahiaContainer) engineMap.get( "theContainer" )).getID(); 197 case PAGE_TYPE: return ((JahiaPage) engineMap.get( "thePage" )).getID(); 198 case FIELD_TYPE: return ((JahiaField) engineMap.get( "theField" )).getID(); 199 case TEMPLATE_TYPE: return ((JahiaPageDefinition) engineMap.get( "theTemplate" )).getID(); 200 201 default: throw new JahiaException (MSG_INTERNAL_ERROR, 202 "Incompatible Object Type passed to JahiaObjectTool", 203 JahiaException.SERVICE_ERROR, 204 JahiaException.CRITICAL_SEVERITY); 205 } 206 } 207 208 209 210 } | Popular Tags |