1 13 26 27 package org.jahia.data.containers; 28 29 30 import org.jahia.data.fields.JahiaFieldDefinition; 31 import org.jahia.exceptions.JahiaException; 32 import org.jahia.registries.JahiaContainerDefinitionsRegistry; 33 import org.jahia.registries.JahiaFieldDefinitionsRegistry; 34 import org.jahia.registries.ServicesRegistry; 35 import org.jahia.services.pages.JahiaPageDefinition; 36 import org.jahia.utils.JahiaConsole; 37 import java.io.Serializable ; 38 39 40 public class JahiaContainerStructure implements Serializable { 41 42 43 public static final int JAHIA_FIELD = 1; 44 public static final int JAHIA_CONTAINER = 2; 45 public static final int ALL_TYPES = -1; 46 47 48 private int subctndefid; 49 private int objectType; 50 private Object objectDef; 51 private int objectDefID; 52 private int rank; 53 54 55 59 public JahiaContainerStructure( int subctndefid, 60 int objectType, 61 int objectDefID, 62 int rank ) 63 throws JahiaException 64 { 65 this.subctndefid = subctndefid; 66 this.objectType = objectType; 67 this.objectDefID = objectDefID; 68 this.rank = rank; 69 switch (objectType) { 70 case (JAHIA_FIELD) : 71 this.objectDef = JahiaFieldDefinitionsRegistry.getInstance(). 72 getDefinition(objectDefID); 73 break; 74 case (JAHIA_CONTAINER) : 75 this.objectDef = JahiaContainerDefinitionsRegistry.getInstance(). 76 getDefinition(objectDefID); 77 break; 78 } 79 } 81 82 83 87 public JahiaContainerStructure( String objectName, 88 int subctndefid, 89 int rank, 90 int pageDefID ) 91 throws JahiaException 92 { 93 this.subctndefid = subctndefid; 94 this.rank = rank; 95 96 JahiaPageDefinition pageDef = ServicesRegistry.getInstance().getJahiaPageTemplateService().lookupPageTemplate(pageDefID); 97 98 if ( pageDef != null ){ 99 100 JahiaFieldDefinition fDef = JahiaFieldDefinitionsRegistry.getInstance( 102 ).getDefinition(pageDef.getJahiaID(),objectName); 103 if ((fDef != null) && (!fDef.getTitle(pageDefID).equals(""))) { 104 this.objectType = JahiaContainerStructure.JAHIA_FIELD; 105 this.objectDefID = fDef.getID(); 106 this.objectDef = fDef; 107 } else { 108 109 JahiaContainerDefinition cDef = JahiaContainerDefinitionsRegistry.getInstance( 110 ).getDefinition(pageDef.getJahiaID(), objectName); 111 if (cDef != null) { 112 this.objectType = JahiaContainerStructure.JAHIA_CONTAINER; 113 this.objectDefID = cDef.getID(); 114 this.objectDef = cDef; 115 } else { 116 String errorMsg = objectName + " is neither a field or a container -> not declared !"; 117 JahiaConsole.println( "JahiaContainerStructure", errorMsg + " -> BAILING OUT" ); 118 throw new JahiaException( "Cannot synchronize fields with database", 119 errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL_SEVERITY ); 120 } 121 } 122 } else { 123 String errorMsg = " cannot found objectName's " + " page definition !"; 124 JahiaConsole.println( "JahiaContainerStructure", errorMsg + " -> BAILING OUT" ); 125 throw new JahiaException( "Cannot synchronize fields with database", 126 errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL_SEVERITY ); 127 } 128 } 130 131 134 protected JahiaContainerStructure() { 135 136 } 137 138 142 public int getSubctndefid() { return subctndefid; } 143 public int getObjectType() { return objectType; } 144 public int getObjectDefID() { return objectDefID; } 145 public Object getObjectDef() { return objectDef; } 146 public int getRank() { return rank; } 147 public void setSubctndefid( int defID ) { this.subctndefid = defID; } 148 149 151 152 153 157 public boolean equals( JahiaContainerStructure theStruct ) 158 { 159 if ((theStruct.getSubctndefid() == this.getSubctndefid()) && 160 (theStruct.getObjectType() == this.getObjectType()) && 161 (theStruct.getObjectDefID() == this.getObjectDefID()) && 162 (theStruct.getRank() == this.getRank())) { 163 return true; 164 } else { 165 return false; 166 } 167 } 169 170 } | Popular Tags |