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