View Javadoc

1   /**
2    * Standard Portlet Collection Project 7 
3    * open source portlets every community needs
4    *
5    * Copyright (C) 2007  Phillip Merensky (phillip23@users.sourceforge.net)
6    *
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation, either version 3 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19   */
20  package spcp7.imagegallery.impl.alfresco.utils;
21  
22  import java.util.Map;
23  
24  import spcp7.imagegallery.abstractionlayer.enums.DefaultProperties;
25  import spcp7.imagegallery.abstractionlayer.exception.PropertyValidationException;
26  import spcp7.imagegallery.abstractionlayer.face.persistence.PropertyModelFace;
27  import spcp7.imagegallery.impl.alfresco.AlfrescoContentRetrievalImpl;
28  
29  /**
30   * This class provides Alfresco specific validation functions.
31   * 
32   * @author Phillip Merensky
33   * 
34   */
35  public class AlfrescoValidation {
36  
37      public AlfrescoValidation() {
38  
39      }
40  
41      /**
42       * This method only tests if the properties are available and not if their
43       * content is valid. If the content is not valid an excpetion will be thrown
44       * within {@link AlfrescoContentRetrievalImpl}.
45       * 
46       * @param properties
47       *                the properties which should be validated
48       * @throws PropertyValidationException
49       *                 If a property could not be validated
50       */
51      public void validateAlfrescoQueryProperties(
52  	    Map<String, PropertyModelFace> properties)
53  	    throws PropertyValidationException {
54  	if (properties != null) {
55  	    if (!properties
56  		    .containsKey(DefaultProperties.SPCP7_CURRENT_PATH
57  			    .toString())) {
58  		throw new PropertyValidationException("Property "
59  			+ DefaultProperties.SPCP7_CURRENT_PATH.toString()
60  			+ " not found",
61  			DefaultProperties.SPCP7_CURRENT_PATH.toString(),
62  			"not set");
63  
64  	    }
65  	    if (!properties
66  		    .containsKey(AlfrescoDefaultProperties.ALFRESCO_WORKSPACE_STORE
67  			    .toString())) {
68  		throw new PropertyValidationException("Property "
69  			+ AlfrescoDefaultProperties.ALFRESCO_WORKSPACE_STORE
70  				.toString() + " not found",
71  			AlfrescoDefaultProperties.ALFRESCO_WORKSPACE_STORE
72  				.toString(), "not set");
73  
74  	    }
75  	    if (!properties
76  		    .containsKey(AlfrescoDefaultProperties.ALFRESCO_SPACES_STORE
77  			    .toString())) {
78  		throw new PropertyValidationException("Property "
79  			+ AlfrescoDefaultProperties.ALFRESCO_SPACES_STORE
80  				.toString() + " not found",
81  			AlfrescoDefaultProperties.ALFRESCO_SPACES_STORE
82  				.toString(), "not set");
83  
84  	    }
85  	    if (!properties
86  		    .containsKey(AlfrescoDefaultProperties.ALFRESCO_MAX_RESULT_ROWS
87  			    .toString())) {
88  		throw new PropertyValidationException("Property "
89  			+ AlfrescoDefaultProperties.ALFRESCO_MAX_RESULT_ROWS
90  				.toString() + " not found",
91  			AlfrescoDefaultProperties.ALFRESCO_MAX_RESULT_ROWS
92  				.toString(), "not set");
93  
94  	    }
95  	    if (!properties
96  		    .containsKey(AlfrescoDefaultProperties.ALFRESCO_BASE_URL
97  			    .toString())) {
98  		throw new PropertyValidationException("Property "
99  			+ AlfrescoDefaultProperties.ALFRESCO_BASE_URL
100 				.toString() + " not found",
101 			AlfrescoDefaultProperties.ALFRESCO_BASE_URL.toString(),
102 			"not set");
103 
104 	    }
105 	} else {
106 	    throw new PropertyValidationException(
107 		    "Property map for validation was null!",
108 		    "Property map for validation was null!",
109 		    "Property map for validation was null!");
110 	}
111     }
112 }