001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.jsfsupport.container;
042:
043: import java.io.File;
044: import java.io.InputStream;
045: import java.net.MalformedURLException;
046: import java.net.URL;
047: import java.util.Enumeration;
048: import java.util.Hashtable;
049: import java.util.Set;
050:
051: //import javax.portlet.PortletContext;
052: //import javax.portlet.PortletRequestDispatcher;
053:
054: import org.openide.modules.InstalledFileLocator;
055:
056: /**
057: * A design-time portlet context for web apps rendered at designtime in Creator.
058: *
059: * Based heavily on RaveServletContext. I could not subclass RaveServletContext or
060: * make it implement both interfaces, because various client code, such as the Braveheart
061: * PageRenderer, checks "!(context instanceof ServletContext)" to see if it's a portlet,
062: * so a context which implements both will confuse code using that technique.
063: *
064: * @author Tor Norbye
065: */
066: public class RavePortletContext { //implements PortletContext {
067: /**
068: * Storage for attributes
069: */
070: private Hashtable attributes = new Hashtable();
071:
072: /**
073: * Storage for parameters
074: */
075: private Hashtable parameters = new Hashtable();
076:
077: /** Creates a new instance of RavePortletContext */
078: public RavePortletContext() {
079: }
080:
081: public Object getAttribute(String name) {
082: return attributes.get(name);
083: }
084:
085: public void removeAttribute(String name) {
086: attributes.remove(name);
087: }
088:
089: public void setAttribute(String name, Object value) {
090: attributes.put(name, value);
091: }
092:
093: public Enumeration getAttributeNames() {
094: return attributes.keys();
095: }
096:
097: public String getInitParameter(String name) {
098: return (String) parameters.get(name);
099: }
100:
101: public java.util.Enumeration getInitParameterNames() {
102: return parameters.keys();
103: }
104:
105: public int getMajorVersion() {
106: return 1;
107: }
108:
109: public int getMinorVersion() {
110: return 0;
111: }
112:
113: public String getMimeType(String file) {
114: throw new UnsupportedOperationException();
115: }
116:
117: public String getRealPath(String path) {
118: URL url = Thread.currentThread().getContextClassLoader()
119: .getResource(path);
120:
121: if (url == null) {
122: return null;
123: }
124:
125: String str = url.getPath();
126:
127: if (str.startsWith("file:")) {
128: int i = 5;
129:
130: while (str.charAt(i) == '/')
131: i++;
132:
133: str = str.substring(i);
134: }
135:
136: return str;
137: }
138:
139: public java.net.URL getResource(String resource)
140: throws MalformedURLException {
141: URL url = null;
142: ClassLoader loader = getClass().getClassLoader();
143:
144: if (!resource.endsWith(".jar")) {
145: String fqpath = "com/sun/rave/jsfsupp/container" + resource;
146: url = loader.getResource(fqpath);
147: } else {
148: // TODO: BOB
149: // If the location of where we install component libraries changes (likely),
150: // the hard-coded relative path below needs to change
151: File file = InstalledFileLocator.getDefault().locate(
152: "/modules/autoload/ext/" + resource, null, false);
153: url = file.toURL();
154: }
155:
156: return url;
157: }
158:
159: public InputStream getResourceAsStream(String path) {
160: ClassLoader loader = getClass().getClassLoader();
161: String fqpath = "com/sun/rave/jsfsupp/container" + path;
162:
163: return loader.getResourceAsStream(fqpath);
164: }
165:
166: public String getPortletContextName() {
167: return "RavePortletContext";
168: }
169:
170: public String getServerInfo() {
171: return "RavePortletContext";
172: }
173:
174: // public PortletRequestDispatcher getNamedDispatcher(String name) {
175: // throw new UnsupportedOperationException();
176: // }
177: //
178: // public PortletRequestDispatcher getRequestDispatcher(String path) {
179: // throw new UnsupportedOperationException();
180: // }
181:
182: public java.util.Set getResourcePaths(String path) {
183: throw new UnsupportedOperationException();
184: }
185:
186: public void log(String msg) {
187: throw new UnsupportedOperationException();
188: }
189:
190: public void log(String message, Throwable throwable) {
191: throw new UnsupportedOperationException();
192: }
193: }
|