View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.property.processor;
17  
18  import java.io.File;
19  import java.util.Properties;
20  
21  import org.kuali.common.util.Mode;
22  import org.kuali.common.util.OrgUtils;
23  import org.kuali.common.util.PropertyUtils;
24  import org.kuali.common.util.Str;
25  import org.kuali.common.util.property.Constants;
26  import org.springframework.util.Assert;
27  
28  public class HomeProcessor implements PropertyProcessor {
29  
30  	Mode propertyOverwriteMode = Constants.DEFAULT_PROPERTY_OVERWRITE_MODE;
31  	String userHomeProperty = Constants.DEFAULT_USER_HOME_PROPERTY;
32  	String fileSeparator = File.separator;
33  	String hiddenDirectoryIndicator = Str.DOT;
34  	String organizationGroupId;
35  	String groupId;
36  
37  	public HomeProcessor() {
38  		this(null, null);
39  	}
40  
41  	public HomeProcessor(String organizationGroupId, String groupId) {
42  		super();
43  		this.organizationGroupId = organizationGroupId;
44  		this.groupId = groupId;
45  	}
46  
47  	@Override
48  	public void process(Properties properties) {
49  		Assert.notNull(organizationGroupId);
50  		Assert.notNull(groupId);
51  
52  		String organizationCode = OrgUtils.getOrgCode(organizationGroupId);
53  		String groupCode = OrgUtils.getGroupCode(organizationGroupId, groupId);
54  
55  		String organizationHomeProperty = organizationCode + Str.DOT + Constants.DEFAULT_HOME_SUFFIX;
56  		String groupHomeProperty = organizationCode + Str.DOT + Constants.GROUP + Str.DOT + Constants.DEFAULT_HOME_SUFFIX;
57  
58  		String organizationHome = System.getProperty(userHomeProperty) + fileSeparator + hiddenDirectoryIndicator + organizationCode;
59  		String groupHome = organizationHome + fileSeparator + groupCode;
60  
61  		PropertyUtils.addOrOverrideProperty(properties, organizationHomeProperty, organizationHome, propertyOverwriteMode);
62  		PropertyUtils.addOrOverrideProperty(properties, groupHomeProperty, groupHome, propertyOverwriteMode);
63  	}
64  
65  	public Mode getPropertyOverwriteMode() {
66  		return propertyOverwriteMode;
67  	}
68  
69  	public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
70  		this.propertyOverwriteMode = propertyOverwriteMode;
71  	}
72  
73  	public String getUserHomeProperty() {
74  		return userHomeProperty;
75  	}
76  
77  	public void setUserHomeProperty(String userHomeProperty) {
78  		this.userHomeProperty = userHomeProperty;
79  	}
80  
81  	public String getFileSeparator() {
82  		return fileSeparator;
83  	}
84  
85  	public void setFileSeparator(String fileSeparator) {
86  		this.fileSeparator = fileSeparator;
87  	}
88  
89  	public String getHiddenDirectoryIndicator() {
90  		return hiddenDirectoryIndicator;
91  	}
92  
93  	public void setHiddenDirectoryIndicator(String hiddenDirectoryIndicator) {
94  		this.hiddenDirectoryIndicator = hiddenDirectoryIndicator;
95  	}
96  
97  	public String getOrganizationGroupId() {
98  		return organizationGroupId;
99  	}
100 
101 	public void setOrganizationGroupId(String organizationGroupId) {
102 		this.organizationGroupId = organizationGroupId;
103 	}
104 
105 	public String getGroupId() {
106 		return groupId;
107 	}
108 
109 	public void setGroupId(String groupId) {
110 		this.groupId = groupId;
111 	}
112 }