001    /**
002     * Copyright 2010-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.common.util.property.processor;
017    
018    import java.io.File;
019    import java.util.Properties;
020    
021    import org.kuali.common.util.Mode;
022    import org.kuali.common.util.OrgUtils;
023    import org.kuali.common.util.PropertyUtils;
024    import org.kuali.common.util.Str;
025    import org.kuali.common.util.property.Constants;
026    import org.springframework.util.Assert;
027    
028    public class HomeProcessor implements PropertyProcessor {
029    
030            Mode propertyOverwriteMode = Constants.DEFAULT_PROPERTY_OVERWRITE_MODE;
031            String userHomeProperty = Constants.DEFAULT_USER_HOME_PROPERTY;
032            String fileSeparator = File.separator;
033            String hiddenDirectoryIndicator = Str.DOT;
034            String organizationGroupId;
035            String groupId;
036    
037            public HomeProcessor() {
038                    this(null, null);
039            }
040    
041            public HomeProcessor(String organizationGroupId, String groupId) {
042                    super();
043                    this.organizationGroupId = organizationGroupId;
044                    this.groupId = groupId;
045            }
046    
047            @Override
048            public void process(Properties properties) {
049                    Assert.notNull(organizationGroupId);
050                    Assert.notNull(groupId);
051    
052                    String organizationCode = OrgUtils.getOrgCode(organizationGroupId);
053                    String groupCode = OrgUtils.getGroupCode(organizationGroupId, groupId);
054    
055                    String organizationHomeProperty = organizationCode + Str.DOT + Constants.DEFAULT_HOME_SUFFIX;
056                    String groupHomeProperty = organizationCode + Str.DOT + Constants.GROUP + Str.DOT + Constants.DEFAULT_HOME_SUFFIX;
057    
058                    String organizationHome = System.getProperty(userHomeProperty) + fileSeparator + hiddenDirectoryIndicator + organizationCode;
059                    String groupHome = organizationHome + fileSeparator + groupCode;
060    
061                    PropertyUtils.addOrOverrideProperty(properties, organizationHomeProperty, organizationHome, propertyOverwriteMode);
062                    PropertyUtils.addOrOverrideProperty(properties, groupHomeProperty, groupHome, propertyOverwriteMode);
063            }
064    
065            public Mode getPropertyOverwriteMode() {
066                    return propertyOverwriteMode;
067            }
068    
069            public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
070                    this.propertyOverwriteMode = propertyOverwriteMode;
071            }
072    
073            public String getUserHomeProperty() {
074                    return userHomeProperty;
075            }
076    
077            public void setUserHomeProperty(String userHomeProperty) {
078                    this.userHomeProperty = userHomeProperty;
079            }
080    
081            public String getFileSeparator() {
082                    return fileSeparator;
083            }
084    
085            public void setFileSeparator(String fileSeparator) {
086                    this.fileSeparator = fileSeparator;
087            }
088    
089            public String getHiddenDirectoryIndicator() {
090                    return hiddenDirectoryIndicator;
091            }
092    
093            public void setHiddenDirectoryIndicator(String hiddenDirectoryIndicator) {
094                    this.hiddenDirectoryIndicator = hiddenDirectoryIndicator;
095            }
096    
097            public String getOrganizationGroupId() {
098                    return organizationGroupId;
099            }
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    }