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.geronimo.console.jmsmanager.wizard;
018
019 import org.apache.geronimo.console.util.PortletManager;
020 import org.apache.geronimo.kernel.repository.Artifact;
021 import org.apache.geronimo.kernel.repository.ListableRepository;
022
023 import javax.portlet.ActionRequest;
024 import javax.portlet.ActionResponse;
025 import javax.portlet.PortletException;
026 import javax.portlet.RenderRequest;
027 import javax.portlet.RenderResponse;
028 import java.io.IOException;
029 import java.util.ArrayList;
030 import java.util.Collections;
031 import java.util.Iterator;
032 import java.util.List;
033 import java.util.SortedSet;
034 import org.apache.geronimo.console.MultiPageModel;
035
036 /**
037 * Handler for the screen where you select a JMS provider (because
038 * you didn't want one of the ones we know about).
039 *
040 * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
041 */
042 public class SelectProviderHandler extends AbstractHandler {
043 private final static String[] SKIP_RARS_CONTAINING = new String[]{"tranql"};
044
045 public SelectProviderHandler() {
046 super(SELECT_PROVIDER_MODE, "/WEB-INF/view/jmswizard/provider.jsp");
047 }
048
049 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
050 return getMode();
051 }
052
053 public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException {
054 loadRARList(request);
055 }
056
057 public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
058 JMSResourceData data = (JMSResourceData) model;
059 String rar = request.getParameter(RAR_FILE_PARAMETER);
060 if (isEmpty(rar)) {
061 return SELECT_PROVIDER_MODE + BEFORE_ACTION;
062 }
063 data.setRarURI(rar);
064 return CONFIGURE_RA_MODE + BEFORE_ACTION;
065 }
066
067 private void loadRARList(RenderRequest renderRequest) {
068 // List the available RARs
069 List list = new ArrayList();
070 ListableRepository[] repos = PortletManager.getCurrentServer(renderRequest).getRepositories();
071 for (int i = 0; i < repos.length; i++) {
072 ListableRepository repo = repos[i];
073 final SortedSet artifacts = repo.list();
074 outer:
075 for (Iterator iterator = artifacts.iterator(); iterator.hasNext();) {
076 Artifact artifact = (Artifact)iterator.next();
077 String test = artifact.toString();
078 if (!test.endsWith("/rar")) { //todo: may need to change this logic if configId format changes
079 continue;
080 } else if (repo.getLocation(artifact).isDirectory()) {
081 continue;
082 }
083 for (int k = 0; k < SKIP_RARS_CONTAINING.length; k++) {
084 String skip = SKIP_RARS_CONTAINING[k];
085 if (test.indexOf(skip) > -1) {
086 continue outer;
087 }
088 }
089 list.add(test);
090 }
091 }
092 Collections.sort(list);
093 renderRequest.setAttribute("rars", list);
094 }
095 }