KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > action > evaluator > CompareMimeTypeEvaluator


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.action.evaluator;
18
19 import java.util.List JavaDoc;
20
21 import org.alfresco.model.ContentModel;
22 import org.alfresco.repo.action.evaluator.compare.ContentPropertyName;
23 import org.alfresco.service.cmr.action.ActionCondition;
24 import org.alfresco.service.cmr.action.ActionServiceException;
25 import org.alfresco.service.cmr.action.ParameterDefinition;
26 import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
27 import org.alfresco.service.cmr.dictionary.PropertyDefinition;
28 import org.alfresco.service.cmr.repository.NodeRef;
29 import org.alfresco.service.namespace.QName;
30
31 /**
32  * Compare mime type evaluator
33  *
34  * @author Roy Wetherall
35  */

36 public class CompareMimeTypeEvaluator extends ComparePropertyValueEvaluator
37 {
38     /**
39      * Evaluator constants
40      */

41     public static final String JavaDoc NAME = "compare-mime-type";
42     
43     /**
44      *
45      */

46     private static final String JavaDoc ERRID_NOT_A_CONTENT_TYPE = "compare_mime_type_evaluator.not_a_content_type";
47     private static final String JavaDoc ERRID_NO_PROPERTY_DEFINTION_FOUND = "compare_mime_type_evaluator.no_property_definition_found";
48     
49     /**
50      * @see org.alfresco.repo.action.evaluator.ActionConditionEvaluatorAbstractBase#evaluateImpl(org.alfresco.service.cmr.action.ActionCondition, org.alfresco.service.cmr.repository.NodeRef)
51      */

52     public boolean evaluateImpl(ActionCondition actionCondition, NodeRef actionedUponNodeRef)
53     {
54         QName propertyQName = (QName)actionCondition.getParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY);
55         if (propertyQName == null)
56         {
57             // Default to the standard content property
58
actionCondition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, ContentModel.PROP_CONTENT);
59         }
60         else
61         {
62             // Ensure that we are dealing with a content property
63
QName propertyTypeQName = null;
64             PropertyDefinition propertyDefintion = this.dictionaryService.getProperty(propertyQName);
65             if (propertyDefintion != null)
66             {
67                 propertyTypeQName = propertyDefintion.getDataType().getName();
68                 if (DataTypeDefinition.CONTENT.equals(propertyTypeQName) == false)
69                 {
70                     throw new ActionServiceException(ERRID_NOT_A_CONTENT_TYPE);
71                 }
72             }
73             else
74             {
75                 throw new ActionServiceException(ERRID_NO_PROPERTY_DEFINTION_FOUND);
76             }
77         }
78         
79         // Set the content property to be MIMETYPE
80
actionCondition.setParameterValue(ComparePropertyValueEvaluator.PARAM_CONTENT_PROPERTY, ContentPropertyName.MIME_TYPE.toString());
81
82         return super.evaluateImpl(actionCondition, actionedUponNodeRef);
83     }
84
85     /**
86      * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
87      */

88     @Override JavaDoc
89     protected void addParameterDefintions(List JavaDoc<ParameterDefinition> paramList)
90     {
91         super.addParameterDefintions(paramList);
92     }
93 }
94
Popular Tags