KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > equinox > jsp > jasper > registry > JSPFactory


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.equinox.jsp.jasper.registry;
12
13 import java.util.Hashtable JavaDoc;
14 import org.eclipse.core.runtime.*;
15 import org.eclipse.equinox.internal.jsp.jasper.registry.Activator;
16 import org.eclipse.equinox.jsp.jasper.JspServlet;
17 import org.osgi.framework.Bundle;
18
19 /**
20  * <p>
21  * The JSPFactory can be used in conjunction with org.eclipse.equinox.http.registry and the Servlets extension point
22  * to allow the use of JSPs declaratively with the extension registry.
23  * </p>
24  * <p>
25  * JSPFactory will accept a "path" parameter corresponding to the base path in the bundle to look up JSP resources.
26  * This parameter can be set using the ":" separator approach or by xml parameter.
27  * </p>
28  * e.g. class="org.eclipse.equinox.jsp.jasper.registry.JSPFactory:/A/PATH" or &lt;parameter name="path" value="/A/PATH"/&gt;
29  */

30 public class JSPFactory implements IExecutableExtensionFactory, IExecutableExtension {
31
32     private IConfigurationElement config;
33     private String JavaDoc bundleResourcePath;
34
35     public void setInitializationData(IConfigurationElement config, String JavaDoc propertyName, Object JavaDoc data) throws CoreException {
36         this.config = config;
37         if (data != null) {
38             if (data instanceof String JavaDoc)
39                 bundleResourcePath = (String JavaDoc) data;
40             else if (data instanceof Hashtable JavaDoc) {
41                 bundleResourcePath = (String JavaDoc) ((Hashtable JavaDoc) data).get("path"); //$NON-NLS-1$
42
}
43         }
44     }
45
46     public Object JavaDoc create() throws CoreException {
47         Bundle b = Activator.getBundle(config.getContributor().getName()); //check for null and illegal state exception
48
String JavaDoc alias = config.getAttribute("alias"); //$NON-NLS-1$
49
if (alias != null && alias.indexOf("/*.") == alias.lastIndexOf('/')) { //$NON-NLS-1$
50
alias = alias.substring(0, alias.lastIndexOf('/'));
51             if (alias.length() == 0)
52                 alias = "/"; //$NON-NLS-1$
53
}
54         return new JspServlet(b, bundleResourcePath, alias);
55     }
56 }
57
Popular Tags