001/* 002 * Copyright 2017 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.odf.enumeration; 017 018import java.util.Locale; 019import java.util.Objects; 020 021import org.apache.commons.lang3.StringUtils; 022 023import org.ametys.cms.repository.Content; 024 025/** 026 * This class represents a entry of ODF reference table 027 * 028 */ 029public class OdfReferenceTableEntry 030{ 031 /** Attribute name for code */ 032 public static final String CODE = "code"; 033 /** Attribute name for CDM value */ 034 public static final String CDM_VALUE = "cdmValue"; 035 /** Attribute name for code Apogee */ 036 public static final String CODE_APOGEE = "codeApogee"; 037 /** Attribute name for ordering */ 038 public static final String ORDER = "order"; 039 040 private Content _entry; 041 042 /** 043 * Constructor 044 * @param content The content representing the entry 045 */ 046 public OdfReferenceTableEntry(Content content) 047 { 048 _entry = content; 049 } 050 051 /** 052 * Get the identifier 053 * @return The identifier 054 */ 055 public String getId() 056 { 057 return _entry.getId(); 058 } 059 060 /** 061 * Get the label 062 * @param lang The language 063 * @return The label 064 */ 065 public String getLabel(String lang) 066 { 067 return _entry.getTitle(new Locale(lang)); 068 } 069 070 /** 071 * Get the code 072 * @return the code 073 */ 074 public String getCode() 075 { 076 return _entry.getValue(CODE, false, StringUtils.EMPTY); 077 } 078 079 /** 080 * Get the CDM value 081 * @return the CDM value 082 */ 083 public String getCdmValue() 084 { 085 return _entry.getValue(CDM_VALUE, false, StringUtils.EMPTY); 086 } 087 088 /** 089 * Get the order 090 * @return the order 091 */ 092 public Long getOrder() 093 { 094 return _entry.getValue(ORDER, false, Long.MAX_VALUE); 095 } 096 097 /** 098 * Get the content 099 * @return the content 100 */ 101 public Content getContent() 102 { 103 return _entry; 104 } 105 106 @Override 107 public int hashCode() 108 { 109 return Objects.hash(_entry.getId()); 110 } 111 112 @Override 113 public boolean equals(Object obj) 114 { 115 if (this == obj) 116 { 117 return true; 118 } 119 if (obj == null) 120 { 121 return false; 122 } 123 if (getClass() != obj.getClass()) 124 { 125 return false; 126 } 127 OdfReferenceTableEntry other = (OdfReferenceTableEntry) obj; 128 return Objects.equals(_entry.getId(), other._entry.getId()); 129 } 130}