View Javadoc
1   package fr.paris.lutece.pligins.documentimport.service;
2   
3   import java.sql.Timestamp;
4   import java.util.ArrayList;
5   import java.util.Collection;
6   import java.util.Date;
7   import java.util.HashMap;
8   import java.util.List;
9   import java.util.Locale;
10  
11  import javax.servlet.http.HttpServletRequest;
12  
13  import org.apache.commons.lang.StringUtils;
14  
15  import fr.paris.lutece.plugins.document.business.Document;
16  import fr.paris.lutece.plugins.document.business.DocumentHome;
17  import fr.paris.lutece.plugins.document.business.DocumentType;
18  import fr.paris.lutece.plugins.document.business.DocumentTypeHome;
19  import fr.paris.lutece.plugins.document.business.attributes.DocumentAttribute;
20  import fr.paris.lutece.plugins.document.business.category.Category;
21  import fr.paris.lutece.plugins.document.business.category.CategoryHome;
22  import fr.paris.lutece.plugins.document.business.spaces.DocumentSpace;
23  import fr.paris.lutece.plugins.document.business.spaces.DocumentSpaceHome;
24  import fr.paris.lutece.plugins.document.service.AttributeManager;
25  import fr.paris.lutece.plugins.document.service.AttributeService;
26  import fr.paris.lutece.plugins.document.service.DocumentException;
27  import fr.paris.lutece.plugins.document.service.DocumentService;
28  import fr.paris.lutece.plugins.document.service.metadata.MetadataHandler;
29  import fr.paris.lutece.plugins.document.service.spaces.SpaceResourceIdService;
30  import fr.paris.lutece.plugins.document.utils.IntegerUtils;
31  import fr.paris.lutece.plugins.documentimport.util.DocumentImport;
32  import fr.paris.lutece.plugins.documentimport.util.DocumentimporError;
33  import fr.paris.lutece.portal.business.user.AdminUser;
34  import fr.paris.lutece.portal.service.i18n.I18nService;
35  import fr.paris.lutece.portal.service.rbac.RBACService;
36  import fr.paris.lutece.util.ReferenceItem;
37  import fr.paris.lutece.util.ReferenceList;
38  import fr.paris.lutece.util.date.DateUtil;
39  import fr.paris.lutece.util.string.StringUtil;
40  
41  public class DocumentimportService {
42  
43  
44  	// Variables declarations
45  	
46  	 private static final String PROPERTY_WARNING_LINE = "documentimport.import_document.warning.line";
47  	 private static final String PROPERTY_ERROR_LINE = "documentimport.import_document.error.line";
48  	 
49  	 private static final String MESSAGE_ERROR_CSV_MANDATORY_FIELD= "documentimport.message.mandatory.required";
50  	 private static final String MESSAGE_INVALID_DATEBEGIN = "documentimport.invalid.date.begin";
51  	 private static final String MESSAGE_INVALID_DATEEND = "documentimport.invalid.date.end";
52  	 private static final String MESSAGE_INVALID_DATE_BEFORE_70 = "documentimport.invalid.date.before";
53  	 private static final String MESSAGE_ERROR_DATEEND_BEFORE_DATEBEGIN= "documentimport.invalid.date.end.befor.begin";
54  	 private static final String MESSAGE_WARNING_CSV_ILLEGAL_CHARACTER= "documentimport.warning.illegal.char";
55  	 
56  	 
57  	 private static final String ERROR= "error";
58  	 private static DocumentimportService _singleton = new DocumentimportService();
59  	
60  	    
61      /** Creates a new instance of DocumentimportService */
62      private DocumentimportService(  )
63      {
64        //  _managerEventListeners = SpringContextService.getBean( "document.documentEventListernersManager" );
65      }
66  
67  	/**
68       * Return the data of a document object
69       * @param mRequest The MultipartHttpServletRequest
70       * @param document The document object
71       * @param locale The locale
72       * @return data of document object
73       */
74      public  String  getDocumentData(HttpServletRequest mRequest, Document document,  HashMap<String,String> valueAttribute, DocumentimporError _docError,Locale locale, AdminUser user )
75      {
76          String strDocumentTitle = valueAttribute.get(DocumentImport.PARAMETER_TITLE);
77          String strDocumentSummary = valueAttribute.get(DocumentImport.PARAMETER_SUMMARY);
78          String strDocumentComment = valueAttribute.get(DocumentImport.PARAMAETER_COMMENT);
79          String strDateValidityBegin = valueAttribute.get(DocumentImport.PARAMAETER_DATE_VALID_BEGIN);
80          String strDateValidityEnd = valueAttribute.get(DocumentImport.PARAMETER_DATE_VALID_END);
81          String strMailingListId = valueAttribute.get(DocumentImport.PARAMETER_DATE_MAILING_LIST);
82          int nMailingListId = IntegerUtils.convert( strMailingListId, 0 );
83          String strPageTemplateDocumentId = valueAttribute.get(DocumentImport.PARAMETER_TEMPLATE_DOCUMENT_ID);
84          int nPageTemplateDocumentId = IntegerUtils.convert( strPageTemplateDocumentId, 0 );
85          //String[] arrayCategory = mRequest.getParameterValues( PARAMETER_CATEGORY );
86          String[] arrayCategory = null;
87  
88          // Check for mandatory value
89          if ( StringUtils.isBlank( strDocumentSummary ) )
90          {
91           _docError.getWarning(  ).append( I18nService.getLocalizedString( PROPERTY_WARNING_LINE, locale ) );
92         	 _docError.getWarning(  ).append( _docError.getCountLine(  ) );
93         	 _docError.getWarning(  ).append( " > " );
94         	 _docError.getWarning(  )
95                           .append( DocumentImport.PARAMETER_TITLE +" :"+  I18nService.getLocalizedString(MESSAGE_ERROR_CSV_MANDATORY_FIELD  ,
96                         		  locale) );
97         	 _docError.getWarning(  ).append( "<br/>" );
98         	 _docError.setCountWarning( _docError.getCountWarning() + 1 );
99         	 
100        //	 return "error";
101         }
102         if (StringUtils.isBlank( strDocumentSummary ) )
103         {
104          _docError.getWarning(  ).append( I18nService.getLocalizedString( PROPERTY_WARNING_LINE, locale ) );
105        	 _docError.getWarning(  ).append( _docError.getCountLine(  ) );
106        	 _docError.getWarning(  ).append( " > " );
107        	 _docError.getWarning(  )
108                          .append( DocumentImport.PARAMETER_SUMMARY  + " :" +  I18nService.getLocalizedString(MESSAGE_ERROR_CSV_MANDATORY_FIELD  ,
109                        		  locale  ));
110        	 _docError.getWarning(  ).append( "<br/>" );
111        	 _docError.setCountWarning( _docError.getCountWarning() + 1 );
112        	 
113        //	 return "error";
114         }
115 
116         // Check for illegal character character
117         if ( StringUtil.containsHtmlSpecialCharacters( strDocumentTitle ) )
118         {
119         	 _docError.getWarning(  ).append( I18nService.getLocalizedString( PROPERTY_WARNING_LINE, locale ) );
120           	 _docError.getWarning(  ).append( _docError.getCountLine(  ) );
121           	 _docError.getWarning(  ).append( " > " );
122           	 _docError.getWarning(  )
123                             .append(  DocumentImport.PARAMETER_TITLE + " :" + I18nService.getLocalizedString(MESSAGE_WARNING_CSV_ILLEGAL_CHARACTER  ,
124                           		  locale) );
125           	 _docError.getWarning(  ).append( "<br/>" );
126           	 _docError.setCountWarning( _docError.getCountWarning() + 1 );
127           	 
128         }
129      // Check for illegal character character
130         if ( StringUtil.containsHtmlSpecialCharacters( strDocumentSummary ) )
131         {
132         	 _docError.getWarning(  ).append( I18nService.getLocalizedString( PROPERTY_WARNING_LINE, locale ) );
133           	 _docError.getWarning(  ).append( _docError.getCountLine(  ) );
134           	 _docError.getWarning(  ).append( " > " );
135           	 _docError.getWarning(  )
136                             .append( DocumentImport.PARAMETER_SUMMARY + " :" + I18nService.getLocalizedString( MESSAGE_WARNING_CSV_ILLEGAL_CHARACTER  ,
137                           		  locale)  );
138           	 _docError.getWarning(  ).append( "<br/>" );
139           	_docError.setCountWarning( _docError.getCountWarning() + 1 );
140         }
141 
142         DocumentType documentType = DocumentTypeHome.findByPrimaryKey( document.getCodeDocumentType(  ) );
143         List<DocumentAttribute> listAttributes = documentType.getAttributes(  );
144 
145         for ( DocumentAttribute attribute : listAttributes )
146         {
147             String strAdminMessage = setAttribute( attribute, document, valueAttribute,_docError,locale );
148 
149             if ( strAdminMessage != null )
150             {
151                 return ERROR;
152             }
153         }
154 
155         Timestamp dateValidityBegin = null;
156         Timestamp dateValidityEnd = null;
157 
158         if ( ( strDateValidityBegin != null ) && !strDateValidityBegin.equals( "" ) )
159         {
160             Date dateBegin = DateUtil.formatDateLongYear( strDateValidityBegin, locale );
161 
162             if ( ( dateBegin == null ) )
163             {
164             	 _docError.getWarning(  ).append( I18nService.getLocalizedString( PROPERTY_WARNING_LINE, locale ) );
165               	 _docError.getWarning(  ).append( _docError.getCountLine(  ) );
166               	 _docError.getWarning(  ).append( " > " );
167               	 _docError.getWarning(  )
168                                 .append( DocumentImport.PARAMAETER_DATE_VALID_BEGIN + " :" + I18nService.getLocalizedString( MESSAGE_INVALID_DATEBEGIN  ,
169                               		  locale) );
170               	_docError.getWarning(  ).append( "<br/>" );
171               	_docError.setCountWarning( _docError.getCountWarning() + 1 );
172                
173             }
174 
175             dateValidityBegin = new Timestamp( dateBegin.getTime(  ) );
176 
177             if ( dateValidityBegin.before( new Timestamp( 0 ) ) )
178             {
179             	 _docError.getWarning(  ).append( I18nService.getLocalizedString( PROPERTY_WARNING_LINE, locale ) );
180               	 _docError.getWarning(  ).append( _docError.getCountLine(  ) );
181               	 _docError.getWarning(  ).append( " > " );
182               	 _docError.getWarning(  )
183                                 .append( DocumentImport.PARAMAETER_DATE_VALID_BEGIN + " :" +  I18nService.getLocalizedString( MESSAGE_INVALID_DATE_BEFORE_70  ,
184                               		  locale) );
185               	_docError.getWarning(  ).append( "<br/>" );
186               	_docError.setCountWarning( _docError.getCountWarning() + 1 );
187               	
188             }
189         }
190 
191         if ( ( strDateValidityEnd != null ) && !strDateValidityEnd.equals( "" ) )
192         {
193             Date dateEnd = DateUtil.formatDateLongYear( strDateValidityEnd, locale );
194 
195             if ( ( dateEnd == null ) )
196             {
197             	 _docError.getWarning(  ).append( I18nService.getLocalizedString( PROPERTY_WARNING_LINE, locale ) );
198               	 _docError.getWarning(  ).append( _docError.getCountLine(  ) );
199               	 _docError.getWarning(  ).append( " > " );
200               	 _docError.getWarning(  )
201                                 .append( DocumentImport.PARAMETER_DATE_VALID_END+ " :" + I18nService.getLocalizedString( MESSAGE_INVALID_DATEEND  ,
202                               		  locale) );
203               	_docError.getWarning(  ).append( "<br/>" );
204               	_docError.setCountWarning( _docError.getCountWarning() + 1 );
205               	
206             }
207 
208             dateValidityEnd = new Timestamp( dateEnd.getTime(  ) );
209 
210             if ( dateValidityEnd.before( new Timestamp( 0 ) ) )
211             {
212             	 _docError.getWarning(  ).append( I18nService.getLocalizedString( PROPERTY_WARNING_LINE, locale ) );
213               	 _docError.getWarning(  ).append( _docError.getCountLine(  ) );
214               	 _docError.getWarning(  ).append( " > " );
215               	 _docError.getWarning(  )
216                                 .append( DocumentImport.PARAMETER_DATE_VALID_END + " :" + I18nService.getLocalizedString( MESSAGE_INVALID_DATE_BEFORE_70  ,
217                               		  locale)   );
218               	_docError.getWarning(  ).append( "<br/>" );
219               	_docError.setCountWarning( _docError.getCountWarning() + 1 );
220               
221             }
222         }
223 
224         //validate period (dateEnd > dateBegin )
225         if ( ( dateValidityBegin != null ) && ( dateValidityEnd != null ) )
226         {
227             if ( dateValidityEnd.before( dateValidityBegin ) )
228             {
229             	 _docError.getWarning(  ).append( I18nService.getLocalizedString( PROPERTY_WARNING_LINE, locale ) );
230               	 _docError.getWarning(  ).append( _docError.getCountLine(  ) );
231               	 _docError.getWarning(  ).append( " > " );
232               	 _docError.getWarning(  )
233                                 .append( DocumentImport.PARAMETER_DATE_VALID_END + ", "+  DocumentImport.PARAMAETER_DATE_VALID_BEGIN + " :" +  I18nService.getLocalizedString(
234                                 		MESSAGE_ERROR_DATEEND_BEFORE_DATEBEGIN  ,
235                               		  locale) );
236               	_docError.getWarning(  ).append( "<br/>" );
237               	_docError.setCountWarning( _docError.getCountWarning() + 1 );
238             	
239             }
240         }
241 
242         document.setTitle( strDocumentTitle );
243         document.setSummary( strDocumentSummary );
244         document.setComment( strDocumentComment );
245         document.setDateValidityBegin( dateValidityBegin );
246         document.setDateValidityEnd( dateValidityEnd );
247         document.setMailingListId( nMailingListId );
248         document.setPageTemplateDocumentId( nPageTemplateDocumentId );
249 
250         MetadataHandler hMetadata = documentType.metadataHandler(  );
251 
252         if ( hMetadata != null )
253         {
254             document.setXmlMetadata( hMetadata.getXmlMetadata( mRequest.getParameterMap(  ) ) );
255         }
256 
257         document.setAttributes( listAttributes );
258 
259         //Categories
260         List<Category> listCategories = new ArrayList<Category>(  );
261 
262         if ( arrayCategory != null )
263         {
264             for ( String strIdCategory : arrayCategory )
265             {
266                 listCategories.add( CategoryHome.find( IntegerUtils.convert( strIdCategory ) ) );
267             }
268         }
269 
270         document.setCategories( listCategories );
271 
272         try {
273 			this.createDocument(document, user);
274 			
275 		} catch (DocumentException e) {
276 			// TODO Auto-generated catch block
277 			e.printStackTrace();
278 		}
279         
280         return null; // No error
281     }
282     
283     /**
284      * Update the specify attribute with the mRequest parameters
285      *
286      * @param attribute The {@link DocumentAttribute} to update
287      * @param document The {@link Document}
288      * @param mRequest The multipart http request
289      * @param locale The locale
290      * @return an admin message if error or null else
291      */
292     private  String setAttribute( DocumentAttribute attribute, Document document, HashMap<String,String> valueAttribute , DocumentimporError _docError,
293             Locale locale )
294         {
295             String strParameterStringValue = StringUtils.isEmpty(valueAttribute.get(attribute.getName()))  ? "" : valueAttribute.get(attribute.getName());
296            // FileItem fileParameterBinaryValue = mRequest.getFile( attribute.getCode(  ) );
297            // String strIsUpdatable = mRequest.getParameter( PARAMETER_ATTRIBUTE_UPDATE + attribute.getCode(  ) );
298            // String strToResize = mRequest.getParameter( attribute.getCode(  ) + PARAMETER_CROPPABLE );
299            // boolean bIsUpdatable = ( ( strIsUpdatable == null ) || strIsUpdatable.equals( "" ) ) ? false : true;
300            // boolean bToResize = ( ( strToResize == null ) || strToResize.equals( "" ) ) ? false : true;
301 
302             if ( !StringUtils.isEmpty(strParameterStringValue) ) // If the field is a string
303             {
304                 // Check for mandatory value
305                 if ( attribute.isRequired(  ) && strParameterStringValue.trim(  ).equals( "" ) )
306                 {
307                 	
308                 	 _docError.getWarning(  ).append( I18nService.getLocalizedString( PROPERTY_WARNING_LINE, locale ) );
309                 	 _docError.getWarning(  ).append( _docError.getCountLine(  ) );
310                 	 _docError.getWarning(  ).append( " > " );
311                 	 _docError.getWarning(  )
312                                   .append( attribute.getName(  )  + " :" +  I18nService.getLocalizedString( MESSAGE_ERROR_CSV_MANDATORY_FIELD  ,
313                                 		  locale));
314                 	 _docError.getWarning(  ).append( "<br/>" );
315                 	 _docError.setCountWarning(_docError.getCountWarning( ) + 1 );
316                     return null;
317                 }
318 
319                 // Check for specific attribute validation
320                 AttributeManager manager = AttributeService.getInstance(  ).getManager( attribute.getCodeAttributeType(  ) );
321                 if ( attribute.getCodeAttributeType().equalsIgnoreCase("numerictext") && strParameterStringValue.trim(  ).equals( "" ) )
322                 {
323                 	strParameterStringValue= "0";
324                 }
325                 String strValidationErrorMessage = manager.validateValue( attribute.getId(  ), strParameterStringValue,
326                         locale );
327 
328                 if ( strValidationErrorMessage != null )
329                 {
330     	                
331     	             _docError.getError().append( I18nService.getLocalizedString( PROPERTY_ERROR_LINE, locale ) );
332     	           	 _docError.getError(  ).append( _docError.getCountLine(  ) );
333     	           	 _docError.getError(  ).append( " > " );
334     	           	 _docError.getError(  ).append( attribute.getName(  )+": " + strValidationErrorMessage );
335     	           	 _docError.getError(  ).append( "<br/>" );
336     	           	 
337     	           	_docError.setCountLineFailure( _docError.getCountLineFailure(  ) + 1 );
338     	               
339     	           	 return ERROR;
340     	            	
341                 }
342             }
343              	 attribute.setTextValue( strParameterStringValue );
344              	 return null;
345          /*    else if ( fileParameterBinaryValue != null ) // If the field is a file
346             {
347                 attribute.setBinary( true );
348 
349                 String strContentType = fileParameterBinaryValue.getContentType(  );
350                 byte[] bytes = fileParameterBinaryValue.get(  );
351                 String strFileName = fileParameterBinaryValue.getName(  );
352                 String strExtension = FilenameUtils.getExtension( strFileName );
353 
354                 AttributeManager manager = AttributeService.getInstance(  ).getManager( attribute.getCodeAttributeType(  ) );
355 
356                 if ( !bIsUpdatable )
357                 {
358                     // there is no new value then take the old file value
359                     DocumentAttribute oldAttribute = document.getAttribute( attribute.getCode(  ) );
360 
361                     if ( ( oldAttribute != null ) && ( oldAttribute.getBinaryValue(  ) != null ) &&
362                             ( oldAttribute.getBinaryValue(  ).length > 0 ) )
363                     {
364                         bytes = oldAttribute.getBinaryValue(  );
365                         strContentType = oldAttribute.getValueContentType(  );
366                         strFileName = oldAttribute.getTextValue(  );
367                         strExtension = FilenameUtils.getExtension( strFileName );
368                     }
369                 }
370 
371                 List<AttributeTypeParameter> parameters = manager.getExtraParametersValues( locale, attribute.getId(  ) );
372 
373                 String extensionList = StringUtils.EMPTY;
374 
375                 if ( CollectionUtils.isNotEmpty( parameters ) &&
376                         CollectionUtils.isNotEmpty( parameters.get( 0 ).getValueList(  ) ) )
377                 {
378                     extensionList = parameters.get( 0 ).getValueList(  ).get( 0 );
379                 }
380 
381                 // Check for mandatory value
382                 if ( attribute.isRequired(  ) && ( ( bytes == null ) || ( bytes.length == 0 ) ) )
383                 {
384                     return AdminMessageService.getMessageUrl( mRequest, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
385                 }
386                 else if ( StringUtils.isNotBlank( extensionList ) && !extensionList.contains( strExtension ) )
387                 {
388                     Object[] params = new Object[2];
389                     params[0] = attribute.getName(  );
390                     params[1] = extensionList;
391 
392                     return AdminMessageService.getMessageUrl( mRequest, MESSAGE_EXTENSION_ERROR, params,
393                         AdminMessage.TYPE_STOP );
394                 }
395 
396                 // Check for specific attribute validation
397                 String strValidationErrorMessage = manager.validateValue( attribute.getId(  ), strFileName, locale );
398 
399                 if ( strValidationErrorMessage != null )
400                 {
401                     String[] listArguments = { attribute.getName(  ), strValidationErrorMessage };
402 
403                     return AdminMessageService.getMessageUrl( mRequest, MESSAGE_ATTRIBUTE_VALIDATION_ERROR, listArguments,
404                         AdminMessage.TYPE_STOP );
405                 }
406 
407            /*     if ( bToResize && !ArrayUtils.isEmpty( bytes ) )
408                 {
409                     // Resize image
410                     String strWidth = mRequest.getParameter( attribute.getCode(  ) + PARAMETER_WIDTH );
411 
412                     if ( StringUtils.isBlank( strWidth ) || !StringUtils.isNumeric( strWidth ) )
413                     {
414                         String[] listArguments = 
415                             {
416                                 attribute.getName(  ),
417                                 I18nService.getLocalizedString( MESSAGE_ATTRIBUTE_WIDTH_ERROR, mRequest.getLocale(  ) )
418                             };
419 
420                         return AdminMessageService.getMessageUrl( mRequest, MESSAGE_ATTRIBUTE_VALIDATION_ERROR,
421                             listArguments, AdminMessage.TYPE_STOP );
422                     }
423 
424                     try
425                     {
426                         bytes = ImageUtils.resizeImage( bytes, Integer.valueOf( strWidth ) );
427                     }
428                     catch ( IOException e )
429                     {
430                         return AdminMessageService.getMessageUrl( mRequest, MESSAGE_ATTRIBUTE_RESIZE_ERROR,
431                             AdminMessage.TYPE_STOP );
432                     }
433                 }
434 
435            //     attribute.setBinaryValue( bytes );
436                 attribute.setValueContentType( strContentType );
437                 attribute.setTextValue( strFileName );
438             }*/
439 
440           //  return null;
441         }
442 
443     
444     /**
445      * Create a new document
446      *
447      * @param document The document
448      * @param user The user doing the action
449      * @throws DocumentException raise when error occurs in event or rule
450      */
451     public void createDocument( Document document, AdminUser user)
452         throws DocumentException
453     {
454     	DocumentService.getInstance().createDocument(document, user);
455        /* document.setId( DocumentHome.newPrimaryKey(  ) );
456         document.setDateCreation( new Timestamp( new java.util.Date(  ).getTime(  ) ) );
457         document.setDateModification( new Timestamp( new java.util.Date(  ).getTime(  ) ) );
458         
459         DocumentHome.create( document );*/
460     }
461     
462     /**
463      * Get the unique instance of the service
464      *
465      * @return The unique instance
466      */
467     public static DocumentimportService getInstance(  )
468     {
469         return _singleton;
470     }
471     
472     /**
473      * get user space 
474      * @param user
475      * @return documents space
476      */
477     public Collection<DocumentSpace> getUserSpaces( AdminUser user )
478     {
479         Collection<DocumentSpace> listSpaces = DocumentSpaceHome.findAll(  );
480         listSpaces = RBACService.getAuthorizedCollection( listSpaces, SpaceResourceIdService.PERMISSION_VIEW, user );
481 
482         return listSpaces;
483     }
484     
485     
486     /**
487      * get identifiant of the space
488      * @param nameSpaceParent
489      * @param nameSpaceFils
490      * @return ID
491      */
492     public int getIdSpace(String nameSpaceParent, String nameSpaceFils){
493     	
494     	
495     	if(nameSpaceParent != null || nameSpaceFils!= null ){
496     		String ident= getIdSpaceParent(nameSpaceParent);
497     		if(ident == null){
498     			return -1;
499     		}
500 	    	List<DocumentSpace> docSpace= DocumentSpaceHome.findChilds(Integer.parseInt(ident));
501 	    	
502 	    	for(DocumentSpace item: docSpace ){
503 	    		
504 	    		if(item.getName().equals(nameSpaceFils)) return item.getId();
505 	    	}
506     	}
507     	return -1;
508     }
509     
510     /**
511      * get parent identifiant of the space
512      * @param nameSpace
513      * @return ID
514      */
515     private String getIdSpaceParent(String nameSpace){
516     	
517     	ReferenceList listSpace= DocumentSpaceHome.getDocumentSpaceList(  );
518     	
519     	for(ReferenceItem item: listSpace ){
520     		
521     		if(item.getName().equals(nameSpace)) return item.getCode();
522     	}
523     	
524     	return null;
525     }
526 }