001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.portlets.rpad.portlet.web.deployer;
018:
019: import java.util.Map;
020:
021: import javax.faces.context.FacesContext;
022:
023: import org.apache.jetspeed.portlets.rpad.RPADConstants;
024: import org.apache.jetspeed.portlets.rpad.RPADException;
025: import org.apache.jetspeed.portlets.rpad.Repository;
026: import org.apache.jetspeed.portlets.rpad.RepositoryManager;
027: import org.apache.jetspeed.portlets.rpad.portlet.util.FacesMessageUtil;
028: import org.apache.jetspeed.portlets.rpad.simple.SimpleRepository;
029:
030: public class EditRepositoryPage {
031:
032: private RepositoryManager repositoryManager = null;
033:
034: private boolean newRepository;
035:
036: private String name;
037:
038: private String path;
039:
040: public EditRepositoryPage() {
041: Map sessionMap = FacesContext.getCurrentInstance()
042: .getExternalContext().getSessionMap();
043: Repository repo = (Repository) sessionMap
044: .get(RPADConstants.REPOSITORY);
045: if (repo != null) {
046: //TODO support repositories other than SimpleRepository
047: if (repo instanceof SimpleRepository) {
048: SimpleRepository simpleRepo = (SimpleRepository) repo;
049: newRepository = false;
050: setName(simpleRepo.getName());
051: setPath(simpleRepo.getConfigPath());
052: } else {
053: newRepository = true;
054: sessionMap.remove(RPADConstants.REPOSITORY);
055: }
056: } else {
057: newRepository = true;
058: }
059: }
060:
061: public RepositoryManager getRepositoryManager() {
062: if (repositoryManager == null) {
063: repositoryManager = RepositoryManager.getInstance();
064: }
065: return repositoryManager;
066: }
067:
068: public String jumpDisplayRepositories() {
069: return "deployer_displayRepositories";
070: }
071:
072: public String doCreateRepository() {
073: if (getRepositoryManager().getRepository(getName()) == null) {
074: //TODO support repositories other than SimpleRepository
075: SimpleRepository repo = new SimpleRepository();
076: repo.setName(getName());
077: repo.setConfigPath(getPath());
078: repo.init();
079:
080: try {
081: getRepositoryManager().addRepository(getName(), repo);
082: getRepositoryManager().reload();
083: // TODO i18n
084: FacesMessageUtil.addInfoMessage(getName() + " exits.");
085: return "deployer_displayRepositories";
086: } catch (RPADException e) {
087: //TODO i18n
088: FacesMessageUtil
089: .addErrorMessage("Could not add a repository: "
090: + getName());
091: }
092: } else {
093: //TODO i18n
094: FacesMessageUtil.addWarnMessage(getName() + " exits.");
095: }
096:
097: return null;
098: }
099:
100: public String doUpdateRepository() {
101: Map sessionMap = FacesContext.getCurrentInstance()
102: .getExternalContext().getSessionMap();
103: Repository repo = (Repository) sessionMap
104: .get(RPADConstants.REPOSITORY);
105: if (repo != null) {
106: Repository r = getRepositoryManager().getRepository(
107: repo.getName());
108:
109: //TODO support repositories other than SimpleRepository
110: if (r instanceof SimpleRepository) {
111: SimpleRepository simpleRepo = (SimpleRepository) r;
112: simpleRepo.setName(getName());
113: simpleRepo.setConfigPath(getPath());
114: } else {
115: //TODO i18n
116: FacesMessageUtil
117: .addWarnMessage("Could not get the proper repository.");
118: }
119: try {
120: getRepositoryManager().store();
121: getRepositoryManager().reload();
122: //TODO i18n
123: FacesMessageUtil
124: .addWarnMessage("Could not get the proper repository.");
125: return null;
126: } catch (RPADException e) {
127: //TODO i18n
128: FacesMessageUtil
129: .addErrorMessage("Could not update the target repository.");
130: }
131:
132: } else {
133: //TODO i18n
134: FacesMessageUtil
135: .addWarnMessage("Your session might be expired.");
136: }
137: return "deployer_displayRepositories";
138: }
139:
140: /**
141: * @return the name
142: */
143: public String getName() {
144: return name;
145: }
146:
147: /**
148: * @param name the name to set
149: */
150: public void setName(String name) {
151: this .name = name;
152: }
153:
154: /**
155: * @return the newRepository
156: */
157: public boolean isNewRepository() {
158: return newRepository;
159: }
160:
161: /**
162: * @param newRepository the newRepository to set
163: */
164: public void setNewRepository(boolean newRepository) {
165: this .newRepository = newRepository;
166: }
167:
168: /**
169: * @return the path
170: */
171: public String getPath() {
172: return path;
173: }
174:
175: /**
176: * @param path the path to set
177: */
178: public void setPath(String path) {
179: this.path = path;
180: }
181: }
|