1 31 32 package org.opencms.jsp; 33 34 import org.opencms.file.CmsPropertyDefinition; 35 import org.opencms.file.CmsResource; 36 import org.opencms.i18n.CmsMessages; 37 38 import java.util.Map ; 39 40 56 public class CmsJspNavElement implements Comparable { 57 58 private String m_fileName; 59 private Boolean m_hasNav; 60 private int m_navTreeLevel = Integer.MIN_VALUE; 61 private float m_position; 62 private Map m_properties; 63 private String m_resource; 64 private String m_text; 65 66 79 public CmsJspNavElement() { 80 81 } 83 84 93 public CmsJspNavElement(String resource, Map properties) { 94 95 init(resource, properties, -1); 96 } 97 98 108 public CmsJspNavElement(String resource, Map properties, int navTreeLevel) { 109 110 init(resource, properties, navTreeLevel); 111 } 112 113 116 public int compareTo(Object obj) { 117 118 if (obj == this) { 119 return 0; 120 } 121 if (obj instanceof CmsJspNavElement) { 122 float pos = ((CmsJspNavElement)obj).getNavPosition(); 123 if (m_position == pos) { 125 return 0; 126 } 127 return (m_position < pos) ? -1 : 1; 128 } 129 return 0; 130 } 131 132 135 public boolean equals(Object obj) { 136 137 if (obj == this) { 138 return true; 139 } 140 if (obj instanceof CmsJspNavElement) { 141 return ((CmsJspNavElement)obj).m_resource.equals(m_resource); 142 } 143 return false; 144 } 145 146 153 public String getDescription() { 154 155 return (String )m_properties.get(CmsPropertyDefinition.PROPERTY_DESCRIPTION); 156 } 157 158 165 public String getFileName() { 166 167 if (m_fileName == null) { 168 if (!m_resource.endsWith("/")) { 170 m_fileName = m_resource.substring(m_resource.lastIndexOf("/") + 1, m_resource.length()); 171 } else { 172 m_fileName = m_resource.substring( 173 m_resource.substring(0, m_resource.length() - 1).lastIndexOf("/") + 1, 174 m_resource.length()); 175 } 176 } 177 return m_fileName; 178 } 179 180 186 public String getInfo() { 187 188 return (String )m_properties.get(CmsPropertyDefinition.PROPERTY_NAVINFO); 189 } 190 191 197 public String getLocale() { 198 199 return (String )m_properties.get(CmsPropertyDefinition.PROPERTY_LOCALE); 200 } 201 202 208 public String getNavImage() { 209 210 return (String )m_properties.get(CmsPropertyDefinition.PROPERTY_NAVIMAGE); 211 } 212 213 222 public float getNavPosition() { 223 224 return m_position; 225 } 226 227 236 public String getNavText() { 237 238 if (m_text == null) { 239 m_text = (String )m_properties.get(CmsPropertyDefinition.PROPERTY_NAVTEXT); 241 if (m_text == null) { 242 m_text = CmsMessages.formatUnknownKey(CmsPropertyDefinition.PROPERTY_NAVTEXT); 243 } 244 } 245 return m_text; 246 } 247 248 253 public int getNavTreeLevel() { 254 255 if (m_navTreeLevel < 0) { 256 m_navTreeLevel = CmsResource.getPathLevel(m_resource); 258 } 259 return m_navTreeLevel; 260 } 261 262 267 public String getParentFolderName() { 268 269 return CmsResource.getParentFolder(m_resource); 270 } 271 272 282 public Map getProperties() { 283 284 return m_properties; 285 } 286 287 296 public String getProperty(String key) { 297 298 return (String )m_properties.get(key); 299 } 300 301 306 public String getResourceName() { 307 308 return m_resource; 309 } 310 311 318 public String getTitle() { 319 320 return (String )m_properties.get(CmsPropertyDefinition.PROPERTY_TITLE); 321 } 322 323 326 public int hashCode() { 327 328 return super.hashCode(); 329 } 330 331 339 public void init(String resource, Map properties) { 340 341 init(resource, properties, -1); 342 } 343 344 365 public void init(String resource, Map properties, int navTreeLevel) { 366 367 m_resource = resource; 368 m_properties = properties; 369 m_navTreeLevel = navTreeLevel; 370 m_position = Float.MAX_VALUE; 372 try { 373 m_position = Float.parseFloat((String )m_properties.get(CmsPropertyDefinition.PROPERTY_NAVPOS)); 374 } catch (Exception e) { 375 } 378 } 379 380 387 public boolean isFolderLink() { 388 389 return m_resource.endsWith("/"); 390 } 391 392 404 public boolean isInNavigation() { 405 406 if (m_hasNav == null) { 407 Object o1 = m_properties.get(CmsPropertyDefinition.PROPERTY_NAVTEXT); 409 Object o2 = m_properties.get(CmsPropertyDefinition.PROPERTY_NAVPOS); 410 m_hasNav = new Boolean (((o1 != null) || (o2 != null)) && (m_resource.indexOf('~') < 0)); 411 } 412 return m_hasNav.booleanValue(); 413 } 414 415 421 public void setNavPosition(float value) { 422 423 m_position = value; 424 } 425 } | Popular Tags |