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.crm.business.demand.category;
35  
36  import java.util.List;
37  import java.util.Locale;
38  
39  import javax.servlet.http.HttpServletRequest;
40  
41  import fr.paris.lutece.plugins.crm.business.demand.DemandType;
42  import fr.paris.lutece.plugins.crm.util.CrmUtils;
43  import fr.paris.lutece.plugins.crm.util.constants.CRMConstants;
44  import fr.paris.lutece.util.xml.XmlUtil;
45  
46  /**
47   *
48   * This is the business class for the object Category
49   *
50   */
51  public class Category
52  {
53  
54      private int _nIdCategory;
55      private String _strName;
56      private String _strDescription;
57      private String _strCode;
58  
59      /**
60       * Returns the IdCategory
61       * 
62       * @return The IdCategory
63       */
64      public int getIdCategory( )
65      {
66          return _nIdCategory;
67      }
68  
69      /**
70       * Sets the IdCategory
71       * 
72       * @param nIdCategory
73       *            The IdCategory
74       */
75      public void setIdCategory( int nIdCategory )
76      {
77          _nIdCategory = nIdCategory;
78      }
79  
80      /**
81       * Returns the Name
82       * 
83       * @return The Name
84       */
85      public String getName( )
86      {
87          return _strName;
88      }
89  
90      /**
91       * Sets the Name
92       * 
93       * @param strName
94       *            The Name
95       */
96      public void setName( String strName )
97      {
98          _strName = strName;
99      }
100 
101     /**
102      * Returns the Description
103      * 
104      * @return The Description
105      */
106     public String getDescription( )
107     {
108         return _strDescription;
109     }
110 
111     /**
112      * Sets the Description
113      * 
114      * @param strDescription
115      *            The Description
116      */
117     public void setDescription( String strDescription )
118     {
119         _strDescription = strDescription;
120     }
121     
122     /**
123      * Returns the Code
124      * @return The Code
125      */
126     public String getCode( )
127     {
128         return _strCode;
129     }
130 
131     /**
132      * Sets the Code
133      * @param strCode The Code
134      */
135     public void setCode( String strCode )
136     {
137         _strCode = strCode;
138     }
139 
140     /**
141      * Returns the xml of this Category with demand Type associated
142      *
143      * @param request
144      *            The HTTP Servlet request
145      * @param locale
146      *            the Locale
147      * @param listDemandType
148      *            the list of demande type
149      * @return the xml of this Category
150      */
151     public String getXml( HttpServletRequest request, Locale locale, List<DemandType> listDemandType )
152     {
153         StringBuffer strXml = new StringBuffer( );
154         XmlUtil.beginElement( strXml, CRMConstants.TAG_CATEGORY );
155         XmlUtil.addElement( strXml, CRMConstants.TAG_CATEGORY_ID, _nIdCategory );
156         CrmUtils.addElementHtml( strXml, CRMConstants.TAG_CATEGORY_NAME, _strName );
157         CrmUtils.addElementHtml( strXml, CRMConstants.TAG_CATEGORY_DESCRIPTION, _strDescription );
158         if ( listDemandType != null )
159         {
160             XmlUtil.beginElement( strXml, CRMConstants.TAG_DEMAND_TYPE_LIST );
161             for ( DemandType demandType : listDemandType )
162             {
163                 strXml.append( demandType.getXml( request, locale ) );
164 
165             }
166             XmlUtil.endElement( strXml, CRMConstants.TAG_DEMAND_TYPE_LIST );
167         }
168 
169         XmlUtil.endElement( strXml, CRMConstants.TAG_CATEGORY );
170         return strXml.toString( );
171     }
172 
173     /**
174      * Returns the xml of this Category
175      *
176      * @param request
177      *            The HTTP Servlet request
178      * @param locale
179      *            the Locale
180      * @return the xml of this Category
181      */
182     public String getXml( HttpServletRequest request, Locale locale )
183     {
184         return getXml( request, locale, null );
185     }
186 }