View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.library.business;
35  
36  import fr.paris.lutece.portal.service.i18n.I18nService;
37  import fr.paris.lutece.portal.service.i18n.Localizable;
38  
39  import java.util.Locale;
40  
41  
42  public class MediaAttribute implements Localizable
43  {
44      public static final int ATTRIBUTE_TYPE_TEXT_USER = 0;
45      public static final int ATTRIBUTE_TYPE_TEXT_DOCUMENT = 1;
46      public static final int ATTRIBUTE_TYPE_BINARY = 2;
47      public static final int ATTRIBUTE_TYPE_TITLE_DOCUMENT = 3;
48      public static final int ATTRIBUTE_TYPE_SUMMARY_DOCUMENT = 4;
49      public static final String PROPERTY_ATTRIBUTE_TYPE_LABEL_TEXT_USER = "library.attribute.type.label.textUser";
50      public static final String PROPERTY_ATTRIBUTE_TYPE_LABEL_TEXT_DOCUMENT = "library.attribute.type.label.textDocument";
51      public static final String PROPERTY_ATTRIBUTE_TYPE_LABEL_BINARY = "library.attribute.type.label.binary";
52      public static final String PROPERTY_ATTRIBUTE_TYPE_LABEL_TITLE_DOCUMENT = "library.attribute.type.label.titleDocument";
53      public static final String PROPERTY_ATTRIBUTE_TYPE_LABEL_SUMMARY_DOCUMENT = "library.attribute.type.label.summaryDocument";
54      private int _nAttributeId;
55      private int _nMediaId;
56      private String _strCode;
57      private String _strDescription;
58      private int _nTypeId;
59      private String _strDefaultValue;
60      private Locale _locale;
61  
62      public int getAttributeId(  )
63      {
64          return _nAttributeId;
65      }
66  
67      public void setAttributeId( int nId )
68      {
69          _nAttributeId = nId;
70      }
71  
72      public String getCode(  )
73      {
74          return _strCode;
75      }
76  
77      public void setCode( String strCode )
78      {
79          _strCode = strCode;
80      }
81  
82      public String getDescription(  )
83      {
84          return _strDescription;
85      }
86  
87      public void setDescription( String strDescription )
88      {
89          _strDescription = strDescription;
90      }
91  
92      public int getMediaId(  )
93      {
94          return _nMediaId;
95      }
96  
97      public void setMediaId( int nMediaId )
98      {
99          _nMediaId = nMediaId;
100     }
101 
102     public boolean isAssociableWithDocument(  )
103     {
104         return ( ( _nTypeId != ATTRIBUTE_TYPE_TEXT_USER ) && ( _nTypeId != ATTRIBUTE_TYPE_TITLE_DOCUMENT ) &&
105         ( _nTypeId != ATTRIBUTE_TYPE_SUMMARY_DOCUMENT ) );
106     }
107 
108     public int getTypeId(  )
109     {
110         return _nTypeId;
111     }
112 
113     public void setTypeId( int nTypeId )
114     {
115         _nTypeId = nTypeId;
116     }
117 
118     public String getTypeLabel(  )
119     {
120         String strTypeLabel;
121 
122         switch ( getTypeId(  ) )
123         {
124             case ATTRIBUTE_TYPE_BINARY:
125                 strTypeLabel = I18nService.getLocalizedString( PROPERTY_ATTRIBUTE_TYPE_LABEL_BINARY, _locale );
126 
127                 break;
128 
129             case ATTRIBUTE_TYPE_TEXT_DOCUMENT:
130                 strTypeLabel = I18nService.getLocalizedString( PROPERTY_ATTRIBUTE_TYPE_LABEL_TEXT_DOCUMENT, _locale );
131 
132                 break;
133 
134             case ATTRIBUTE_TYPE_TITLE_DOCUMENT:
135                 strTypeLabel = I18nService.getLocalizedString( PROPERTY_ATTRIBUTE_TYPE_LABEL_TITLE_DOCUMENT, _locale );
136 
137                 break;
138 
139             case ATTRIBUTE_TYPE_SUMMARY_DOCUMENT:
140                 strTypeLabel = I18nService.getLocalizedString( PROPERTY_ATTRIBUTE_TYPE_LABEL_SUMMARY_DOCUMENT, _locale );
141 
142                 break;
143 
144             default:
145                 strTypeLabel = I18nService.getLocalizedString( PROPERTY_ATTRIBUTE_TYPE_LABEL_TEXT_USER, _locale );
146 
147                 break;
148         }
149 
150         return strTypeLabel;
151     }
152 
153     public void setLocale( Locale locale )
154     {
155         _locale = locale;
156     }
157 
158     /**
159      * Getter for the default value
160      *
161      * @return the MediaAttribute default value
162      */
163     public String getDefaultValue(  )
164     {
165         return _strDefaultValue;
166     }
167 
168     /**
169      * Setter for the default value
170      *
171      * @param strDefaultValue the default value to set for the MediaAttribute
172      */
173     public void setDefaultValue( String strDefaultValue )
174     {
175         _strDefaultValue = strDefaultValue;
176     }
177 }