001/* 002 * Copyright 2013 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.cms.contenttype.indexing; 017 018import org.ametys.cms.contenttype.MetadataDefinition; 019import org.ametys.cms.contenttype.MetadataType; 020import org.ametys.runtime.i18n.I18nizableText; 021 022/** 023 * This class is an implementation of {@link IndexingField} for field linked to a remote {@link MetadataDefinition} 024 * 025 */ 026public class DefaultMetadataIndexingField implements MetadataIndexingField 027{ 028 /** The field name */ 029 protected String _name; 030 /** The metadata path */ 031 protected String _metadataPath; 032 /** The metadata definition */ 033 protected MetadataDefinition _definition; 034 035 /** 036 * Constructor for indexing field 037 * @param name The field's name 038 * @param definition The metadata definition 039 * @param metadataPath The metadata path 040 */ 041 public DefaultMetadataIndexingField(String name, MetadataDefinition definition, String metadataPath) 042 { 043 _name = name; 044 _definition = definition; 045 _metadataPath = metadataPath; 046 } 047 048 @Override 049 public String getMetadataPath() 050 { 051 return _metadataPath; 052 } 053 054 /** 055 * Set the path to metadata 056 * @param metadataPath the path to metadata 057 */ 058 public void setMetadataPath (String metadataPath) 059 { 060 _metadataPath = metadataPath; 061 } 062 063 @Override 064 public String getName() 065 { 066 return _name; 067 } 068 069 /** 070 * Set the metadata name. 071 * @param name the metadata name. 072 */ 073 public void setName(String name) 074 { 075 _name = name; 076 } 077 078 @Override 079 public I18nizableText getLabel() 080 { 081 return _definition.getLabel(); 082 } 083 084 @Override 085 public I18nizableText getDescription() 086 { 087 return _definition.getDescription(); 088 } 089 090 @Override 091 public MetadataType getType() 092 { 093 return _definition.getType(); 094 } 095 096 @Override 097 public MetadataDefinition getMetadataDefinition() 098 { 099 return _definition; 100 } 101 102 /** 103 * Set the metadata definition. 104 * @param definition the metadata definition. 105 */ 106 public void setMetadataDefinition(MetadataDefinition definition) 107 { 108 _definition = definition; 109 } 110 111 @Override 112 public String toString() 113 { 114 StringBuilder field = new StringBuilder(); 115 116 field.append(_name); 117 field.append(" ("); 118 field.append(getType()); 119 field.append(")"); 120 121 return field.toString(); 122 } 123 124}