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 /** Attribute name for archiving */ 040 public static final String ARCHIVED = "archived"; 041 042 private Content _entry; 043 044 /** 045 * Constructor 046 * @param content The content representing the entry 047 */ 048 public OdfReferenceTableEntry(Content content) 049 { 050 _entry = content; 051 } 052 053 /** 054 * Get the identifier 055 * @return The identifier 056 */ 057 public String getId() 058 { 059 return _entry.getId(); 060 } 061 062 /** 063 * Get the label 064 * @param lang The language 065 * @return The label 066 */ 067 public String getLabel(String lang) 068 { 069 return _entry.getTitle(new Locale(lang)); 070 } 071 072 /** 073 * Get the code 074 * @return the code 075 */ 076 public String getCode() 077 { 078 return _entry.getValue(CODE, false, StringUtils.EMPTY); 079 } 080 081 /** 082 * Get the CDM value 083 * @return the CDM value 084 */ 085 public String getCdmValue() 086 { 087 return _entry.getValue(CDM_VALUE, false, StringUtils.EMPTY); 088 } 089 090 /** 091 * Get the order 092 * @return the order 093 */ 094 public Long getOrder() 095 { 096 return _entry.getValue(ORDER, false, Long.MAX_VALUE); 097 } 098 099 /** 100 * Get the archiving state 101 * @return <code>true</code> if the entry is archived, <code>false</code> otherwise 102 */ 103 public Boolean isArchived() 104 { 105 return _entry.getValue(ARCHIVED, false, false); 106 } 107 108 /** 109 * Get the content 110 * @return the content 111 */ 112 public Content getContent() 113 { 114 return _entry; 115 } 116 117 @Override 118 public int hashCode() 119 { 120 return Objects.hash(_entry.getId()); 121 } 122 123 @Override 124 public boolean equals(Object obj) 125 { 126 if (this == obj) 127 { 128 return true; 129 } 130 if (obj == null) 131 { 132 return false; 133 } 134 if (getClass() != obj.getClass()) 135 { 136 return false; 137 } 138 OdfReferenceTableEntry other = (OdfReferenceTableEntry) obj; 139 return Objects.equals(_entry.getId(), other._entry.getId()); 140 } 141}