View Javadoc
1   package fr.paris.lutece.plugins.crm.util;
2   
3   import fr.paris.lutece.portal.service.util.AppLogService;
4   import fr.paris.lutece.util.xml.XmlUtil;
5   
6   public class CrmUtils
7   {
8   
9       public static final int CONSTANT_ID_NULL = -1;
10  
11      private static final String REGEX_ID = "^[\\d]+$";
12  
13      /**
14       * convert a string to int
15       *
16       * @param strParameter
17       *            the string parameter to convert
18       * @return the conversion
19       */
20      public static int convertStringToInt( String strParameter )
21      {
22          int nIdParameter = -1;
23  
24          try
25          {
26              if ( ( strParameter != null ) && strParameter.matches( REGEX_ID ) )
27              {
28                  nIdParameter = Integer.parseInt( strParameter );
29              }
30          }
31          catch( NumberFormatException ne )
32          {
33              AppLogService.error( ne );
34          }
35  
36          return nIdParameter;
37      }
38  
39      /**
40       * Add a CDATA type element to XML document buffer add Empty value if strValue is null
41       *
42       * @param strXmlBuffer
43       *            The XML document buffer
44       * @param strTag
45       *            The tag name of the element to add
46       * @param strValue
47       *            The value of the element
48       */
49      public static void addElementHtml( StringBuffer strXmlBuffer, String strTag, String strValue )
50      {
51          if ( strValue != null )
52          {
53              XmlUtil.addElementHtml( strXmlBuffer, strTag, strValue );
54          }
55          else
56          {
57              XmlUtil.addEmptyElement( strXmlBuffer, strTag, null );
58          }
59      }
60  
61  }