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.infomanager;
017:
018: import java.io.IOException;
019: import java.util.ArrayList;
020: import java.util.List;
021: import java.util.StringTokenizer;
022: import java.util.Map;
023: import java.util.TreeMap;
024:
025: import javax.portlet.ActionRequest;
026: import javax.portlet.ActionResponse;
027: import javax.portlet.PortletConfig;
028: import javax.portlet.PortletException;
029: import javax.portlet.PortletRequestDispatcher;
030: import javax.portlet.RenderRequest;
031: import javax.portlet.RenderResponse;
032: import javax.portlet.WindowState;
033:
034: import org.apache.geronimo.console.BasePortlet;
035: import org.apache.geronimo.console.util.PortletManager;
036:
037: public class JavaSystemInfoPortlet extends BasePortlet {
038:
039: private static final String NORMALVIEW_JSP = "/WEB-INF/view/infomanager/javaSysNormal.jsp";
040:
041: private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/infomanager/javaSysMaximized.jsp";
042:
043: private static final String HELPVIEW_JSP = "/WEB-INF/view/infomanager/javaSysHelp.jsp";
044:
045: private PortletRequestDispatcher normalView;
046:
047: private PortletRequestDispatcher maximizedView;
048:
049: private PortletRequestDispatcher helpView;
050:
051: public void processAction(ActionRequest actionRequest,
052: ActionResponse actionResponse) throws PortletException,
053: IOException {
054: }
055:
056: protected void doView(RenderRequest renderRequest,
057: RenderResponse renderResponse) throws IOException,
058: PortletException {
059: if (WindowState.MINIMIZED
060: .equals(renderRequest.getWindowState())) {
061: return;
062: }
063:
064: ShrinkingMap javaSysProps = new ShrinkingMap(PortletManager
065: .getCurrentJVM(renderRequest).getSystemProperties());
066:
067: renderRequest.setAttribute("javaSysProps", javaSysProps);
068:
069: String sep = (String) javaSysProps.get("path.separator");
070:
071: String test = (String) javaSysProps.get("sun.boot.class.path");
072: if (test != null) {
073: javaSysProps.put("sun.boot.class.path", split(test, sep));
074: }
075: test = (String) javaSysProps.get("sun.boot.library.path");
076: if (test != null) {
077: javaSysProps.put("sun.boot.library.path", split(test, sep));
078: }
079: test = (String) javaSysProps.get("java.library.path");
080: if (test != null) {
081: javaSysProps.put("java.library.path", split(test, sep));
082: }
083: test = (String) javaSysProps.get("java.class.path");
084: if (test != null) {
085: javaSysProps.put("java.class.path", split(test, sep));
086: }
087: test = (String) javaSysProps.get("java.endorsed.dirs");
088: if (test != null) {
089: javaSysProps.put("java.endorsed.dirs", split(test, sep));
090: }
091: test = (String) javaSysProps.get("java.ext.dirs");
092: if (test != null) {
093: javaSysProps.put("java.ext.dirs", split(test, sep));
094: }
095: test = (String) javaSysProps.get("common.loader");
096: if (test != null) {
097: javaSysProps.put("common.loader", test.replace(',', ' '));
098: }
099:
100: // Remove a few properties for security reasons
101: javaSysProps.remove("javax.net.ssl.keyStore");
102: javaSysProps.remove("javax.net.ssl.keyStorePassword");
103: javaSysProps.remove("javax.net.ssl.trustStore");
104: javaSysProps.remove("javax.net.ssl.trustStorePassword");
105:
106: javaSysProps.setShrinking(true);
107:
108: if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
109: normalView.include(renderRequest, renderResponse);
110: } else {
111: maximizedView.include(renderRequest, renderResponse);
112: }
113: }
114:
115: private List split(String path, String sep) {
116: StringTokenizer st = new StringTokenizer(path, sep);
117:
118: List l = new ArrayList();
119:
120: while (st.hasMoreTokens()) {
121: l.add(st.nextToken());
122: }
123: return l;
124: }
125:
126: protected void doHelp(RenderRequest renderRequest,
127: RenderResponse renderResponse) throws PortletException,
128: IOException {
129: helpView.include(renderRequest, renderResponse);
130: }
131:
132: public void init(PortletConfig portletConfig)
133: throws PortletException {
134: super .init(portletConfig);
135: normalView = portletConfig.getPortletContext()
136: .getRequestDispatcher(NORMALVIEW_JSP);
137: maximizedView = portletConfig.getPortletContext()
138: .getRequestDispatcher(MAXIMIZEDVIEW_JSP);
139: helpView = portletConfig.getPortletContext()
140: .getRequestDispatcher(HELPVIEW_JSP);
141: }
142:
143: public void destroy() {
144: normalView = null;
145: maximizedView = null;
146: helpView = null;
147: super.destroy();
148: }
149:
150: }
|