diff options
Diffstat (limited to 'plugins/org.eclipse.jst.j2ee.web/web/org')
20 files changed, 0 insertions, 4438 deletions
diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/J2EEFlexProjWebDeployable.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/J2EEFlexProjWebDeployable.java deleted file mode 100644 index be6eda79b..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/J2EEFlexProjWebDeployable.java +++ /dev/null @@ -1,435 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.web.deployables; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.jst.j2ee.internal.deployables.J2EEFlexProjDeployable; -import org.eclipse.jst.j2ee.internal.deployables.LooseArchiveDeployable; -import org.eclipse.jst.j2ee.internal.deployables.LooseArchiveDeployableFactory; -import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit; -import org.eclipse.jst.server.core.ILooseArchive; -import org.eclipse.jst.server.core.ILooseArchiveSupport; -import org.eclipse.jst.server.core.IWebModule; -import org.eclipse.wst.common.componentcore.internal.Property; -import org.eclipse.wst.common.componentcore.internal.StructureEdit; -import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent; -import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; -import org.eclipse.wst.common.componentcore.resources.ComponentHandle; -import org.eclipse.wst.server.core.IModule; -import org.eclipse.wst.server.core.IModuleType; -import org.eclipse.wst.web.internal.operation.ILibModule; - -/** - * @version 1.0 - * @author - */ -public class J2EEFlexProjWebDeployable extends J2EEFlexProjDeployable implements IWebModule, ILooseArchiveSupport, IModuleType { - protected String contextRoot; - - protected ILooseArchive[] archives; - private IPath rootfolder = null; - - protected Map uris = new HashMap(); - - public static final String WEB_MODULE_TYPE = "jst.web"; - - - - /** - * @param aNature - * @param aFactoryId - */ - public J2EEFlexProjWebDeployable(IProject project, String aFactoryId, WorkbenchComponent aWorkbenchModule) { - super(project, aFactoryId, aWorkbenchModule); - this.contextRoot = getUncachedContextRoot(); - } - - public String getId() { - return getProject().getName(); - } - - public String getContextRoot() { - List existingProps = wbModule.getComponentType().getProperties(); - for (int i = 0; i < existingProps.size(); i++) { - Property prop = (Property) existingProps.get(i); - if(prop.getName().equals(J2EEConstants.CONTEXTROOT)){ - return prop.getValue(); - } - } - return wbModule.getName(); - } - - - - public String getUncachedContextRoot() { - //return getWebNature().getContextRoot(); - - return project.getName(); - - } - - - - - public String getJ2EESpecificationVersion() { - String Version = "1.2"; //$NON-NLS-1$ - - WebArtifactEdit webEdit = null; - try { - ComponentHandle handle = ComponentHandle.create(StructureEdit.getContainingProject(wbModule),wbModule.getName()); - webEdit = WebArtifactEdit.getWebArtifactEditForRead(handle); - if(webEdit != null) { - int nVersion = webEdit.getJ2EEVersion(); - switch( nVersion ){ - case 12: - Version = IModuleConstants.J2EE_VERSION_1_2; - break; - case 13: - Version = IModuleConstants.J2EE_VERSION_1_3; - break; - case 14: - Version = IModuleConstants.J2EE_VERSION_1_4; - break; - default: - Version = IModuleConstants.J2EE_VERSION_1_2; - break; - } - } - } - catch(Exception e){ - e.printStackTrace(); - } finally { - if(webEdit != null) - webEdit.dispose(); - } - - return Version; - } - - public String getJSPFileMapping(String jspFile) { - return null; - } - - private int getServletVersion(){ - WebArtifactEdit webEdit = null; - int nVersion = 22; - try{ - ComponentHandle handle = ComponentHandle.create(StructureEdit.getContainingProject(wbModule),wbModule.getName()); - webEdit = WebArtifactEdit.getWebArtifactEditForRead(handle); - if(webEdit != null) { - nVersion = webEdit.getServletVersion(); - } - } - catch(Exception e){ - e.printStackTrace(); - } finally { - if(webEdit != null) - webEdit.dispose(); - } - return nVersion; - } - - public String getJSPSpecificationVersion() { - - String ret = "1.2"; //$NON-NLS-1$ - int nVersion = getServletVersion(); - switch( nVersion ){ - - case 22: - ret = IModuleConstants.JSP_VERSION_1_1; - break; - case 23: - ret = IModuleConstants.JSP_VERSION_1_2; - break; - case 24: - ret = IModuleConstants.JSP_VERSION_2_0; - break; - default: - ret = IModuleConstants.JSP_VERSION_1_1; - break; - } - return ret; - } - - public String getServletSpecificationVersion() { - - String ret = "2.3"; //$NON-NLS-1$ - int nVersion = getServletVersion(); - switch( nVersion ){ - - case 22: - ret = IModuleConstants.SERVLET_VERSION_2_2; - break; - case 23: - ret = IModuleConstants.SERVLET_VERSION_2_3; - break; - case 24: - ret = IModuleConstants.SERVLET_VERSION_2_4; - break; - default: - ret = IModuleConstants.SERVLET_VERSION_2_3; - break; - } - return ret; - } - - - public String getServletMapping(String className) { - return null; - } - - - public boolean isPublishRequired() { - return false; - } - - protected LooseArchiveDeployableFactory getLooseArchiveDeployableFactory() { - /* - * Iterator factories = - * Arrays.asList(ServerCore.getModuleFactories()).iterator(); while - * (factories.hasNext()) { ModuleFactory deployableFactory = - * (ModuleFactory) factories.next(); ModuleFactoryDelegate - * deployableFactoryDelegate = deployableFactory.getDelegate(); if - * (deployableFactoryDelegate instanceof LooseArchiveDeployableFactory) - * return (LooseArchiveDeployableFactory) deployableFactoryDelegate; } - */ - return null; - } - -/* protected ILooseArchive getArchiveDeployable(IProject aProject, LooseArchiveDeployableFactory fact) { - return (ILooseArchive) fact.getModuleProject(aProject); - }*/ - - protected ILibModule[] getLibModules() { - return null; - } - - /* public ILooseArchive[] getLooseArchives() { - return this.archives; - }*/ - - /* - * @see com.ibm.etools.server.core.util.DeployableProject#getRootFolder() - */ - - - - public ILooseArchive[] getUncachedLooseArchives() { - ILibModule[] libModules = getLibModules(); - if (libModules == null) - return null; - - LooseArchiveDeployableFactory fact = getLooseArchiveDeployableFactory(); - if (fact == null) - return null; - - List arcs = new ArrayList(libModules.length); - for (int i = 0; i < libModules.length; i++) { - ILibModule libModule = libModules[i]; - IProject proj = libModule.getProject(); - /* if (proj != null && proj.exists()) - arcs.add(getArchiveDeployable(proj, fact));*/ - } - ILooseArchive[] result = new ILooseArchive[arcs.size()]; - arcs.toArray(result); - return result; - } - - public String getURI(ILooseArchive jar) { - try { - return (String) this.uris.get(jar); - } catch (Exception e) { - // ignore - } - return null; - } - - public String getUncachedURI(ILooseArchive jar) { - if (!(jar instanceof LooseArchiveDeployable)) - return null; - - LooseArchiveDeployable dep = (LooseArchiveDeployable) jar; - IProject proj = dep.getProject(); - return getURI(proj); - } - - protected String getURI(IProject looseJARProject) { - return null; - } - - public boolean isBinary() { - return false; - } - - protected void update() { - ILooseArchive[] oldArchives = this.archives; - this.archives = getUncachedLooseArchives(); - if (this.archives == null) - this.archives = new ILooseArchive[0]; - String oldContextRoot = this.contextRoot; - this.contextRoot = getUncachedContextRoot(); - - boolean changed = false; - if (oldContextRoot == null && this.contextRoot != null) - changed = true; - else if (oldContextRoot != null && !oldContextRoot.equals(this.contextRoot)) - changed = true; - - // fire remove events - List add = new ArrayList(2); - addRemovedObjects(add, oldArchives, this.archives); - - // fire add events - List remove = new ArrayList(2); - addAddedObjects(remove, oldArchives, this.archives); - - // fire change events - int size = this.archives.length; - List change = new ArrayList(size); - for (int i = 0; i < size; i++) { - String newURI = getUncachedURI(this.archives[i]); - String oldURI = getURI(this.archives[i]); - - if (oldURI != null && !oldURI.equals(newURI)) { - change.add(this.archives[i]); - } - this.uris.put(this.archives[i], newURI); - } - - if (!add.isEmpty() || !remove.isEmpty() || !change.isEmpty() || changed) { - IModule[] added = new IModule[add.size()]; - add.toArray(added); - IModule[] changed2 = new IModule[change.size()]; - change.toArray(changed2); - IModule[] removed = new IModule[remove.size()]; - remove.toArray(removed); - // fireModuleChangeEvent(changed, added, changed2, removed); - } - } - - /** - * Return the objects that have been added between array a and array b. - * Assumes that there are no null objects in the array. - */ - protected static void addAddedObjects(List list, Object[] a, Object[] b) { - if (b == null) - return; - else if (a == null) { - int size = b.length; - for (int i = 0; i < size; i++) - list.add(b[i]); - return; - } - int size = b.length; - for (int i = 0; i < size; i++) { - Object obj = b[i]; - boolean found = false; - if (a != null) { - int size2 = a.length; - for (int j = 0; !found && j < size2; j++) { - if (obj != null && obj.equals(a[j])) - found = true; - } - } - if (!found) - list.add(obj); - } - } - - /** - * Return the objects that have been removed between array a and array b. - * Assumes that there are no null objects in the array. - */ - protected static void addRemovedObjects(List list, Object[] a, Object[] b) { - if (a == null) - return; - else if (b == null) { - int size = a.length; - for (int i = 0; i < size; i++) - list.add(a[i]); - return; - } - int size = a.length; - for (int i = 0; i < size; i++) { - Object obj = a[i]; - boolean found = false; - if (b != null) { - int size2 = b.length; - for (int j = 0; !found && j < size2; j++) { - if (obj != null && obj.equals(b[j])) - found = true; - } - } - if (!found) - list.add(obj); - } - } - - public String getType() { - return "j2ee.web"; //$NON-NLS-1$ - } - - public String getVersion() { - - return "1.2"; //$NON-NLS-1$ - } - - /** - * Returns the child modules of this module. - * - * @return com.ibm.wtp.server.core.model.IModule[] - */ - public IModule[] getChildModules() { - List list = new ArrayList(); - - if (this.archives != null) { - int size = this.archives.length; - for (int i = 0; i < size; i++) - list.add(this.archives[i]); - } - - IModule[] children = new IModule[list.size()]; - list.toArray(children); - return children; - } - - - public String getModuleTypeName(){ - return getName(); - } - - public String getModuleTypeVersion(){ - return getVersion(); - } - - public IPath getRootfolder() { -// if (ModuleCoreNature.getModuleCoreNature(project) != null ) { -// if (wbModule != null ) { -// IFolder outputContainer = ModuleCore.getOutputContainerRoot(wbModule); -// IPath path = outputContainer.getProjectRelativePath(); -// } -// } - return rootfolder; - } - - public IModule[] getLooseArchives() { - // TODO Auto-generated method stub - return null; - } - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/ModuleAdapter.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/ModuleAdapter.java deleted file mode 100644 index 4286d3717..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/ModuleAdapter.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Created on Feb 8, 2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.eclipse.jst.j2ee.internal.web.deployables; - -import org.eclipse.emf.common.notify.impl.AdapterImpl; - -/** - * @author blancett - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates - */ -public class ModuleAdapter extends AdapterImpl { - - J2EEFlexProjWebDeployable delegate; - - public void setModuleDelegate(J2EEFlexProjWebDeployable moduleDelegate) { - delegate = moduleDelegate; - } - - public J2EEFlexProjWebDeployable getDelegate() { - return delegate; - } -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployable.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployable.java deleted file mode 100644 index 23f4c257e..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployable.java +++ /dev/null @@ -1,67 +0,0 @@ -/*************************************************************************************************** - * Copyright (c) 2003, 2004 IBM Corporation and others. All rights reserved. This program and the - * accompanying materials are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: IBM Corporation - initial API and implementation - **************************************************************************************************/ -package org.eclipse.jst.j2ee.internal.web.deployables; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jst.j2ee.internal.project.IWebNatureConstants; -import org.eclipse.wst.server.core.IModule; -import org.eclipse.wst.server.core.util.ProjectModule; - -public abstract class WebDeployable extends ProjectModule implements IModule, IWebNatureConstants { - - public WebDeployable(IProject project) { - super(project); - //setWebNature(getWebNature()); - } - -// protected IBaseWebNature getWebNature() { -// return J2EEWebNatureRuntimeUtilities.getRuntime(this.project); -// } - - public String getFactoryId() { - return "com.ibm.wtp.web.server"; //$NON-NLS-1$ - } - - /** - * Sets the nature. - * - * @param nature - * The nature to set - */ -// protected void setWebNature(IBaseWebNature nature) { -// nature.setModule(this); -// } - - /** - * Returns true if this deployable currently exists, and false if it has been deleted or moved - * and is no longer represented by this deployable. - * - * @return boolean - */ - public boolean exists() { - if (getProject() == null || !getProject().exists()) - return false; - try { - return (this.project.hasNature(IWebNatureConstants.J2EE_NATURE_ID)); - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } - - /** - * @see com.ibm.etools.server.core.util.DeployableProject#getRootFolder() - */ - public IPath getRootFolder() { - //To Do: Needs rework based on module - //return getWebNature().getRootPublishableFolder().getProjectRelativePath(); - return null; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployableArtifactAdapterFactory.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployableArtifactAdapterFactory.java deleted file mode 100644 index 3dfa57683..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployableArtifactAdapterFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Created on Jan 18, 2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.eclipse.jst.j2ee.internal.web.deployables; - -import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.debug.ui.actions.ILaunchable; -import org.eclipse.wst.server.core.IModuleArtifact; -import org.eclipse.wst.server.core.model.ModuleArtifactAdapterDelegate; - -public class WebDeployableArtifactAdapterFactory extends ModuleArtifactAdapterDelegate implements IAdapterFactory { - - public Object getAdapter(Object adaptableObject, Class adapterType) { - return null; - } - - public Class[] getAdapterList() { - return new Class[]{ILaunchable.class}; - } - - - public IModuleArtifact getModuleArtifact(Object obj) { - return WebDeployableArtifactUtil.getModuleObject(obj); - } - -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployableArtifactUtil.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployableArtifactUtil.java deleted file mode 100644 index c172935f6..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployableArtifactUtil.java +++ /dev/null @@ -1,391 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.web.deployables; - -import java.util.Arrays; -import java.util.Iterator; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.ITypeHierarchy; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jst.j2ee.internal.web.jfaces.extension.FileURL; -import org.eclipse.jst.j2ee.internal.web.jfaces.extension.FileURLExtensionReader; -import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit; -import org.eclipse.jst.j2ee.webapplication.JSPType; -import org.eclipse.jst.j2ee.webapplication.Servlet; -import org.eclipse.jst.j2ee.webapplication.ServletMapping; -import org.eclipse.jst.j2ee.webapplication.ServletType; -import org.eclipse.jst.j2ee.webapplication.WebApp; -import org.eclipse.jst.j2ee.webapplication.WebType; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.internal.StructureEdit; -import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent; -import org.eclipse.wst.common.componentcore.resources.ComponentHandle; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualResource; -import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper; -import org.eclipse.wst.server.core.IModule; -import org.eclipse.wst.server.core.IModuleArtifact; -import org.eclipse.wst.server.core.ServerUtil; -import org.eclipse.wst.server.core.util.WebResource; - -/** - * @version 1.0 - * @author - */ -public class WebDeployableArtifactUtil { - private final static String[] extensionsToExclude = new String[]{"sql", "xmi"}; //$NON-NLS-1$ //$NON-NLS-2$ - private final static String GENERIC_SERVLET_CLASS_TYPE = "javax.servlet.GenericServlet"; - private final static String CACTUS_SERVLET_CLASS_TYPE = "org.apache.cactus.server.ServletTestRedirector"; - - public WebDeployableArtifactUtil() { - super(); - } - - public static IModuleArtifact getModuleObject(Object obj) { - IResource resource = null; - if (obj instanceof IResource) - resource = (IResource) obj; - else if (obj instanceof IAdaptable) - resource = (IResource) ((IAdaptable) obj).getAdapter(IResource.class); - else if (obj instanceof EObject) { - resource = ProjectUtilities.getProject((EObject) obj); - if (obj instanceof Servlet) { - Servlet servlet = ((Servlet) obj); - Resource servResource = servlet.eResource(); - IVirtualResource[] resources = null; - try { - IResource eclipeServResoruce = (IResource) WorkbenchResourceHelper.getFile(servResource); - resources = ComponentCore.createResources(eclipeServResoruce); - } catch (Exception e) { - e.printStackTrace(); - } - IVirtualComponent component = null; - if (resources[0] != null) - component = resources[0].getComponent(); - String mapping = null; - java.util.List mappings = ((Servlet) obj).getMappings(); - if (mappings != null && !mappings.isEmpty()) { - ServletMapping map = (ServletMapping) mappings.get(0); - mapping = map.getUrlPattern(); - } - if (mapping != null) { - return new WebResource(getModule(resource.getProject(), component), new Path(mapping)); - } - WebType webType = ((Servlet) obj).getWebType(); - if (webType.isJspType()) { - resource = ((IProject) resource).getFile(((JSPType) webType).getJspFile()); //$NON-NLS-1$ - } else if (webType.isServletType()) { - return new WebResource(getModule(resource.getProject(), component), new Path("servlet/" + ((ServletType) webType).getClassName())); //$NON-NLS-1$ - } - } - } - if (resource == null) - return null; - - if (resource instanceof IProject) { - IProject project = (IProject) resource; - if (hasInterestedComponents(project)) - return new WebResource(getModule(project, null), project.getProjectRelativePath()); - } - - if (!hasInterestedComponents(resource.getProject())) - return null; - if (isCactusJunitTest(resource)) - return null; - - IPath rootPath = resource.getProjectRelativePath(); - IPath resourcePath = resource.getFullPath(); - IVirtualResource[] resources = ComponentCore.createResources(resource); - IVirtualComponent component = null; - if (resources[0] != null || resources.length <= 0) - component = resources[0].getComponent(); - String className = getServletClassName(resource); - if (className != null && component != null) { - String mapping = getServletMapping(resource, true, className, component.getName()); - if (mapping != null) { - return new WebResource(getModule(resource.getProject(), component), new Path(mapping)); - } - // if there is no servlet mapping, provide direct access to the servlet - // through the fully qualified class name - return new WebResource(getModule(resource.getProject(), component), new Path("servlet/" + className)); //$NON-NLS-1$ - - } - resourcePath = trim(resourcePath, component.getName()); - resourcePath = trim(resourcePath, WebArtifactEdit.WEB_CONTENT); - // resourcePath = trim(resourcePath,WebArtifactEdit.META_INF); - // resourcePath = trim(resourcePath,WebArtifactEdit.WEB_INF); - - // Extension read to get the correct URL for Java Server Faces file if - // the jsp is of type jsfaces. - FileURL jspURL = FileURLExtensionReader.getInstance().getFilesURL(); - if (jspURL != null) { - IPath correctJSPPath = jspURL.getFileURL(resource, resourcePath); - if (correctJSPPath != null && correctJSPPath.toString().length() > 0) - return new WebResource(getModule(resource.getProject(), component), correctJSPPath); - } - // return Web resource type - return new WebResource(getModule(resource.getProject(), component), resourcePath); - } - - private static IPath trim(IPath resourcePath, String stripValue) { - int x = -1; - String[] segements = resourcePath.segments(); - for (int i = 0; i < segements.length; i++) { - if (segements[i].equals(stripValue)) { - x = ++i; - break; - } - } - if (x > -1) - return resourcePath.removeFirstSegments(x); - return resourcePath; - } - - private static boolean shouldExclude(IResource resource) { - String fileExt = resource.getFileExtension(); - - // Exclude files of certain extensions - for (int i = 0; i < extensionsToExclude.length; i++) { - String extension = extensionsToExclude[i]; - if (extension.equalsIgnoreCase(fileExt)) - return true; - } - return false; - } - - protected static IModule getModule(IProject project, IVirtualComponent component) { - IModule deployable = null; - Iterator iterator = Arrays.asList(ServerUtil.getModules("j2ee.web")).iterator(); - String componentName = null; - if (component != null) - componentName = component.getName(); - else - return getModuleProject(project, iterator); - while (iterator.hasNext()) { - Object next = iterator.next(); - if (next instanceof IModule) { - deployable = (IModule) next; - if (deployable.getName().equals(componentName)) { - return deployable; - } - } - } - return null; - } - - protected static IModule getModuleProject(IProject project, Iterator iterator) { - IModule deployable = null; - while (iterator.hasNext()) { - Object next = iterator.next(); - if (next instanceof IModule) { - deployable = (IModule) next; - if (deployable.getProject().equals(project)) - return deployable; - } - } - return null; - } - - /** - * - * Very temporary api - TODO - rip this out by 1.0 - */ - private static boolean isCactusJunitTest(IResource resource) { - return getClassNameForType(resource, CACTUS_SERVLET_CLASS_TYPE) != null; - } - - - - private static IType[] getTypes(IJavaElement element) { - try { - if (element.getElementType() != IJavaElement.COMPILATION_UNIT) - return null; - - return ((ICompilationUnit) element).getAllTypes(); - } catch (Exception e) { - return null; - } - } - - public static String getServletClassName(IResource resource) { - return getClassNameForType(resource, GENERIC_SERVLET_CLASS_TYPE); - } - - public static String getClassNameForType(IResource resource, String superType) { - if (resource == null) - return null; - - try { - IProject project = resource.getProject(); - IPath path = resource.getFullPath(); - if (!project.hasNature(JavaCore.NATURE_ID) || path == null) - return null; - - IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID); - if (!javaProject.isOpen()) - javaProject.open(new NullProgressMonitor()); - - // output location may not be on classpath - IPath outputPath = javaProject.getOutputLocation(); - if (outputPath != null && "class".equals(path.getFileExtension()) && outputPath.isPrefixOf(path)) { //$NON-NLS-1$ - int count = outputPath.segmentCount(); - path = path.removeFirstSegments(count); - } - - // remove initial part of classpath - IClasspathEntry[] classPathEntry = javaProject.getResolvedClasspath(true); - if (classPathEntry != null) { - int size = classPathEntry.length; - for (int i = 0; i < size; i++) { - IPath classPath = classPathEntry[i].getPath(); - if (classPath.isPrefixOf(path)) { - int count = classPath.segmentCount(); - path = path.removeFirstSegments(count); - i += size; - } - } - } - - // get java element - IJavaElement javaElement = javaProject.findElement(path); - - IType[] types = getTypes(javaElement); - if (types != null) { - int size2 = types.length; - for (int i = 0; i < size2; i++) { - if (hasSuperclass(types[i], superType)) - return types[i].getFullyQualifiedName(); - } - } - return null; - } catch (Exception e) { - return null; - } - } - - public static boolean hasSuperclass(IType type, String superClassName) { - try { - ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null); - IType[] superClasses = hierarchy.getAllSuperclasses(type); - - int size = superClasses.length; - for (int i = 0; i < size; i++) { - if (superClassName.equals(superClasses[i].getFullyQualifiedName())) //$NON-NLS-1$ - return true; - } - return false; - } catch (Exception e) { - return false; - } - } - - - private static boolean isServlet(IType type) { - try { - ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null); - IType[] superClasses = hierarchy.getAllSuperclasses(type); - - int size = superClasses.length; - for (int i = 0; i < size; i++) { - if ("javax.servlet.GenericServlet".equals(superClasses[i].getFullyQualifiedName())) //$NON-NLS-1$ - return true; - } - return false; - } catch (Exception e) { - return false; - } - } - - - public static String getServletMapping(IResource resource, boolean isServlet, String typeName, String componentName) { - if (typeName == null || typeName.equals("")) //$NON-NLS-1$ - return null; - - IProject project = resource.getProject(); - WebArtifactEdit edit = null; - WebApp webApp = null; - try { - ComponentHandle handle = ComponentHandle.create(project,componentName); - edit = WebArtifactEdit.getWebArtifactEditForRead(handle); - edit.getDeploymentDescriptorRoot(); - webApp = edit.getWebApp(); - } finally { - if (edit != null) { - edit.dispose(); - } - } - Object key = new Object(); - try { - if (webApp == null) - return null; - Iterator iterator = webApp.getServlets().iterator(); - while (iterator.hasNext()) { - Servlet servlet = (Servlet) iterator.next(); - boolean valid = false; - - WebType webType = servlet.getWebType(); - if (webType.isServletType() && isServlet) { - ServletType type = (ServletType) webType; - if (typeName.equals(type.getClassName())) - valid = true; - } else if (webType.isJspType() && !isServlet) { - JSPType type = (JSPType) webType; - if (typeName.equals(type.getJspFile())) - valid = true; - } - if (valid) { - java.util.List mappings = servlet.getMappings(); - if (mappings != null && !mappings.isEmpty()) { - ServletMapping map = (ServletMapping) mappings.get(0); - return map.getUrlPattern(); - } - } - } - return null; - } catch (Exception e) { - return null; - } - } - - protected static boolean hasInterestedComponents(IProject project) { - StructureEdit edit = null; - try { - edit = StructureEdit.getStructureEditForWrite(project); - WorkbenchComponent[] components = edit.findComponentsByType("jst.web"); - // WorkbenchComponent[] earComponents = edit.findComponentsByType("jst.ear"); - if (components == null || components.length == 0) // || earComponents != null || - // earComponents.length > 0 - return false; - else - return true; - } catch (Exception e) { - System.out.println(e); - } finally { - edit.dispose(); - } - return false; - } - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployableFactory.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployableFactory.java deleted file mode 100644 index dfa4d221e..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployableFactory.java +++ /dev/null @@ -1,132 +0,0 @@ -/*************************************************************************************************** - * Copyright (c) 2003, 2004 IBM Corporation and others. All rights reserved. This program and the - * accompanying materials are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: IBM Corporation - initial API and implementation - **************************************************************************************************/ -package org.eclipse.jst.j2ee.internal.web.deployables; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.util.EList; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.j2ee.internal.deployables.J2EEDeployableFactory; -import org.eclipse.jst.j2ee.internal.project.IWebNatureConstants; -import org.eclipse.jst.j2ee.internal.project.J2EENature; -import org.eclipse.wst.common.componentcore.internal.ComponentType; -import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent; -import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; -import org.eclipse.wst.server.core.IModule; -import org.eclipse.wst.server.core.IModuleType; -import org.eclipse.wst.server.core.IProjectProperties; -import org.eclipse.wst.server.core.ServerCore; - -public class WebDeployableFactory extends J2EEDeployableFactory { - private static final String ID = "com.ibm.wtp.web.server"; //$NON-NLS-1$ - - protected static final IPath[] PATHS = new IPath[]{new Path(".j2ee") //$NON-NLS-1$ - }; - - public String getFactoryId() { - return ID; - } - - public String getNatureID() { - return IModuleConstants.MODULE_NATURE_ID; - } - - public IModule createModule(J2EENature nature) { - return null; - } - - protected IPath[] getListenerPaths() { - return PATHS; - } - - - protected List createModuleDelegates(EList workBenchModules, IProject project) throws CoreException { - J2EEFlexProjWebDeployable moduleDelegate = null; - IModule module = null; - List moduleList = new ArrayList(workBenchModules.size()); - for (int i = 0; i < workBenchModules.size(); i++) { - try { - WorkbenchComponent wbModule = (WorkbenchComponent) workBenchModules.get(i); - ComponentType type = wbModule.getComponentType(); - if (type == null || !type.getComponentTypeId().equals(J2EEFlexProjWebDeployable.WEB_MODULE_TYPE)) - continue; - moduleDelegate = new J2EEFlexProjWebDeployable(project, ID, wbModule); - module = createModule(wbModule.getName(), wbModule.getName(), moduleDelegate.getType(), moduleDelegate.getVersion(), moduleDelegate.getProject()); - moduleList.add(module); - moduleDelegate.initialize(module); - // adapt(moduleDelegate, (WorkbenchComponent) workBenchModules.get(i)); - } catch (Exception e) { - Logger.getLogger().write(e); - } finally { - if (module != null) { - if (getModuleDelegate(module) == null) - moduleDelegates.add(moduleDelegate); - } - } - } - return moduleList; - - } - - private void adapt(J2EEFlexProjWebDeployable moduleDelegate, WorkbenchComponent wbModule) { - - ModuleAdapter moduleAdapter = new ModuleAdapter() { - public void notifyChanged(Notification msg) { - super.notifyChanged(msg); - } - }; - moduleAdapter.setTarget(wbModule); - moduleAdapter.setModuleDelegate(moduleDelegate); - wbModule.eAdapters().add(moduleAdapter); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.server.core.model.ModuleFactoryDelegate#getModules() - */ - public IModule[] getModules() { - cacheModules(false); - ArrayList moduleList = new ArrayList(); - for (Iterator iter = projects.values().iterator(); iter.hasNext();) { - IModule[] element = (IModule[]) iter.next(); - for (int j = 0; j < element.length; j++) { - moduleList.add(element[j]); - } - } - IModule[] modules = new IModule[moduleList.size()]; - moduleList.toArray(modules); - return modules; - - } - - protected boolean isValidModule(IProject project) { - if (isFlexableProject(project)) { - IProjectProperties properties = ServerCore.getProjectProperties(project); - if (properties != null || properties.getRuntimeTarget() == null || properties.getRuntimeTarget().getRuntimeType().getModuleTypes() != null) { - IModuleType[] moduleTypes = properties.getRuntimeTarget().getRuntimeType().getModuleTypes(); - for (int i = 0; i < moduleTypes.length; i++) { - IModuleType moduleType = moduleTypes[i]; - if (moduleType.getId().equals("j2ee.web")) - return true; - } - - } - - } - return false; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebModuleArtifact.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebModuleArtifact.java deleted file mode 100644 index 1c998db2d..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebModuleArtifact.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Created on Feb 21, 2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.eclipse.jst.j2ee.internal.web.deployables; - -/** - * Key Class for adapter manager - */ -public class WebModuleArtifact { - -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURL.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURL.java deleted file mode 100644 index 777e92514..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURL.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Jun 13, 2004 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.eclipse.jst.j2ee.internal.web.jfaces.extension; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; - - -/** - * @author vijayb - * - * TODO To change the template for this generated type comment go to Window - Preferences - Java - - * Code Style - Code Templates - */ -public interface FileURL { - public IPath getFileURL(IResource resource, IPath existingURL); -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURLExtension.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURLExtension.java deleted file mode 100644 index be20ed88c..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURLExtension.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Jun 13, 2004 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.eclipse.jst.j2ee.internal.web.jfaces.extension; - -import org.eclipse.core.internal.runtime.Assert; -import org.eclipse.core.runtime.IConfigurationElement; - -import org.eclipse.jem.util.logger.proxy.Logger; - -/** - * @author vijayb - * - * TODO To change the template for this generated type comment go to Window - Preferences - Java - - * Code Style - Code Templates - */ -public class FileURLExtension { - private String id = null; - private FileURL instance; - private boolean errorCondition = false; - private IConfigurationElement element; - public static final String FILE_URL_EXTENSION = "fileURL"; //$NON-NLS-1$ - public static final String RUN = "run"; //$NON-NLS-1$ - public static final String ATT_ID = "id"; //$NON-NLS-1$ - public static final String ATT_CLASS = "class"; //$NON-NLS-1$ - - - /** - * - */ - public FileURLExtension() { - super(); - } - - public FileURL getInstance() { - try { - if (this.instance == null && !this.errorCondition) - this.instance = (FileURL) this.element.createExecutableExtension("run"); //$NON-NLS-1$ - } catch (Throwable e) { - Logger.getLogger().logError(e); - this.errorCondition = true; - } - return this.instance; - } - - public FileURLExtension(IConfigurationElement element) { - Assert.isLegal(FILE_URL_EXTENSION.equals(element.getName()), "Extensions must be of the type \"" + FILE_URL_EXTENSION + "\"."); //$NON-NLS-1$ //$NON-NLS-2$ - this.element = element; - init(); - } - - private void init() { - this.id = this.element.getAttribute(ATT_ID); - - } - - /** - * @return Returns the id. - */ - public String getId() { - return this.id; - } - - /** - * @param id - * The id to set. - */ - public void setId(String id) { - this.id = id; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURLExtensionReader.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURLExtensionReader.java deleted file mode 100644 index acdcc7e18..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURLExtensionReader.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Jun 13, 2004 - */ -package org.eclipse.jst.j2ee.internal.web.jfaces.extension; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.jem.util.RegistryReader; -import org.eclipse.jst.j2ee.internal.web.plugin.WebPlugin; - -/** - * @author vijayb - * - * This class loads all the extensions that define the correct URL string for the Java Server Faces - * file - * - */ -public class FileURLExtensionReader extends RegistryReader { - static FileURLExtensionReader instance = null; - protected List fileURLExtensions; - - /** - * @param registry - * @param pluginID - * @param extensionPoint - */ - public FileURLExtensionReader() { - super(WebPlugin.PLUGIN_ID, "fileURL"); //$NON-NLS-1$ - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.frameworks.internal.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement) - */ - public boolean readElement(IConfigurationElement element) { - if (FileURLExtension.FILE_URL_EXTENSION.equals(element.getName())) { - addExtension(element); - return true; - } - return false; - } - - /** - * Sets the extension point. - * - * @param extensions - * The extensions to set - */ - protected void addExtension(IConfigurationElement newExtension) { - getFileURLExtensions().add(new FileURLExtension(newExtension)); - } - - /** - * Sets the extension point. - * - * @param extensions - * The extensions to set - */ - protected void addExtensionPoint(FileURLExtensionReader newExtension) { - if (this.fileURLExtensions == null) - this.fileURLExtensions = new ArrayList(); - this.fileURLExtensions.add(newExtension); - } - - /** - * @return the appropriate handler for the project based on priorities of those which are - * available and enabled - */ - public FileURL getFilesURL() { - FileURLExtension fileURLExt; - for (Iterator fileURLExtItr = getFileURLExtensions().iterator(); fileURLExtItr.hasNext();) { - fileURLExt = (FileURLExtension) fileURLExtItr.next(); - return fileURLExt.getInstance(); - } - return null; - } - - /** - * Gets the instance. - * - * @return Returns a FileURLExtensionReader - */ - public static FileURLExtensionReader getInstance() { - if (instance == null) { - instance = new FileURLExtensionReader(); - instance.readRegistry(); - } - return instance; - } - - /** - * @return Returns the handlerExtensions. - */ - protected List getFileURLExtensions() { - if (this.fileURLExtensions == null) - this.fileURLExtensions = new ArrayList(); - return this.fileURLExtensions; - } - - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/migration/WebProjectMigratorStrategy.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/migration/WebProjectMigratorStrategy.java deleted file mode 100644 index 4fdec8b60..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/migration/WebProjectMigratorStrategy.java +++ /dev/null @@ -1,227 +0,0 @@ -package org.eclipse.jst.j2ee.internal.web.migration; - -import java.util.ArrayList; - -import org.eclipse.core.internal.resources.Container; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; -import org.eclipse.jst.j2ee.internal.J2EEVersionUtil; -import org.eclipse.jst.j2ee.internal.project.IWebNatureConstants; -import org.eclipse.jst.j2ee.internal.web.operations.OldWebSettingsForMigration; -import org.eclipse.wst.common.componentcore.internal.ComponentcoreFactory; -import org.eclipse.wst.common.componentcore.internal.DependencyType; -import org.eclipse.wst.common.componentcore.internal.Property; -import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; -import org.eclipse.wst.common.internal.migration.IMigratorStrategy; - - - -public class WebProjectMigratorStrategy implements IMigratorStrategy { - - protected IProject project; - protected static String JAVA_SOURCE = "JavaSource"; - protected static String CONTEXT_ROOT = "ContextRoot"; - protected static String JSP_LEVEL = "JSPLevel"; - protected static String FEATURE_ID = "FeatureID"; - protected static String JAVA_SOURCE_DEPLOY_PATH_NAME = "/WEB-INF/classes"; - protected static String WEB_DEPLOYMENT_DESCRIPTOR_PATH = "/WEB-INF/web.xml"; - - protected OldWebSettingsForMigration fWebSettings; - int fVersion; - - - - public IJavaProject getJavaProject() { - IJavaProject javaProject = JavaCore.create(project); - return javaProject; - } - - public IPackageFragmentRoot[] getPackageRoots() { - try { - return getJavaProject().getAllPackageFragmentRoots(); - } catch (JavaModelException e) { - e.printStackTrace(); - } - return null; - - } - - public IResource[] getResources(String componentName, int type) { - IResource[] resources = null; - switch (type) { - case IMigratorStrategy.SOURCE : { - IPackageFragmentRoot[] roots = getPackageRoots(); - ArrayList sourceFolders = new ArrayList(roots.length); - for (int i = 0; i < roots.length; i++) { - IResource packageResource; - try { - packageResource = (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) ? roots[i].getCorrespondingResource() : null; - if (packageResource != null && packageResource.getType() == IResource.FOLDER) - sourceFolders.add(packageResource); - } catch (JavaModelException e) { - e.printStackTrace(); - } - } - resources = new Container[sourceFolders.size()]; - sourceFolders.toArray(resources); - break; - } - case IMigratorStrategy.CONTENT : { - resources = new Container[1]; - Container webContent = (Container) project.getFolder(getBasicWebModulePath()); - if (webContent != null) - resources[0] = webContent; - break; - } - } - return resources; - } - - public OldWebSettingsForMigration getWebSettings() { - if (fWebSettings == null) { - fWebSettings = new OldWebSettingsForMigration(getProject()); - } - return fWebSettings; - } - - public IPath getRuntimeType(IResource resource, int type) { - if (resource.getName().equals(JAVA_SOURCE)) - return (new Path(JAVA_SOURCE_DEPLOY_PATH_NAME)); - return new Path("/"); - } - - public String[] getComponentNames() { - return new String[]{project.getName()}; - } - - - public void setCurrentProject(IProject aProject) { - project = aProject; - } - - public IProject getProject() { - return project; - } - - public IPath getBasicWebModulePath() { - OldWebSettingsForMigration webSettings = getWebSettings(); - String name = webSettings.getWebContentName(); - if (name == null) { - int version = getVersion(); - // If created in V5 or beyond - if (version != -1 && version >= 500) - return IWebNatureConstants.WEB_MODULE_PATH_; - return IWebNatureConstants.WEB_MODULE_PATH_V4; - } - return new Path(name); - } - - public int getVersion() { - if (fVersion == -1) { - try { - String versionString = getWebSettings().getVersion(); - if (versionString != null) - fVersion = Integer.parseInt(versionString); - } catch (NumberFormatException e) { - //Ignore - } - } - return fVersion; - } - - - public IResource[] getExcludedResources(String componentName, int type) { - return null; - } - - public String getComponentTypeName(String componentName) { - return IModuleConstants.JST_WEB_MODULE; - } - - public String getComponetTypeVersion(String componentName) { - return J2EEVersionUtil.getJ2EETextVersion(getJ2EEVersion()); - } - - public Property[] getProperties(String componentName) { - String contextRootName = getWebSettings().getContextRoot(); - String jspLevel = getWebSettings().getJSPLevel(); - String[] featureIDs = getWebSettings().getFeatureIds(); - Property[] properties = new Property[featureIDs.length + 2]; - properties[0] = createProperty(CONTEXT_ROOT, contextRootName); - properties[1] = createProperty(JSP_LEVEL, jspLevel); - for (int i = 2; i < featureIDs.length + 2; i++) { - properties[i] = createProperty(FEATURE_ID + "_" + (i - 1), featureIDs[i - 2]); - - } - return properties; - } - - public Property createProperty(String name, String value) { - Property property = ComponentcoreFactory.eINSTANCE.createProperty(); - property.setName(name); - property.setValue(value); - return property; - } - - - public int getJ2EEVersion() { - int j2eeVersion; - switch (getModuleVersion()) { - case J2EEVersionConstants.WEB_2_2_ID : - j2eeVersion = J2EEVersionConstants.J2EE_1_2_ID; - break; - case J2EEVersionConstants.WEB_2_3_ID : - j2eeVersion = J2EEVersionConstants.J2EE_1_3_ID; - break; - case J2EEVersionConstants.WEB_2_4_ID : - j2eeVersion = J2EEVersionConstants.WEB_2_4_ID; - default : - j2eeVersion = J2EEVersionConstants.J2EE_1_4_ID; - } - return j2eeVersion; - } - - - private int getModuleVersion() { - return getWebSettings().getModuleVersion(); - } - - public void postMigrateStrategy() { - //Default - } - - - public boolean hasReferencedComponent(String componentName) { - return false; - } - - - public String[] getReferencedComponentNames(String componentName) { - return null; - } - - - public DependencyType getDependancyType(String referencedComponentName, String componentName) { - return null; - } - - - public IPath getReferencedComponentHandleURI(String referencedComponentName, String componentName) { - return null; - } - - public IPath getReferencedComponentRuntimeType(String referencedComponentName, String componentName) { - return null; - } - - public IProject[] getRequiredProjectsForMigration() { - return null; - } -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/AddServletOperation.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/AddServletOperation.java deleted file mode 100644 index 4de3a2256..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/AddServletOperation.java +++ /dev/null @@ -1,284 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.web.operations; - -import java.lang.reflect.InvocationTargetException; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.j2ee.application.internal.operations.IAnnotationsDataModel; -import org.eclipse.jst.j2ee.common.CommonFactory; -import org.eclipse.jst.j2ee.common.Description; -import org.eclipse.jst.j2ee.common.ParamValue; -import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; -import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModel; -import org.eclipse.jst.j2ee.webapplication.InitParam; -import org.eclipse.jst.j2ee.webapplication.JSPType; -import org.eclipse.jst.j2ee.webapplication.Servlet; -import org.eclipse.jst.j2ee.webapplication.ServletMapping; -import org.eclipse.jst.j2ee.webapplication.ServletType; -import org.eclipse.jst.j2ee.webapplication.WebApp; -import org.eclipse.jst.j2ee.webapplication.WebapplicationFactory; -import org.eclipse.wst.common.componentcore.internal.operation.ArtifactEditOperation; - -/** - * This class, AddServlet Operation is a WTPOperation following the WTP wizard data model and - * operation framework. - * @see org.eclipse.wst.common.frameworks.internal.operations.WTPOperation - * @see org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel - * - * This operation subclasses the EditModelOperation so the changes made to the deployment descriptor - * models are saved to the edit model. - * @see org.eclipse.wst.common.internal.emfworkbench.operation.EditModelOperation - * - * It is the operation which should be used when adding a new servlet to - * a web app, whether that be an annotated servlet or a non annotated servlet. This uses the - * NewServletClassDataModel to retrieve properties set by the user in order to create the custom - * servet. - * @see org.eclipse.jst.j2ee.internal.web.operations.NewServletClassDataModel - * - * In the non annotated case, this operation will add the metadata necessary into the web deployment - * descriptor. In the annotated case, it will not, it will leave this up to the parsing of the - * annotations to build the deployment descriptor artifacts. To actually create the java class for - * the servlet, the operation uses the NewServletClassOperation. The NewServletClassOperation - * shares the same data model. - * @see org.eclipse.jst.j2ee.internal.web.operations.NewServletClassOperation - * - * Clients may subclass this operation to provide their own behaviour on servlet creation. The execute - * method can be extended to do so. Also, generateServletMetaData and creteServletClass are exposed. - * - * The use of this class is EXPERIMENTAL and is subject to substantial changes. - */ -public class AddServletOperation extends ArtifactEditOperation { - - /** - * This is the constructor which should be used when creating the operation. - * It will not accept null parameter. It will not return null. - * @see WTPOperation#WTPOperation(WTPOperationDataModel) - * - * @param dataModel NewServletClassDataModel - * @return AddServletOperation - */ - public AddServletOperation(NewServletClassDataModel dataModel) { - super(dataModel); - } - - /** - * Subclasses may extend this method to add their own actions during execution. - * The implementation of the execute method drives the running of the operation. This - * implementation will create the servlet class, and then if the servlet is not - * annotated, it will create the servlet metadata for the web deployment descriptor. - * This method will accept null as a parameter. - * @see org.eclipse.wst.common.frameworks.internal.operations.WTPOperation#execute(IProgressMonitor) - * @see AddServletOperation#createServletClass() - * @see AddServletOperation#generateServletMetaData(NewServletClassDataModel, String, boolean) - * - * @param monitor IProgressMonitor - * @throws CoreException - * @throws InterruptedException - * @throws InvocationTargetException - */ - protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { - //Retrieve values set in the newservletclass data model - NewServletClassDataModel model = (NewServletClassDataModel) operationDataModel; - boolean isServletType = model.getBooleanProperty(NewServletClassDataModel.IS_SERVLET_TYPE); - String qualifiedClassName = model.getStringProperty(NewJavaClassDataModel.CLASS_NAME); - - // If it is servlet type, create the java class - if (isServletType) - qualifiedClassName = createServletClass(); - - // If the servlet is not annotated, generate the servlet metadata for the DD - if (!model.getBooleanProperty(IAnnotationsDataModel.USE_ANNOTATIONS)) - generateServletMetaData(model, qualifiedClassName, isServletType); - } - - /** - * Subclasses may extend this method to add their own creation of the actual servlet java class. - * This implementation uses the NewServletClassOperation which is a subclass of the NewJavaClassOperation. - * The NewServletClassOperation will use the same NewServletClassDataModel to retrieve the properties in - * order to create the java class accordingly. This method will not return null. - * @see NewServletClassOperation - * @see org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassOperation - * @see NewServletClassDataModel - * - * @return String qualified servlet classname - */ - protected String createServletClass() { - // Create servlet java class file using the NewServletClassOperation. The same data model is shared. - NewServletClassDataModel model = (NewServletClassDataModel) operationDataModel; - NewServletClassOperation op = new NewServletClassOperation(model); - try { - op.run(null); - } catch (InvocationTargetException e) { - Logger.getLogger().log(e); - } catch (InterruptedException e) { - Logger.getLogger().log(e); - } - // Return the qualified classname of the newly created java class for the servlet - return model.getQualifiedClassName(); - } - - /** - * Subclasses may extend this method to add their own generation steps for the creation of the - * metadata for the web deployment descriptor. This implementation uses the J2EE models to create - * the Servlet model instance, any init params specified, and any servlet mappings. It then adds - * these to the web application model. This will then be written out to the deployment descriptor - * file. This method does not accept null parameters. - * @see Servlet - * @see AddServletOperation#createServlet(String, boolean) - * @see AddServletOperation#setUpInitParams(List, Servlet) - * @see AddServletOperation#setUpURLMappings(List, Servlet) - * - * @param model - * @param qualifiedClassName - * @param isServletType - */ - protected void generateServletMetaData(NewServletClassDataModel model, String qualifiedClassName, boolean isServletType) { - // Set up the servlet modelled object - Servlet servlet = createServlet(qualifiedClassName, isServletType); - - // Set up the InitParams if any - List initParamList = (List) model.getProperty(NewServletClassDataModel.INIT_PARAM); - if (initParamList != null) - setUpInitParams(initParamList,servlet); - - // Set up the servlet URL mappings if any - List urlMappingList = (List) model.getProperty(NewServletClassDataModel.URL_MAPPINGS); - if (urlMappingList != null) - setUpURLMappings(urlMappingList, servlet); - } - - /** - * This method is intended for private use only. This method is used to create the servlet - * modelled object, to set any parameters specified in the data model, and then to add the - * servlet instance to the web application model. This method does not accpet null parameters. - * It will not return null. - * @see AddServletOperation#generateServletMetaData(NewServletClassDataModel, String, boolean) - * @see WebapplicationFactory#createServlet() - * @see Servlet - * - * @param qualifiedClassName - * @param isServletType - * @return Servlet instance - */ - private Servlet createServlet(String qualifiedClassName, boolean isServletType) { - // Get values from data model - NewServletClassDataModel model = (NewServletClassDataModel) this.operationDataModel; - String displayName = model.getStringProperty(NewServletClassDataModel.DISPLAY_NAME); - String description = model.getStringProperty(NewServletClassDataModel.DESCRIPTION); - - // Create the servlet instance and set up the parameters from data model - Servlet servlet = WebapplicationFactory.eINSTANCE.createServlet(); - servlet.setDisplayName(displayName); - servlet.setServletName(displayName); - servlet.setDescription(description); - // Handle servlet case - if (isServletType) { - ServletType servletType = WebapplicationFactory.eINSTANCE.createServletType(); - servletType.setClassName(qualifiedClassName); - servlet.setWebType(servletType); - } - // Handle JSP case - else { - JSPType jspType = WebapplicationFactory.eINSTANCE.createJSPType(); - jspType.setJspFile(qualifiedClassName); - servlet.setWebType(jspType); - } - // Add the servlet to the web application model - WebApp webApp = (WebApp) getArtifactEdit().getContentModelRoot(); - webApp.getServlets().add(servlet); - // Return the servlet instance - return servlet; - } - - /** - * This method is intended for internal use only. This is used to create any init params - * for the new servlet metadata. It will not accept null parameters. The init params are - * set on the servlet modelled object. - * @see AddServletOperation#generateServletMetaData(NewServletClassDataModel, String, boolean) - * @see WebapplicationFactory#createInitParam() - * - * @param initParamList - * @param servlet - */ - private void setUpInitParams(List initParamList, Servlet servlet) { - // Get the web app instance from the data model - WebApp webApp = (WebApp) getArtifactEdit().getContentModelRoot(); - int nP = initParamList.size(); - // If J2EE 1.4, add the param value and description info instances to the servlet init params - if (webApp.getJ2EEVersionID() >= J2EEVersionConstants.J2EE_1_4_ID) { - for (int iP = 0; iP < nP; iP++) { - String[] stringArray = (String[]) initParamList.get(iP); - // Create 1.4 common param value - ParamValue param = CommonFactory.eINSTANCE.createParamValue(); - param.setName(stringArray[0]); - param.setValue(stringArray[1]); - // Create 1.4 common descripton value - Description descriptionObj = CommonFactory.eINSTANCE.createDescription(); - descriptionObj.setValue(stringArray[2]); - // Set the description on the param - param.getDescriptions().add(descriptionObj); - param.setDescription(stringArray[2]); - // Add the param to the servlet model list of init params - servlet.getInitParams().add(param); - } - } - // If J2EE 1.2 or 1.3, use the servlet specific init param instances - else { - for (int iP = 0; iP < nP; iP++) { - String[] stringArray = (String[]) initParamList.get(iP); - // Create the web init param - InitParam ip = WebapplicationFactory.eINSTANCE.createInitParam(); - // Set the param name - ip.setParamName(stringArray[0]); - // Set the param value - ip.setParamValue(stringArray[1]); - // Set the param description - ip.setDescription(stringArray[2]); - // Add the init param to the servlet model list of params - servlet.getParams().add(ip); - } - } - } - - /** - * This method is intended for internal use only. This method is used to create the servlet - * mapping modelled objects so the metadata for the servlet mappings is store in the web - * deployment descriptor. This method will not accept null parameters. The servlet mappings - * are added to the web application modelled object. - * @see AddServletOperation#generateServletMetaData(NewServletClassDataModel, String, boolean) - * @see WebapplicationFactory#createServletMapping() - * - * @param urlMappingList - * @param servlet - */ - private void setUpURLMappings(List urlMappingList, Servlet servlet) { - // Get the web app modelled object from the data model - WebApp webApp = (WebApp) getArtifactEdit().getContentModelRoot(); - int nM = urlMappingList.size(); - // Create the servlet mappings if any - for (int iM = 0; iM < nM; iM++) { - String[] stringArray = (String[]) urlMappingList.get(iM); - // Create the servlet mapping instance from the web factory - ServletMapping mapping = WebapplicationFactory.eINSTANCE.createServletMapping(); - // Set the servlet and servlet name - mapping.setServlet(servlet); - mapping.setName(servlet.getServletName()); - // Set the URL pattern to map the servlet to - mapping.setUrlPattern(stringArray[0]); - // Add the servlet mapping to the web application modelled list - webApp.getServletMappings().add(mapping); - } - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/CreateServletTemplateModel.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/CreateServletTemplateModel.java deleted file mode 100644 index ee99e6897..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/CreateServletTemplateModel.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Aug 6, 2004 - */ -package org.eclipse.jst.j2ee.internal.web.operations; - -import java.util.List; - -import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModel; - - -/** - * @author jlanuti - */ -public class CreateServletTemplateModel { - - NewServletClassDataModel dataModel = null; - public static final String INIT = "init"; //$NON-NLS-1$ - public static final String TO_STRING = "toString"; //$NON-NLS-1$ - public static final String GET_SERVLET_INFO = "getServletInfo"; //$NON-NLS-1$ - public static final String DO_POST = "doPost"; //$NON-NLS-1$ - public static final String DO_PUT = "doPut"; //$NON-NLS-1$ - public static final String DO_DELETE = "doDelete"; //$NON-NLS-1$ - public static final String DESTROY = "destroy"; //$NON-NLS-1$ - public static final String DO_GET = "doGet"; //$NON-NLS-1$ - - public static final int NAME = 0; - public static final int VALUE = 1; - public static final int DESCRIPTION = 2; - - /** - * Constructor - */ - public CreateServletTemplateModel(NewServletClassDataModel dataModel) { - super(); - this.dataModel = dataModel; - } - - public String getServletClassName() { - return getProperty(NewJavaClassDataModel.CLASS_NAME); - } - - public String getJavaPackageName() { - return getProperty(NewJavaClassDataModel.JAVA_PACKAGE); - } - - public String getQualifiedJavaClassName() { - return getJavaPackageName() + "." + getServletClassName(); //$NON-NLS-1$ - } - - public String getSuperclassName() { - return getProperty(NewJavaClassDataModel.SUPERCLASS); - } - - public String getServletName() { - return getProperty(NewJavaClassDataModel.CLASS_NAME); - } - - public boolean isPublic() { - return this.dataModel.getBooleanProperty(NewJavaClassDataModel.MODIFIER_PUBLIC); - } - - public boolean isFinal() { - return this.dataModel.getBooleanProperty(NewJavaClassDataModel.MODIFIER_FINAL); - } - - public boolean isAbstract() { - return this.dataModel.getBooleanProperty(NewJavaClassDataModel.MODIFIER_ABSTRACT); - } - - protected String getProperty(String propertyName) { - return this.dataModel.getStringProperty(propertyName); - } - - public boolean shouldGenInit() { - return implementImplementedMethod(INIT); - } - - public boolean shouldGenToString() { - return implementImplementedMethod(TO_STRING); - } - - public boolean shouldGenGetServletInfo() { - return implementImplementedMethod(GET_SERVLET_INFO); - } - - public boolean shouldGenDoPost() { - return implementImplementedMethod(DO_POST); - } - - public boolean shouldGenDoPut() { - return implementImplementedMethod(DO_PUT); - } - - public boolean shouldGenDoDelete() { - return implementImplementedMethod(DO_DELETE); - } - - public boolean shouldGenDestroy() { - return implementImplementedMethod(DESTROY); - } - - public boolean shouldGenDoGet() { - return implementImplementedMethod(DO_GET); - } - - public List getInitParams() { - return (List) dataModel.getProperty(NewServletClassDataModel.INIT_PARAM); - } - - public String getInitParam(int index, int type) { - List params = getInitParams(); - if (index < params.size()) { - String[] stringArray = (String[]) params.get(index); - return stringArray[type]; - } - return null; - } - - public List getServletMappings() { - return (List) dataModel.getProperty(NewServletClassDataModel.URL_MAPPINGS); - } - - public String getServletMapping(int index) { - List mappings = getServletMappings(); - if (index < mappings.size()) { - String[] map = (String[]) mappings.get(index); - return map[0]; - } - return null; - } - - public String getServletDescription() { - return dataModel.getStringProperty(NewServletClassDataModel.DESCRIPTION); - } - - public List getInterfaces() { - return (List) this.dataModel.getProperty(NewJavaClassDataModel.INTERFACES); - } - - protected boolean implementImplementedMethod(String methodName) { - if (methodName.equals(INIT)) - return dataModel.getBooleanProperty(NewServletClassDataModel.INIT); - else if (methodName.equals(TO_STRING)) - return dataModel.getBooleanProperty(NewServletClassDataModel.TO_STRING); - else if (methodName.equals(GET_SERVLET_INFO)) - return dataModel.getBooleanProperty(NewServletClassDataModel.GET_SERVLET_INFO); - else if (methodName.equals(DO_POST)) - return dataModel.getBooleanProperty(NewServletClassDataModel.DO_POST); - else if (methodName.equals(DO_PUT)) - return dataModel.getBooleanProperty(NewServletClassDataModel.DO_PUT); - else if (methodName.equals(DO_DELETE)) - return dataModel.getBooleanProperty(NewServletClassDataModel.DO_DELETE); - else if (methodName.equals(DESTROY)) - return dataModel.getBooleanProperty(NewServletClassDataModel.DESTROY); - else if (methodName.equals(DO_GET)) - return dataModel.getBooleanProperty(NewServletClassDataModel.DO_GET); - else - return false; - } - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassDataModel.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassDataModel.java deleted file mode 100644 index 651b5643e..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassDataModel.java +++ /dev/null @@ -1,625 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.internal.web.operations; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jem.util.emf.workbench.JavaProjectUtilities; -import org.eclipse.jst.j2ee.application.internal.operations.IAnnotationsDataModel; -import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; -import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModel; -import org.eclipse.jst.j2ee.internal.web.operations.WebPropertiesUtil; -import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit; -import org.eclipse.jst.j2ee.webapplication.Servlet; -import org.eclipse.jst.j2ee.webapplication.WebApp; -import org.eclipse.wst.common.componentcore.ArtifactEdit; -import org.eclipse.wst.common.componentcore.resources.ComponentHandle; -import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; - -/** - * The NewServletClassData model is a subclass of WTPOperationDataModel and follows the WTP Operation and WTP Wizard frameworks. - * @see org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel - * @see org.eclipse.wst.common.frameworks.internal.operations.WTPOperation - * - * This data model is a subclass of the NewJavaClassDataModel, which stores base properties necessary in - * the creation of a default java class. - * @see org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModel - * - * The NewServletClassDataModel provides more specific properties for java class creation that are required - * in creating a servlet java class. The data model is used to store these values for the NewServletClassOperation. - * That operation will create the servlet java class based on the settings defined here in the data model. - * @see org.eclipse.jst.j2ee.internal.web.operations.NewServletClassOperation - * - * This data model implements the IAnnotationsDataModel to get the USE_ANNOTATIONS property for determining - * whether or not to generate an annotated java class. - * @see org.eclipse.jst.j2ee.application.internal.operations.IAnnotationsDataModel - * - * Clients can subclass this data model to cache and provide their own specific attributes. They should also provide their - * own validation methods and default values for the properties they add. - * - * The use of this class is EXPERIMENTAL and is subject to substantial changes. - */ -public class NewServletClassDataModel extends NewJavaClassDataModel implements IAnnotationsDataModel { - - /** - * Optional, boolean property used to specify whether to generate the init method. - * The default is false. - */ - public static final String INIT = "NewServletClassDataModel.INIT"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the doPost method. - * The default is true. - */ - public static final String DO_POST = "NewServletClassDataModel.DO_POST"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the destroy method. - * The default is false. - */ - public static final String DESTROY = "NewServletClassDataModel.DESTROY"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the toString method. - * The default is false. - */ - public static final String TO_STRING = "NewServletClassDataModel.TO_STRING"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the doPut method. - * The default is false. - */ - public static final String DO_PUT = "NewServletClassDataModel.DO_PUT"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the doGet method. - * The default is true. - */ - public static final String DO_GET = "NewServletClassDataModel.DO_GET"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the getServletInfo method. - * The default is false. - */ - public static final String GET_SERVLET_INFO = "NewServletClassDataModel.GET_SERVLET_INFO"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the doDelete method. - * The default is false. - */ - public static final String DO_DELETE = "NewServletClassDataModel.DO_DELETE"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to determine if building JSP or servlet. - * The default is true. - */ - public static final String IS_SERVLET_TYPE = "NewServletClassDataModel.IS_SERVLET_TYPE"; //$NON-NLS-1$ - - /** - * Optional, List property used to cache all the init params defined on the servlet. - */ - public static final String INIT_PARAM = "NewServletClassDataModel.INIT_PARAM"; //$NON-NLS-1$ - - /** - * Optional, List propety used to cache all the servlet mappings for this servlet on the web application. - */ - public static final String URL_MAPPINGS = "NewServletClassDataModel.URL_MAPPINGS"; //$NON-NLS-1$ - - /** - * Required, String property of the display name for the servlet - */ - public static final String DISPLAY_NAME = "NewServletClassDataModel.DISPLAY_NAME"; //$NON-NLS-1$ - - /** - * Optional, String property of the description info for the servlet - */ - public static final String DESCRIPTION = "NewServletClassDataModel.DESCRIPTION"; //$NON-NLS-1$ - - /** - * The fully qualified default servlet superclass: HttpServlet. - */ - public final static String SERVLET_SUPERCLASS = "javax.servlet.http.HttpServlet"; //$NON-NLS-1$ - - /** - * String array of the default, minimum required fully qualified Servlet interfaces - */ - public final static String[] SERVLET_INTERFACES = {"javax.servlet.Servlet"}; //$NON-NLS-1$ - - /** - * The javajet template file used in creating the servlet template class - */ - public static final String TEMPLATE_FILE = "servletXDoclet.javajet"; //$NON-NLS-1$ - - public static final String NON_ANNOTATED_TEMPLATE_FILE = "servletXDocletNonAnnotated.javajet"; //$NON-NLS-1$ - /** - * The cache of all the interfaces the servlet java class will implement. - */ - private List interfaceList; - - private static boolean useAnnotations = true; - - /** - * Subclasses may extend this method to provide their own default operation for this - * data model. This implementation uses the AddServletOperation to drive the servlet - * creation. It will not return null. - * @see org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel#getDefaultOperation() - * - * @return WTPOperation AddServletOperation - */ - public WTPOperation getDefaultOperation() { - return new AddServletOperation(this); - } - - /** - * Subclasses may extend this method to provide their own determination of whether or not - * certain properties should be disabled or enabled. This method does not accept null parameter. - * It will not return null. This implementation makes sure annotation support is only allowed - * on web projects of J2EE version 1.3 or higher. - * @see org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel#basicIsEnabled(String) - * @see IAnnotationsDataModel#USE_ANNOTATIONS - * - * @param propertyName - * @return Boolean should property be enabled? - */ - protected Boolean basicIsEnabled(String propertyName) { - // Annotations should only be enabled on a valid j2ee project of version 1.3 or higher - if (USE_ANNOTATIONS.equals(propertyName)) { - if (!isAnnotationsSupported()) - return Boolean.FALSE; - return Boolean.TRUE; - } - // Otherwise return super implementation - return super.basicIsEnabled(propertyName); - } - - /** - * Subclasses may extend this method to add their own specific data model properties as valid - * base properties. This implementation adds the servlet specific properties to those added - * by the NewJavaClassDataModel. - * @see NewJavaClassDataModel#initValidBaseProperties() - * @see org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel#initValidBaseProperties() - */ - protected void initValidBaseProperties() { - super.initValidBaseProperties(); - // Add servlet specific properties defined in this data model - addValidBaseProperty(INIT); - addValidBaseProperty(DO_POST); - addValidBaseProperty(DESTROY); - addValidBaseProperty(TO_STRING); - addValidBaseProperty(DO_PUT); - addValidBaseProperty(DO_GET); - addValidBaseProperty(GET_SERVLET_INFO); - addValidBaseProperty(DO_DELETE); - addValidBaseProperty(IS_SERVLET_TYPE); - addValidBaseProperty(INIT_PARAM); - addValidBaseProperty(URL_MAPPINGS); - addValidBaseProperty(USE_ANNOTATIONS); - addValidBaseProperty(DISPLAY_NAME); - addValidBaseProperty(DESCRIPTION); - } - - /** - * Subclasses may extend this method to provide their own default values for - * any of the properties in the data model hierarchy. This method does not - * accept a null parameter. It may return null. This implementation sets - * annotation use to be true, and to generate a servlet with doGet and doPost. - * @see NewJavaClassDataModel#getDefaultProperty(String) - * @see org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel#getDefaultProperty(String) - * - * @param propertyName - * @return Object default value of property - */ - protected Object getDefaultProperty(String propertyName) { - // Generate a doPost method by default - if (propertyName.equals(DO_POST)) - return new Boolean(true); - // Generate a doGet method by default - else if (propertyName.equals(DO_GET)) - return new Boolean(true); - // Use servlet by default - else if (propertyName.equals(IS_SERVLET_TYPE)) - return new Boolean(true); - // Create an annotated servlet java class by default - else if (propertyName.equals(USE_ANNOTATIONS)) - return shouldDefaultAnnotations(); - else if (propertyName.equals(DISPLAY_NAME)) - return getProperty(CLASS_NAME); - else if (propertyName.equals(URL_MAPPINGS)) { - return getDefaultUrlMapping(); - } - // Otherwise check super for default value for property - return super.getDefaultProperty(propertyName); - } - - /** - * Returns the default Url Mapping depending upon the display name of - * the Servlet - * @return List containting the default Url Mapping - */ - private Object getDefaultUrlMapping() { - List urlMappings = null; - String text = (String)getProperty(DISPLAY_NAME); - if (text != null) { - urlMappings = new ArrayList(); - urlMappings.add(new String[]{"/" + text}); //$NON-NLS-1$ - } - return urlMappings; - } - - /** - * Subclasses may extend this method to add their own specific behaviour when a certain - * property in the data model heirarchy is set. This method does not accept null for - * the property name, but it will for propertyValue. It will not return null. It will return - * false if the set fails. This implementation verifies the display name is set to the - * classname, that the annotations is disabled/enabled properly, and that the target project - * name is determined from the source folder setting. - * @see org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel#doSetProperty(String, Object) - * - * @param propertyName - * @param propertyValue - * @return boolean was property set? - */ - protected boolean doSetProperty(String propertyName, Object propertyValue) { - - // If annotations is changed, notify an enablement change - if (propertyName.equals(USE_ANNOTATIONS)) { - useAnnotations = ((Boolean) propertyValue).booleanValue(); - if (useAnnotations && !isAnnotationsSupported()) - return true; - notifyEnablementChange(USE_ANNOTATIONS); - } - // If the source folder is changed, ensure we have the correct project name - if (propertyName.equals(SOURCE_FOLDER)) { - // Get the project name from the source folder name - String sourceFolder = (String) propertyValue; - int index = sourceFolder.indexOf(File.separator); - String projectName = sourceFolder; - if (index == 0) - projectName = sourceFolder.substring(1); - index = projectName.indexOf(File.separator); - if (index != -1) { - projectName = projectName.substring(0, index); - setProperty(PROJECT_NAME, projectName); - } - } - // Call super to set the property on the data model - boolean result = super.doSetProperty(propertyName, propertyValue); - // If class name is changed, update the display name to be the same - if (propertyName.equals(CLASS_NAME) && !isSet(DISPLAY_NAME)) { - notifyDefaultChange(DISPLAY_NAME); - } - // After the property is set, if project changed, update the nature and the annotations enablement - if (propertyName.equals(MODULE_NAME)) { - notifyEnablementChange(USE_ANNOTATIONS); - } - // After property is set, if annotations is set to true, update its value based on the new level of the project - if (getBooleanProperty(USE_ANNOTATIONS)) { - if (!isAnnotationsSupported()) - setBooleanProperty(USE_ANNOTATIONS, false); - } - // Return whether property was set - return result; - } - - protected boolean isAnnotationsSupported() { - if (getTargetProject()==null || getWorkbenchModule()==null) return true; - WebArtifactEdit webEdit = null; - try { - ComponentHandle handle = ComponentHandle.create(getTargetProject(),getWorkbenchModule().getName()); - webEdit = WebArtifactEdit.getWebArtifactEditForRead(handle); - if (webEdit == null) - return false; - return webEdit.getJ2EEVersion() > J2EEVersionConstants.VERSION_1_2; - } catch (Exception e) { - e.printStackTrace(); - return false; - } finally { - if (webEdit != null) - webEdit.dispose(); - } - } - - /** - * Subclasses may extend this method to provide their own validation on any of the valid - * data model properties in the hierarchy. This implementation adds validation for - * the init params, servlet mappings, display name, and existing class - * fields specific to the servlet java class creation. It does not accept a null - * parameter. This method will not return null. - * @see NewJavaClassDataModel#doValidateProperty(String) - * @see org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel#doValidateProperty(String) - * - * @param propertyName - * @return IStatus is property value valid? - */ - protected IStatus doValidateProperty(String propertyName) { - // If our default is the superclass, we know it is ok - if (propertyName.equals(SUPERCLASS) && getStringProperty(propertyName).equals(SERVLET_SUPERCLASS)) - return WTPCommonPlugin.OK_STATUS; - IStatus result = super.doValidateProperty(propertyName); - if (!result.isOK()) - return result; - // Validate init params - if (propertyName.equals(INIT_PARAM)) - return validateInitParamList((List) getProperty(propertyName)); - // Validate servlet mappings - if (propertyName.equals(URL_MAPPINGS)) - return validateURLMappingList((List) getProperty(propertyName)); - // Validate the servlet name in DD - if (propertyName.equals(DISPLAY_NAME)) - return validateDisplayName(getStringProperty(propertyName)); - - // Otherwise defer to super to validate the property - return result; - } - - /** - * Subclasses may extend this method to provide their own validation of the specified - * java classname. This implementation will ensure the class name is not set to Servlet - * and then will forward on to the NewJavaClassDataModel to validate the class name as - * valid java. This method does not accept null as a parameter. It will not return null. - * @see NewServletClassDataModel#validateExistingClass(boolean) - * @see NewJavaClassDataModel#validateJavaClassName(String) - * - * @param className - * @return IStatus is java classname valid? - */ - protected IStatus validateJavaClassName(String className) { - // First use the NewJavaClassDataModel to validate the classname as proper java syntax - IStatus status = super.validateJavaClassName(className); - if (status.isOK()) { - // Do not allow the name to be "Servlet" - if (className.equals("Servlet")) { //$NON-NLS-1$ - String msg = WebMessages.getResourceString(WebMessages.ERR_SERVLET_JAVA_CLASS_NAME_INVALID); - return WTPCommonPlugin.createErrorStatus(msg); - } - return WTPCommonPlugin.OK_STATUS; - } - // Return the status - return status; - } - - /** - * This method is intended for internal use only. It will be used to validate the init params list - * to ensure there are not any duplicates. This method will accept a null paramter. It will - * not return null. - * @see NewServletClassDataModel#doValidateProperty(String) - * - * @param prop - * @return IStatus is init params list valid? - */ - private IStatus validateInitParamList(List prop) { - if (prop != null && !prop.isEmpty()) { - // Ensure there are not duplicate entries in the list - boolean dup = hasDuplicatesInStringArrayList(prop); - if (dup) { - String msg = WebMessages.getResourceString(WebMessages.ERR_DUPLICATED_INIT_PARAMETER); - return WTPCommonPlugin.createErrorStatus(msg); - } - } - // Return OK - return WTPCommonPlugin.OK_STATUS; - } - - /** - * This method is intended for internal use only. This will validate the servlet mappings - * list and ensure there are not duplicate entries. It will accept a null parameter. - * It will not return null. - * @see NewServletClassDataModel#doValidateProperty(String) - * - * @param prop - * @return IStatus is servlet mapping list valid? - */ - private IStatus validateURLMappingList(List prop) { - if (prop != null && !prop.isEmpty()) { - // Ensure there are not duplicates in the mapping list - boolean dup = hasDuplicatesInStringArrayList(prop); - if (dup) { - String msg = WebMessages.getResourceString(WebMessages.ERR_DUPLICATED_URL_MAPPING); - return WTPCommonPlugin.createErrorStatus(msg); - } - } else { - String msg = WebMessages.getResourceString(WebMessages.ERR_SERVLET_MAPPING_URL_PATTERN_EMPTY); - return WTPCommonPlugin.createErrorStatus(msg); - } - // Return OK - return WTPCommonPlugin.OK_STATUS; - } - - /** - * This method is intended for internal use only. It provides a simple - * algorithm for detecting if there are duplicate entries in a list. It will - * accept a null paramter. It will not return null. - * @see NewServletClassDataModel#validateInitParamList(List) - * @see NewServletClassDataModel#validateURLMappingList(List) - * - * @param input - * @return boolean are there dups in the list? - */ - private boolean hasDuplicatesInStringArrayList(List input) { - // If list is null or empty return false - if (input == null) - return false; - int n = input.size(); - boolean dup = false; - // nested for loops to check each element to see if other elements are the same - for (int i = 0; i < n; i++) { - String[] sArray1 = (String[]) input.get(i); - for (int j = i + 1; j < n; j++) { - String[] sArray2 = (String[]) input.get(j); - if (isTwoStringArraysEqual(sArray1, sArray2)) { - dup = true; - break; - } - } - if (dup) - break; - } - // Return boolean status for duplicates - return dup; - } - - /** - * This method is intended for internal use only. This checks to see if the two string - * arrays are equal. If either of the arrays are null or empty, it returns false. - * @see NewServletClassDataModel#hasDuplicatesInStringArrayList(List) - * - * @param sArray1 - * @param sArray2 - * @return boolean are Arrays equal? - */ - private boolean isTwoStringArraysEqual(String[] sArray1, String[] sArray2) { - // If either array is null, return false - if (sArray1 == null || sArray2 == null) - return false; - int n1 = sArray1.length; - int n2 = sArray1.length; - // If either array is empty, return false - if (n1 == 0 || n2 == 0) - return false; - // If they don't have the same length, return false - if (n1 != n2) - return false; - // If their first elements do not match, return false - if (!sArray1[0].equals(sArray2[0])) - return false; - // Otherwise return true - return true; - } - - /** - * This method will return the list of servlet interfaces to be implemented for the - * new servlet java class. It will intialize the list using lazy initialization to - * the minimum interfaces required by the data model SERVLET_INTERFACES. This method - * will not return null. - * @see NewServletClassDataModel#SERVLET_INTERFACES - * - * @return List of servlet interfaces to be implemented - */ - public final List getServletInterfaces() { - if (interfaceList == null) { - interfaceList = new ArrayList(); - // Add minimum required list of servlet interfaces to be implemented - for (int i = 0; i < SERVLET_INTERFACES.length; i++) { - interfaceList.add(SERVLET_INTERFACES[i]); - } - } - // Return interface list - return interfaceList; - } - - /** - * This method is intended for internal use only. This will validate whether the display name - * selected is a valid display name for the servlet in the specified web application. It will - * make sure the name is not empty and that it doesn't already exist in the web app. This - * method will accept null as a parameter. It will not return null. - * @see NewServletClassDataModel#doValidateProperty(String) - * - * @param prop - * @return IStatus is servlet display name valid? - */ - private IStatus validateDisplayName(String prop) { - // Ensure the servlet display name is not null or empty - if (prop == null || prop.trim().length() == 0) { - String msg = WebMessages.getResourceString(WebMessages.ERR_DISPLAY_NAME_EMPTY); - return WTPCommonPlugin.createErrorStatus(msg); - } - if (getTargetProject()==null || getWorkbenchModule()==null) - return WTPCommonPlugin.OK_STATUS; - ArtifactEdit edit = null; - try { - edit = getArtifactEditForRead(); - WebApp webApp = (WebApp) edit.getContentModelRoot(); - if (webApp == null) - return WTPCommonPlugin.OK_STATUS; - List servlets = webApp.getServlets(); - boolean exists = false; - // Ensure the display does not already exist in the web application - if (servlets != null && !servlets.isEmpty()) { - for (int i = 0; i < servlets.size(); i++) { - String name = ((Servlet) servlets.get(i)).getServletName(); - if (prop.equals(name)) - exists = true; - } - } - // If the servlet name already exists, throw an error - if (exists) { - String msg = WebMessages.getResourceString(WebMessages.ERR_SERVLET_DISPLAY_NAME_EXIST, new String[]{prop}); - return WTPCommonPlugin.createErrorStatus(msg); - } - } finally { - if (edit!=null) - edit.dispose(); - } - - //Otherwise, return OK - return WTPCommonPlugin.OK_STATUS; - } - - /** - * Subclasses may extend this method to perform their own retrieval mechanism. - * This implementation simply returns the JDT package fragment root for the selected source - * folder. This method may return null. - * @see IJavaProject#getPackageFragmentRoot(org.eclipse.core.resources.IResource) - * - * @return IPackageFragmentRoot - */ - public IPackageFragmentRoot getJavaPackageFragmentRoot() { - // Ensure project is not null - IProject project = getTargetProject(); - if (project == null) - return null; - - IJavaProject javaProject = JavaProjectUtilities.getJavaProject(project); - if (javaProject != null) { - // Ensure source folder exists - IFolder sourcefolder = getJavaSourceFolder(); - // Get the java package for the selected folder - if (sourcefolder != null) - return javaProject.getPackageFragmentRoot(sourcefolder); - } - return null; - } - - /** - * Subclasses may extend this method to perform their own retrieval of a default java source folder. - * This implementation returns the JavaSource folder as default since we are in a - * web project. This method may return null. - * @see NewJavaClassDataModel#getDefaultJavaSourceFolder() - * - * @return IFolder default java source folder - */ - protected IFolder getDefaultJavaSourceFolder() { - // Ensure project is not null - IProject project = getTargetProject(); - if (project == null) - return null; - - return (IFolder) WebPropertiesUtil.getJavaSourceFolder(project); - } - - /** - * @return boolean should the default annotations be true? - */ - private static Boolean shouldDefaultAnnotations() { - if (useAnnotations) - return Boolean.TRUE; - return Boolean.FALSE; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassOperation.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassOperation.java deleted file mode 100644 index f1f58238f..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassOperation.java +++ /dev/null @@ -1,325 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.web.operations; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.resources.ICommand; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.emf.codegen.jet.JETException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.common.internal.annotations.controller.AnnotationsController; -import org.eclipse.jst.common.internal.annotations.controller.AnnotationsControllerManager; -import org.eclipse.jst.j2ee.application.internal.operations.IAnnotationsDataModel; -import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModel; -import org.eclipse.jst.j2ee.internal.project.WTPJETEmitter; -import org.eclipse.jst.j2ee.internal.web.plugin.WebPlugin; -import org.eclipse.wst.common.componentcore.internal.operation.ArtifactEditOperation; -import org.eclipse.wst.common.componentcore.internal.operation.ArtifactEditOperationDataModel; -import org.eclipse.wst.common.frameworks.internal.enablement.nonui.WFTWrappedException; - -/** - * The NewServletClassOperation is a WTPOperation following the WTP wizard data model and - * operation framework. - * @see org.eclipse.wst.common.frameworks.internal.operations.WTPOperation - * @see org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModel - * - * It extends EditModelOperation to provide servlet specific java class generation. - * @see org.eclipse.wst.common.internal.emfworkbench.operation.EditModelOperation - * - * This operation is used by the AddServletOperation to generate either an annotated or - * non annotated java class for an added servlet. It shares the NewServletClassDataModel - * with the AddServletOperation to store the appropriate properties required to generate - * the new servlet. - * @see org.eclipse.jst.j2ee.internal.web.operations.AddServletOperation - * @see org.eclipse.jst.j2ee.internal.web.operations.NewServletClassDataModel - * - * In the annotated case, a WTPJetEmitter servlet template is created and used to generate the - * servlet java class with the embedded annotated tags. - * @see org.eclipse.jst.j2ee.internal.project.WTPJETEmitter - * @see org.eclipse.jst.j2ee.internal.web.operations.CreateServletTemplateModel - * - * In the non annotated case, the same emitter is used to create the class with the non annotated - * servlet template so the annotated tags are omitted. - * - * Subclasses may extend this operation to provide their own specific servlet java class generation. - * The execute method may be extended to do so. Also, generateUsingTemplates is exposed. - * - * The use of this class is EXPERIMENTAL and is subject to substantial changes. - */ -public class NewServletClassOperation extends ArtifactEditOperation { - - /** - * The extension name for a java class - */ - private static final String DOT_JAVA = ".java"; //$NON-NLS-1$ - /** - * platform plugin beginning for URI string - */ - private static final String PLATFORM_PLUGIN = "platform:/plugin/"; //$NON-NLS-1$ - - /** - * variable for the web plugin - */ - protected static final String WEB_PLUGIN = "WEB_PLUGIN"; //$NON-NLS-1$ - /** - * folder location of the servlet creation templates diretory - */ - protected static final String TEMPLATE_DIR = "/templates/"; //$NON-NLS-1$ - /** - * name of the template emitter to be used to generate the deployment descriptor from the tags - */ - protected static final String TEMPLATE_EMITTER = "org.eclipse.jst.j2ee.ejb.annotations.emitter.template"; //$NON-NLS-1$ - /** - * id of the builder used to kick off generation of web metadata based on parsing of annotations - */ - protected static final String BUILDER_ID = "builderId"; //$NON-NLS-1$ - - /** - * This is the constructor which should be used when creating a NewServletClassOperation. An instance of - * the NewServletClassDataModel should be passed in. This does not accept null parameter. It will - * not return null. - * @see EditModelOperation#EditModelOperation(EditModelOperationDataModel) - * @see NewServletClassDataModel - * - * @param dataModel - * @return NewServletClassOperation - */ - public NewServletClassOperation(ArtifactEditOperationDataModel dataModel) { - super(dataModel); - } - - /** - * Subclasses may extend this method to add their own actions during execution. - * The implementation of the execute method drives the running of the operation. - * This implemenatation will create the java source folder, create the java package, - * and then if using annotations, will use templates to generate an annotated servlet - * java class, or if it is not annotated, the servlet java class file will be created - * without the annotated tags using templates. - * Optionally, subclasses may extend the generateUsingTemplates or createJavaFile method - * rather than extend the execute method. This method will accept a null paramter. - * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperation#execute(org.eclipse.core.runtime.IProgressMonitor) - * @see NewServletClassOperation#generateUsingTemplates(IProgressMonitor, IPackageFragment) - * - * @param monitor - * @throws CoreException - * @throws InterruptedException - * @throws InvocationTargetException - */ - protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { - // Create source folder if it does not exist - createJavaSourceFolder(); - // Create java package if it does not exist - IPackageFragment pack = createJavaPackage(); - // Generate using templates - generateUsingTemplates(monitor, pack); - } - - /** - * This method will return the java package as specified by the new java class data model. - * If the package does not exist, it will create the package. This method should not return - * null. - * @see NewJavaClassDataModel#JAVA_PACKAGE - * @see IPackageFragmentRoot#createPackageFragment(java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) - * - * @return IPackageFragment the java package - */ - protected final IPackageFragment createJavaPackage() { - NewJavaClassDataModel model = (NewJavaClassDataModel) operationDataModel; - // Retrieve the package name from the java class data model - String packageName = model.getStringProperty(NewJavaClassDataModel.JAVA_PACKAGE); - IPackageFragmentRoot packRoot = model.getJavaPackageFragmentRoot(); - IPackageFragment pack = packRoot.getPackageFragment(packageName); - // Handle default package - if (pack == null) { - pack = packRoot.getPackageFragment(""); //$NON-NLS-1$ - } - // Create the package fragment if it does not exist - if (!pack.exists()) { - String packName = pack.getElementName(); - try { - pack = packRoot.createPackageFragment(packName, true, null); - } catch (JavaModelException e) { - Logger.getLogger().log(e); - } - } - // Return the package - return pack; - } - - /** - * Subclasses may extend this method to provide their own template based creation - * of an annotated servlet java class file. This implementation uses the creation of - * a CreateServletTemplateModel and the WTPJetEmitter to create the java class with the - * annotated tags. This method accepts null for monitor, it does not accept null for - * fragment. If annotations are not being used the tags will be omitted from the class. - * @see CreateServletTemplateModel - * @see NewServletClassOperation#generateTemplateSource(CreateServletTemplateModel, IProgressMonitor) - * - * @param monitor - * @param fragment - * @throws CoreException - * @throws WFTWrappedException - */ - protected void generateUsingTemplates(IProgressMonitor monitor, IPackageFragment fragment) throws WFTWrappedException, CoreException { - // Create the servlet template model - CreateServletTemplateModel tempModel = createTemplateModel(); - IProject project = ((ArtifactEditOperationDataModel)getOperationDataModel()).getTargetProject(); - String source; - // Using the WTPJetEmitter, generate the java source based on the servlet template model - try { - source = generateTemplateSource(tempModel, monitor); - } catch (JETException e) { - throw new WFTWrappedException(e); - } - if (fragment != null) { - // Create the java file - String javaFileName = tempModel.getServletClassName() + DOT_JAVA; - ICompilationUnit cu = fragment.getCompilationUnit(javaFileName); - // Add the compilation unit to the java file - if (cu == null || !cu.exists()) - cu = fragment.createCompilationUnit(javaFileName, source, true, monitor); - IFile aFile = (IFile) cu.getResource(); - // Let the annotations controller process the annotated resource - AnnotationsController controller = AnnotationsControllerManager.INSTANCE.getAnnotationsController(project); - if (controller != null) - controller.process(aFile); - //((J2EEEditModel)model.getEditModel()).getWorkingCopy(cu, true); //Track CU. - } - // Add the annotations builder to the java project so metadata can be generated. - //TODO for M4 cannot add builder directly here, needs to be set up more extensibly - addAnnotationsBuilder(); - } - - /** - * This method is intended for internal use only. This method will add the annotations builder - * for Xdoclet to the targetted project. This needs to be removed from the operation and set - * up to be more extensible throughout the workbench. - * @see NewServletClassOperation#generateUsingTemplates(IProgressMonitor, IPackageFragment) - * - * @deprecated - */ - private void addAnnotationsBuilder() { - try { - NewServletClassDataModel dataModel = (NewServletClassDataModel) operationDataModel; - // Find the xdoclet builder from the extension registry - IConfigurationElement[] configurationElements = Platform.getExtensionRegistry().getConfigurationElementsFor(TEMPLATE_EMITTER); - String builderID = configurationElements[0].getNamespace() + "."+ configurationElements[0].getAttribute(BUILDER_ID); //$NON-NLS-1$ - IProject project = dataModel.getTargetProject(); - IProjectDescription description = project.getDescription(); - ICommand[] commands = description.getBuildSpec(); - boolean found = false; - // Check if the builder is already set on the project - for (int i = 0; i < commands.length; ++i) { - if (commands[i].getBuilderName().equals(builderID)) { - found = true; - break; - } - } - // If the builder is not on the project, add it - if (!found) { - ICommand command = description.newCommand(); - command.setBuilderName(builderID); - ICommand[] newCommands = new ICommand[commands.length + 1]; - System.arraycopy(commands, 0, newCommands, 0, commands.length); - newCommands[commands.length] = command; - IProjectDescription desc = project.getDescription(); - desc.setBuildSpec(newCommands); - project.setDescription(desc, null); - } - } catch (Exception e) { - //Ignore - } - } - - /** - * This method is intended for internal use only. This will use the WTPJETEmitter to create - * an annotated java file based on the passed in servlet class template model. This method - * does not accept null parameters. It will not return null. If annotations are not used, - * it will use the non annotated template to omit the annotated tags. - * @see NewServletClassOperation#generateUsingTemplates(IProgressMonitor, IPackageFragment) - * @see JETEmitter#generate(org.eclipse.core.runtime.IProgressMonitor, java.lang.Object[]) - * @see CreateServletTemplateModel - * - * @param tempModel - * @param monitor - * @return String the source for the java file - * @throws JETException - */ - private String generateTemplateSource(CreateServletTemplateModel tempModel, IProgressMonitor monitor) throws JETException { - String templateURI; - // If annotated, use annotated template - if (((NewServletClassDataModel) getOperationDataModel()).getBooleanProperty(IAnnotationsDataModel.USE_ANNOTATIONS)) - templateURI = PLATFORM_PLUGIN + WebPlugin.PLUGIN_ID + TEMPLATE_DIR + NewServletClassDataModel.TEMPLATE_FILE; - // Otherwise use non annotated template - else - templateURI = PLATFORM_PLUGIN + WebPlugin.PLUGIN_ID + TEMPLATE_DIR + NewServletClassDataModel.NON_ANNOTATED_TEMPLATE_FILE; - WTPJETEmitter emitter = new WTPJETEmitter(templateURI, this.getClass().getClassLoader()); - emitter.setIntelligentLinkingEnabled(true); - emitter.addVariable(WEB_PLUGIN, WebPlugin.PLUGIN_ID); - return emitter.generate(monitor, new Object[]{tempModel}); - } - - /** - * This method is intended for internal use only. This method will create an instance of the - * CreateServletTemplate model to be used in conjunction with the WTPJETEmitter. This method - * will not return null. - * @see CreateServletTemplateModel - * @see NewServletClassOperation#generateUsingTemplates(IProgressMonitor, IPackageFragment) - * - * @return CreateServletTemplateModel - */ - private CreateServletTemplateModel createTemplateModel() { - // Create the CreateServletTemplateModel instance with the new servlet class data model - CreateServletTemplateModel model = new CreateServletTemplateModel((NewServletClassDataModel) getOperationDataModel()); - return model; - } - - /** - * This method will return the java source folder as specified in the java class data model. - * It will create the java source folder if it does not exist. This method may return null. - * @see NewJavaClassDataModel#SOURCE_FOLDER - * @see IFolder#create(boolean, boolean, org.eclipse.core.runtime.IProgressMonitor) - * - * @return IFolder the java source folder - */ - protected final IFolder createJavaSourceFolder() { - NewJavaClassDataModel model = (NewJavaClassDataModel) operationDataModel; - // Get the source folder name from the data model - String folderFullPath = model.getStringProperty(NewJavaClassDataModel.SOURCE_FOLDER); - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IFolder folder = root.getFolder(new Path(folderFullPath)); - // If folder does not exist, create the folder with the specified path - if (!folder.exists()) { - try { - folder.create(true, true, null); - } catch (CoreException e) { - Logger.getLogger().log(e); - } - } - // Return the source folder - return folder; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/OldJ2EESettingsForMigration.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/OldJ2EESettingsForMigration.java deleted file mode 100644 index e90fed71f..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/OldJ2EESettingsForMigration.java +++ /dev/null @@ -1,397 +0,0 @@ -/* - * Created on Aug 19, 2003 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.jst.j2ee.internal.web.operations; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.StringWriter; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.core.util.Util; -import org.eclipse.jst.j2ee.internal.project.J2EENature; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -public class OldJ2EESettingsForMigration { - - protected IFile fSettingsFile; - protected IProject fProject; - protected Document fDomDocument; - protected J2EENature nature = null; - // Version number may not change with every release, - // only when changes necessitate a new version number - public static String CURRENT_VERSION = "600"; //$NON-NLS-1$ - public static String VERSION_V4 = "400"; //$NON-NLS-1$ - public static final String ELEMENT_WORKSPACE_VERSION = "version"; //$NON-NLS-1$ - - public static String J2EE_SETTINGS_FILE_NAME = ".j2ee"; //$NON-NLS-1$ - - static final String ELEMENT_J2EESETTINGS = "j2eesettings"; //$NON-NLS-1$ - static final String ELEMENT_J2EE_MODULE_VERSION = "moduleversion"; //$NON-NLS-1$ - - public OldJ2EESettingsForMigration(IProject project, J2EENature nature) { - fProject = project; - this.nature = nature; - if (getDOMDocument() == null) { - try { - createNewDocument(); - } catch (CoreException e) { - //Ignore - } catch (IOException e) { - //Ignore - } - } - } - - public OldJ2EESettingsForMigration(IProject project, J2EENature nature, IFile webSettings) { - fProject = project; - this.nature = nature; - } - - protected void createNewDocument() throws CoreException, IOException { - StringWriter writer = new StringWriter(); - writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$ - writer.write("\n"); //$NON-NLS-1$ - writer.write("<j2eesettings version=\""); //$NON-NLS-1$ - writer.write(getCurrentVersion()); - writer.write("\">");//$NON-NLS-1$ - writer.write("\n"); //$NON-NLS-1$ - writer.write("</j2eesettings>"); //$NON-NLS-1$ - writer.write("\n"); //$NON-NLS-1$ - - InputStream sourceStream = new ByteArrayInputStream(writer.toString().getBytes("UTF8")); //$NON-NLS-1$ - IFile settingsFile = getSettingsFile(); - if (settingsFile.exists()) - settingsFile.setContents(sourceStream, true, true, null); - else - settingsFile.create(sourceStream, true, null); - read(); - } - - public OldJ2EESettingsForMigration(IProject project) { - fProject = project; - if (getDOMDocument() == null) { - try { - createNewDocument(); - } catch (CoreException e) { - //Ignore - } catch (IOException e) { - //Ignore - } - } - } - - protected Document getDOMDocument() { - if (fDomDocument == null) { - try { - read(); - } catch (IOException e) { - //Ignore - } - } - return fDomDocument; - } - - // Version of getDomDocument for use by import - protected Document getDOMDocument(IFile webSettings) { - if (fDomDocument == null) { - try { - read(webSettings); - } catch (IOException e) { - //Ignore - } - } - return fDomDocument; - } - - public String getCurrentVersion() { - // The following change is needed when the websettings file is - // deleted from a version 4 workspace Checking for webapplication - // folder - Otherwise, new projects will not work. - return CURRENT_VERSION; - } - - protected IFile getSettingsFile() { - if (fSettingsFile == null) { - fSettingsFile = fProject.getFile(J2EE_SETTINGS_FILE_NAME); - } - return fSettingsFile; - } - - protected void read() throws IOException { - // This following was changed for Defect 212723 The Util StringReader - // was changed to the InputStreamReader MAY - IFile settingsFile = getSettingsFile(); - InputStream inputStream = null; - InputStreamReader fileStream = null; - if (settingsFile.exists()) { - try { - ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); - - // JZ: fix to defect 240171 - inputStream = settingsFile.getContents(true); - fileStream = new InputStreamReader(inputStream, "utf-8"); //$NON-NLS-1$ - - DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - fDomDocument = parser.parse(new InputSource(fileStream)); - } finally { - Thread.currentThread().setContextClassLoader(prevClassLoader); - } - } catch (JavaModelException e) { - throw new IOException(Util.bind("file.badFormat")); //$NON-NLS-1$ - } catch (CoreException e) { - throw new IOException(Util.bind("file.badFormat")); //$NON-NLS-1$ - } catch (SAXException e) { - throw new IOException(Util.bind("file.badFormat")); //$NON-NLS-1$ - } catch (ParserConfigurationException e) { - throw new IOException(Util.bind("file.badFormat")); //$NON-NLS-1$ - } finally { - if (fileStream != null) - fileStream.close(); - } - } - } - - - // Version of read for use by import - protected void read(IFile settings) throws IOException { - // This following was changed for Defect 212723 The Util StringReader - // was changed to the InputStreamReader MAY - IFile settingsFile = settings; - - InputStream inputStream = null; - InputStreamReader fileStream = null; - if (settingsFile != null) { - try { - ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); - inputStream = settingsFile.getContents(); - fileStream = new InputStreamReader(inputStream, "utf-8"); //$NON-NLS-1$ - - DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - fDomDocument = parser.parse(new InputSource(fileStream)); - } finally { - Thread.currentThread().setContextClassLoader(prevClassLoader); - } - - } catch (SAXException e) { - throw new IOException(Util.bind("file.badFormat")); //$NON-NLS-1$ - } catch (ParserConfigurationException e) { - throw new IOException(Util.bind("file.badFormat")); //$NON-NLS-1$ - } catch (CoreException ce) { - ce.printStackTrace(); - } finally { - if (fileStream != null) - fileStream.close(); - } - } - } - - public void write() throws CoreException { - if (fDomDocument == null) - return; - - ByteArrayOutputStream outStream = new ByteArrayOutputStream(); - - try { - TransformerFactory factory = TransformerFactory.newInstance(); - Transformer transformer = factory.newTransformer(); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ - transformer.transform(new DOMSource(fDomDocument.getDocumentElement()), new StreamResult(outStream)); - } catch (TransformerConfigurationException e) { - e.printStackTrace(); - } catch (TransformerFactoryConfigurationError e) { - e.printStackTrace(); - } catch (TransformerException e) { - e.printStackTrace(); - } - - InputStream sourceStream = new ByteArrayInputStream(outStream.toByteArray()); - - IFile settingsFile = getSettingsFile(); - if (settingsFile.exists()) - settingsFile.setContents(sourceStream, true, true, null); - else - settingsFile.create(sourceStream, true, null); - } - - public String getVersion() { - Document doc = getDOMDocument(); - if (doc == null) - return null; - - Element root = doc.getDocumentElement(); - if (root == null) - return null; - if (!root.getNodeName().equalsIgnoreCase(getRootNodeName())) - return null; - - return root.getAttribute(ELEMENT_WORKSPACE_VERSION); //$NON-NLS-1$ - } - - - public void setVersion(String version) { - Document doc = getDOMDocument(); - if (doc == null) - return; - - Element root = doc.getDocumentElement(); - if (root == null) - return; - - if (!root.getNodeName().equalsIgnoreCase(getRootNodeName())) - return; - - root.setAttribute(ELEMENT_WORKSPACE_VERSION, version); //$NON-NLS-1$ - } - - protected void setValue(Element root, String nodeName, String value) { - Node node = findOrCreateChildNode(root, nodeName); - - NodeList childNodes = node.getChildNodes(); - - if (childNodes.getLength() == 0) { - Text newText = getDOMDocument().createTextNode(value); - node.appendChild(newText); - root.appendChild(node); - } else { - for (int i = 0; i < childNodes.getLength(); i++) { - Node curNode = childNodes.item(i); - if (curNode.getNodeType() == Node.TEXT_NODE) - curNode.setNodeValue(value); - } - } - } - - protected Node findOrCreateChildNode(Element root, String nodeName) { - Node node = findChildNode(root, nodeName); - if (node == null) { - // If the element does not exist yet, create one. - node = getDOMDocument().createElement(nodeName); - root.appendChild(node); - } - return node; - } - - protected Element findChildNode(Element parent, String nodeName) { - NodeList list = parent.getChildNodes(); - int length = list.getLength(); - for (int i = 0; i < length; ++i) { - Node curNode = list.item(i); - if (curNode.getNodeType() == Node.ELEMENT_NODE) { - Element curElement = (Element) curNode; - if (curElement.getNodeName().equalsIgnoreCase(nodeName)) - return curElement; - } - } - return null; - } - - protected Document getOrCreateDocument() { - Document doc = getDOMDocument(); - if (doc == null) { - try { - createNewDocument(); - doc = getDOMDocument(); - } catch (CoreException e) { - //Ignore - } catch (IOException e) { - //Ignore - } - } - return doc; - } - - protected Element getRootElement() { - Document doc = getDOMDocument(); - if (doc == null) - return null; - - Element root = doc.getDocumentElement(); - if (root == null) - return null; - if (!root.getNodeName().equalsIgnoreCase(getRootNodeName())) - return null; - return root; - } - - protected String getValue(String settingName) { - Element root = getRootElement(); - if (root == null) - return null; - return getNodeValue(root, settingName); - } - - protected String getNodeValue(Element parent, String nodeName) { - if (parent != null) { - Element node = findChildNode(parent, nodeName); - if (node != null) - return getChildText(node); - } - return null; - } - - protected String getChildText(Element node) { - NodeList list = node.getChildNodes(); - int length = list.getLength(); - for (int i = 0; i < length; ++i) { - Node curNode = list.item(i); - if (curNode.getNodeType() == Node.TEXT_NODE) { - return curNode.getNodeValue(); - } - } - return null; - } - - protected void setValue(String nodeName, String value) { - Document doc = getOrCreateDocument(); - setValue(doc.getDocumentElement(), nodeName, value); - } - - public int getModuleVersion() { - int version = 0; - String moduleVer = getValue(ELEMENT_J2EE_MODULE_VERSION); - if (moduleVer != null) - version = Integer.valueOf(moduleVer).intValue(); - return version; - } - - public void setModuleVersion(int moduleVersion) { - Integer holder = new Integer(moduleVersion); - setValue(ELEMENT_J2EE_MODULE_VERSION, holder.toString()); - } - - public String getRootNodeName() { - return ELEMENT_J2EESETTINGS; - } -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/OldWebSettingsForMigration.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/OldWebSettingsForMigration.java deleted file mode 100644 index 62ebd51ce..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/OldWebSettingsForMigration.java +++ /dev/null @@ -1,337 +0,0 @@ -package org.eclipse.jst.j2ee.internal.web.operations; -/* - * Licensed Material - Property of IBM - * (C) Copyright IBM Corp. 2002 - All Rights Reserved. - * US Government Users Restricted Rights - Use, duplication or disclosure - * restricted by GSA ADP Schedule Contract with IBM Corp. - */ - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.StringWriter; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.FactoryConfigurationError; -import javax.xml.parsers.ParserConfigurationException; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jst.j2ee.internal.project.IWebNatureConstants; -import org.eclipse.wst.web.internal.operation.ILibModule; -import org.eclipse.wst.web.internal.operation.LibModule; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -public class OldWebSettingsForMigration extends OldJ2EESettingsForMigration { - static final String ELEMENT_WEBSETTINGS = "j2eesettings"; //$NON-NLS-1$ - static final String ELEMENT_PROJECTTYPE = "project-type"; //$NON-NLS-1$ - static final String ELEMENT_CONTEXTROOT = "context-root"; //$NON-NLS-1$ - static final String ELEMENT_WEBCONTENT = "webcontent"; //$NON-NLS-1$ - static final String ELEMENT_JSPLEVEL = "jsp-level"; //$NON-NLS-1$ - static final String ELEMENT_LIBMODULES = "lib-modules"; //$NON-NLS-1$ - static final String ELEMENT_LIBMODULE = "lib-module"; //$NON-NLS-1$ - static final String ELEMENT_LIBMODULE_JAR = "jar"; //$NON-NLS-1$ - static final String ELEMENT_LIBMODULE_PROJECT = "project"; //$NON-NLS-1$ - static final String ELEMENT_FEATURES = "features"; //$NON-NLS-1$ - static final String ELEMENT_FEATURE = "feature"; //$NON-NLS-1$ - static final String ELEMENT_FEATUREID = "feature-id"; //$NON-NLS-1$ - - static final ILibModule[] EMPTY_LIBMODULES = new ILibModule[0]; - static final String[] EMPTY_FEATURES = new String[0]; - static boolean validWebSettings = true; - - public OldWebSettingsForMigration(IProject project) { - super(project, null); - } - - public OldWebSettingsForMigration(IProject project, IFile webSettings) { - super(project, null, webSettings); - if (getDOMDocument(webSettings) == null) { - validWebSettings = false; - } - } - - protected IFile getSettingsFile() { - if (fSettingsFile == null) { - fSettingsFile = fProject.getFile(IWebNatureConstants.WEBSETTINGS_FILE_NAME); - } - return fSettingsFile; - } - - public String getContextRoot() { - return getValue(ELEMENT_CONTEXTROOT); - } - - public String getJSPLevel() { - return getValue(ELEMENT_JSPLEVEL); - } - - public String getWebContentName() { - return getValue(ELEMENT_WEBCONTENT); - } - - public ILibModule[] getLibModules() { - Element root = getRootElement(); - if (root == null) return EMPTY_LIBMODULES; - - Element libModuleNode = findChildNode(root, ELEMENT_LIBMODULES); - if (libModuleNode == null) return EMPTY_LIBMODULES; - - NodeList children = libModuleNode.getChildNodes(); - ArrayList results = new ArrayList(); - for (int i=0; i<children.getLength(); i++) { - Node node = children.item(i); - ILibModule libModule = getLibModule(node); - if (libModule != null) { - results.add(libModule); - } - } - - return (ILibModule[]) results.toArray(new ILibModule[results.size()]); - } - - protected ILibModule getLibModule(Node node) { - if (!node.getNodeName().equalsIgnoreCase(ELEMENT_LIBMODULE)) return null; - String jarName = getNodeValue((Element) node, ELEMENT_LIBMODULE_JAR); - String projectName = getNodeValue((Element) node, ELEMENT_LIBMODULE_PROJECT); - - ILibModule libModule = new LibModule(jarName, projectName); - return libModule; - } - - public String[] getFeatureIds() { - Element root = getRootElement(); - if (root == null) return EMPTY_FEATURES; - - Element featuresNode = findChildNode(root, ELEMENT_FEATURES); - if (featuresNode == null) return EMPTY_FEATURES; - - NodeList children = featuresNode.getChildNodes(); - ArrayList results = new ArrayList(); - for (int i=0; i<children.getLength(); i++) { - Node node = children.item(i); - String featureId = getFeatureId(node); - if (featureId != null) { - results.add(featureId); - } - } - - return (String[]) results.toArray(new String[results.size()]); - } - - protected String getFeatureId(Node node) { - if (!node.getNodeName().equalsIgnoreCase(ELEMENT_FEATURE)) return null; - String id = getNodeValue((Element) node, ELEMENT_FEATUREID); - - return id; - } - - public String getProjectType() { - return getValue(ELEMENT_PROJECTTYPE); - } - - public String getCurrentVersion() { - // The following change is needed when the websettings file is - // deleted from a version 4 workspace Checking for webapplication - // folder - Otherwise, new projects will not work. -// IContainer webmoduleFolder = fProject.getFolder(IWebNatureConstants.WEB_MODULE_DIRECTORY_V4); -// IFolder webinfFolder = ((IFolder) webmoduleFolder).getFolder(IWebNatureConstants.INFO_DIRECTORY); -// if (webinfFolder.exists()) { -// return VERSION_V4; -// } -// - IContainer webcontetntFolder = fProject.getFolder(IWebNatureConstants.WEB_MODULE_DIRECTORY_); - IFolder webinfFolder = ((IFolder) webcontetntFolder).getFolder(IWebNatureConstants.INFO_DIRECTORY); - if (webinfFolder.exists()) { - return CURRENT_VERSION; - } - - return CURRENT_VERSION; - } - - protected String getValue(String settingName) { - Element root = getRootElement(); - if (root == null) return null; - return getNodeValue(root, settingName); - } - - protected void createNewDocument() throws CoreException, IOException{ - StringWriter writer = new StringWriter(); - writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$ - writer.write("\n"); //$NON-NLS-1$ - writer.write("<websettings version=\""); //$NON-NLS-1$ - writer.write(getCurrentVersion()); - writer.write("\">");//$NON-NLS-1$ - writer.write("\n"); //$NON-NLS-1$ - writer.write("</websettings>"); //$NON-NLS-1$ - writer.write("\n"); //$NON-NLS-1$ - - InputStream sourceStream = new ByteArrayInputStream(writer.toString().getBytes("UTF8")); //$NON-NLS-1$ - IFile webSettingsFile = getSettingsFile(); - if (webSettingsFile.exists()) - webSettingsFile.setContents(sourceStream, true, true, null); - else - webSettingsFile.create(sourceStream, true, null); - read(); - } - - public void setContextRoot(String contextRoot) { - setValue(ELEMENT_CONTEXTROOT, contextRoot); - } - - public void setJSPLevel(String jspLevel) { - setValue(ELEMENT_JSPLEVEL, jspLevel); - } - - public void setWebContentName(String name) { - String defaultName= getWebContentName(); - if (defaultName == null || defaultName.length() == 0 || !name.equals(defaultName)) - setValue(ELEMENT_WEBCONTENT, name); - } - - public void setProjectType(String projectType) { - setValue(ELEMENT_PROJECTTYPE, projectType); - } - - public void setLibModules(ILibModule[] libModules) { - Document doc = getOrCreateDocument(); - Node libModulesNode = findOrCreateChildNode(doc.getDocumentElement(),ELEMENT_LIBMODULES); - Node firstChild = null; - - // Remove all of the children. - while ((firstChild = libModulesNode.getFirstChild()) != null) - libModulesNode.removeChild(firstChild); - - // Add new children. - for (int i = 0; i < libModules.length; i++) { - ILibModule iLibModule = libModules[i]; - if (iLibModule != null) - addLibModule(libModulesNode, iLibModule); - } - } - - protected void addLibModule(Node libModulesNode, ILibModule libModule) { - Document doc = getDOMDocument(); - Element libModuleNode = doc.createElement(ELEMENT_LIBMODULE); - libModulesNode.appendChild(libModuleNode); - setValue(libModuleNode, ELEMENT_LIBMODULE_JAR, libModule.getJarName()); - setValue(libModuleNode, ELEMENT_LIBMODULE_PROJECT, libModule.getProjectName()); - } - - public void setFeatureIds(String[] featureIds) { - Document doc = getOrCreateDocument(); - Node featuresNode = findOrCreateChildNode(doc.getDocumentElement(),ELEMENT_FEATURES); - - // Add new children. - for (int i = 0; i < featureIds.length; i++) { - String sFeatureId = featureIds[i]; - if (sFeatureId != null) - addFeatureId(featuresNode, sFeatureId); - } - } - - protected void addFeatureId(Node featuresNode, String featureId) { - Document doc = getDOMDocument(); - Element featureNode = doc.createElement(ELEMENT_FEATURE); - featuresNode.appendChild(featureNode); - setValue(featureNode,ELEMENT_FEATUREID, featureId); - } - - public boolean isValidWebSettings() { - return validWebSettings; - } - public void removeFeatureId(String removeId) { - Element root = getRootElement(); - if (root != null) { - Element featuresNode = findChildNode(root, ELEMENT_FEATURES); - if (featuresNode != null) { - NodeList children = featuresNode.getChildNodes(); - ArrayList results = new ArrayList(); - for (int i = 0; i < children.getLength(); i++) { - Node node = children.item(i); - String featureId = getFeatureId(node); - if (featureId != null) { - // determine if in the list to remove - if (!(featureId.equals(removeId))) - results.add(featureId); - } - } - // Remove all of the children. - Node firstChild = null; - while ((firstChild = featuresNode.getFirstChild()) != null) - featuresNode.removeChild(firstChild); - if (results.size() > 0) { - String[] updateFeatureIds = (String[]) results.toArray(new String[results.size()]); - // Add new children. - for (int i = 0; i < results.size(); i++) { - String sFeatureId = updateFeatureIds[i]; - if (sFeatureId != null) - addFeatureId(featuresNode, sFeatureId); - } - } - } - } - } - public String getRootNodeName() { - return ELEMENT_WEBSETTINGS; - } - - public static String getWebContentDirectory(InputStream inputStream){ - InputStreamReader fileStream = null; - try { - fileStream = new InputStreamReader(inputStream, "utf-8"); //$NON-NLS-1$ - DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document fDomDocument = parser.parse(new InputSource(fileStream)); - Element root = fDomDocument.getDocumentElement(); - if(root.getNodeName().equalsIgnoreCase(ELEMENT_WEBSETTINGS)){ - NodeList list = root.getChildNodes(); - for(int i=0, length = list.getLength();i<length; i++){ - Node node = list.item(i); - if(node.getNodeName().equals(ELEMENT_WEBCONTENT)){ - NodeList childNodes = node.getChildNodes(); - for (int j = 0, childLength = childNodes.getLength(); j < childLength; j++) { - Node curNode = childNodes.item(j); - if (curNode.getNodeType() == Node.TEXT_NODE) { - return curNode.getNodeValue(); - } - } - return null; - } - } - } - } catch (UnsupportedEncodingException e) { - //Ignore - } catch (ParserConfigurationException e) { - //Ignore - } catch (FactoryConfigurationError e) { - //Ignore - } catch (SAXException e) { - //Ignore - } catch (IOException e) { - //Ignore - } catch(Exception e){ - //Ignore - }finally { - if (fileStream != null) - try { - fileStream.close(); - } catch (IOException e1) { - //Ignore - } - } - return null; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/WebMessages.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/WebMessages.java deleted file mode 100644 index 22af7632e..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/WebMessages.java +++ /dev/null @@ -1,160 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Jan 13, 2004 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -package org.eclipse.jst.j2ee.internal.web.operations; - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.jst.j2ee.internal.common.J2EECommonMessages; - - -/** - * @author jialin - * - * To change the template for this generated type comment go to Window - Preferences - Java - Code - * Generation - Code and Comments - */ -public class WebMessages extends J2EECommonMessages { - public static final String ERR_JAR_NAME_EMPTY = "ERR_JAR_NAME_EMPTY"; //$NON-NLS-1$ - public static final String ERR_JAR_NAME_EXIST = "ERR_JAR_NAME_EXIST"; //$NON-NLS-1$ - public static final String ERR_JAVA_PROJECT_NAME_EMPTY = "ERR_JAVA_PROJECT_NAME_EMPTY"; //$NON-NLS-1$ - public static final String ERR_JAVA_PROJECT_NAME_EXIST = "ERR_JAVA_PROJECT_NAME_EXIST"; //$NON-NLS-1$ - - public static final String ERR_DUPLICATED_INIT_PARAMETER = "ERR_DUPLICATED_INIT_PARAMETER"; //$NON-NLS-1$ - public static final String ERR_DUPLICATED_URL_MAPPING = "ERR_DUPLICATED_URL_MAPPING"; //$NON-NLS-1$ - - public static final String ERR_DISPLAY_NAME_EMPTY = "ERR_DISPLAY_NAME_EMPTY"; //$NON-NLS-1$ - public static final String ERR_SERVLET_NAME_EXIST = "ERR_SERVLET_NAME_EXIST"; //$NON-NLS-1$ - public static final String ERR_SERVLET_DISPLAY_NAME_EXIST = "ERR_SERVLET_DISPLAY_NAME_EXIST"; //$NON-NLS-1$ - public static final String ERR_SERVLET_CLASS_NAME_USED = "ERR_SERVLET_CLASS_NAME_USED"; //$NON-NLS-1$ - public static final String ERR_SERVLET_JAVA_CLASS_NAME_INVALID = "ERR_SERVLET_JAVA_CLASS_NAME_INVALID"; //$NON-NLS-1$ - public static final String ERR_SERVLET_MAPPING_SERVLET_NOT_EXIST = "ERR_SERVLET_MAPPING_SERVLET_NOT_EXIST"; //$NON-NLS-1$ - public static final String ERR_SERVLET_MAPPING_URL_PATTERN_EMPTY = "ERR_SERVLET_MAPPING_URL_PATTERN_EMPTY"; //$NON-NLS-1$ - public static final String ERR_SERVLET_MAPPING_URL_PATTERN_EXIST = "ERR_SERVLET_MAPPING_URL_PATTERN_EXIST"; //$NON-NLS-1$ - public static final String ERR_SERVLET_PARAMETER_NAME_EMPTY = "ERR_SERVLET_PARAMETER_NAME_EMPTY"; //$NON-NLS-1$ - public static final String ERR_SERVLET_PARAMETER_NAME_EXIST = "ERR_SERVLET_PARAMETER_NAME_EXIST"; //$NON-NLS-1$ - public static final String ERR_SERVLET_PARAMETER_VALUE_EMPTY = "ERR_SERVLET_PARAMETER_VALUE_EMPTY"; //$NON-NLS-1$ - public static final String ERR_SERVLET_PARAMETER_VALUE_EXIST = "ERR_SERVLET_PARAMETER_VALUE_EXIST"; //$NON-NLS-1$ - - - public static final String ERR_PAGE_ENCODING_EMPTY = "ERR_PAGE_ENCODING_EMPTY"; //$NON-NLS-1$ - public static final String ERR_PAGE_ENCODING_EXIST = "ERR_PAGE_ENCODING_EXIST"; //$NON-NLS-1$ - public static final String ERR_URL_PATTERN_EXIST = "ERR_URL_PATTERN_EXIST"; //$NON-NLS-1$ - public static final String ERR_INCLUDE_PRELUDES_EXIST = "ERR_INCLUDE_PRELUDES_EXIST"; //$NON-NLS-1$ - public static final String ERR_INCLUDE_CODAS_EXIST = "ERR_INCLUDE_CODAS_EXIST"; //$NON-NLS-1$ - - public static final String ERR_SECURITY_CONSTRAINT_NAME_EMPTY = "ERR_SECURITY_CONSTRAINT_NAME_EMPTY"; //$NON-NLS-1$ - public static final String ERR_SECURITY_CONSTRAINT_NAME_EXIST = "ERR_SECURITY_CONSTRAINT_NAME_EXIST"; //$NON-NLS-1$ - - public static final String ERR_SERVLET_ROLE_REF_NAME_EMPTY = "ERR_SERVLET_ROLE_REF_NAME_EMPTY"; //$NON-NLS-1$ - public static final String ERR_SERVLET_ROLE_REF_NAME_EXIST = "ERR_SERVLET_ROLE_REF_NAME_EXIST"; //$NON-NLS-1$ - public static final String ERR_SERVLET_ROLE_LINK_EMPTY = "ERR_SERVLET_ROLE_LINK_EMPTY"; //$NON-NLS-1$ - - public static final String ERR_CONTEXT_PARAMETER_NAME_EMPTY = "ERR_CONTEXT_PARAMETER_NAME_EMPTY"; //$NON-NLS-1$ - public static final String ERR_CONTEXT_PARAMETER_NAME_EXIST = "ERR_CONTEXT_PARAMETER_NAME_EXIST"; //$NON-NLS-1$ - - public static final String ERR_RESOURCE_NAME_EMPTY = "ERR_RESOURCE_NAME_EMPTY"; //$NON-NLS-1$ - public static final String ERR_RESOURCE_NAME_EXIST = "ERR_RESOURCE_NAME_EXIST"; //$NON-NLS-1$ - public static final String ERR_URL_PATTERNS_EMPTY = "ERR_URL_PATTERNS_EMPTY"; //$NON-NLS-1$ - - public static final String ERR_MIME_MAPPING_EXTENSION_EMPTY = "ERR_MIME_MAPPING_EXTENSION_EMPTY"; //$NON-NLS-1$ - public static final String ERR_MIME_MAPPING_EXTENSION_EXIST = "ERR_MIME_MAPPING_EXTENSION_EXIST"; //$NON-NLS-1$ - - public static final String ERR_FILTER_DISPLAY_NAME_EXIST = "ERR_FILTER_DISPLAY_NAME_EXIST"; //$NON-NLS-1$ - public static final String ERR_FILTER_CLASS_NAME_USED = "ERR_FILTER_CLASS_NAME_USED"; //$NON-NLS-1$ - public static final String ERR_FILTER_CLASS_NAME_INVALID = "ERR_FILTER_CLASS_NAME_INVALID"; //$NON-NLS-1$ - public static final String ERR_FILTER_MAPPING_URL_PATTERN_EMPTY = "3"; //$NON-NLS-1$ - public static final String ERR_FILTER_MAPPING_URL_PATTERN_EXIST = "4"; //$NON-NLS-1$ - public static final String ERR_FILTER_MAPPING_SERVLET_EMPTY = "5"; //$NON-NLS-1$ - public static final String ERR_FILTER_MAPPING_SERVLET_EXIST = "ERR_FILTER_MAPPING_SERVLET_EXIST"; //$NON-NLS-1$ - public static final String ERR_FILTER_MAPPING_SERVLET_DISPATCHER_TYPES_EMPTY = "ERR_FILTER_MAPPING_SERVLET_DISPATCHER_TYPES_EMPTY"; //$NON-NLS-1$ - public static final String ERR_FILTER_PARAM_NAME_EMPTY = "6"; //$NON-NLS-1$ - public static final String ERR_FILTER_PARAM_NAME_EXISTS = "ERR_FILTER_PARAMETER_NAME_EXIST"; //$NON-NLS-1$ - - public static final String ERR_LISTENER_DISPLAY_NAME_EXIST = "ERR_LISTENER_DISPLAY_NAME_EXIST"; //$NON-NLS-1$ - public static final String ERR_LISTENER_CLASS_NAME_USED = "ERR_LISTENER_CLASS_NAME_USED"; //$NON-NLS-1$ - public static final String ERR_LISTENER_CLASS_NAME_INVALID = "ERR_LISTENER_CLASS_NAME_INVALID"; //$NON-NLS-1$ - - public static final String ERR_ENV_ENTRY_NAME_EMPTY = "ERR_ENV_ENTRY_NAME_EMPTY"; //$NON-NLS-1$ - public static final String ERR_ENV_ENTRY_NAME_EXIST = "ERR_ENV_ENTRY_NAME_EXIST"; //$NON-NLS-1$ - - public static final String ERR_WELCOME_PAGE_EMPTY = "ERR_WELCOME_PAGE_EMPTY"; //$NON-NLS-1$ - public static final String ERR_WELCOME_PAGE_EXIST = "ERR_WELCOME_PAGE_EXIST"; //$NON-NLS-1$ - - public static final String ERR_ERROR_CODE_EMPTY = "ERR_ERROR_CODE_EMPTY"; //$NON-NLS-1$ - public static final String ERR_ERROR_CODE_MUST_BE_3_DIGITS = "ERR_ERROR_CODE_MUST_BE_3_DIGITS"; //$NON-NLS-1$ - - public static final String ERR_ERROR_PAGE_LOCATION_EMPTY = "ERR_ERROR_PAGE_LOCATION_EMPTY"; //$NON-NLS-1$ - public static final String ERR_ERROR_PAGE_LOCATION_EXIST = "ERR_ERROR_PAGE_LOCATION_EXIST"; //$NON-NLS-1$ - public static final String ERR_ERROR_PAGE_LOCATION_MUST_START_WITH_SLASH = "ERR_ERROR_PAGE_LOCATION_MUST_START_WITH_SLASH"; //$NON-NLS-1$ - - public static final String ERR_EXCEPTION_TYPE_EMPTY = "ERR_EXCEPTION_TYPE_EMPTY"; //$NON-NLS-1$ - - public static final String ERR_LOCALE_NAME_EMPTY = "ERR_LOCALE_NAME_EMPTY"; //$NON-NLS-1$ - public static final String ERR_LOCALE_NAME_EXIST = "ERR_LOCALE_NAME_EXIST"; //$NON-NLS-1$ - - public static final String ERR_TAGLIBREF_URL_EMPTY = "ERR_TAGLIBREF_URL_EMPTY"; //$NON-NLS-1$ - public static final String ERR_TAGLIBREF_URL_EXIST = "ERR_TAGLIBREF_URL_EXIST"; //$NON-NLS-1$ - - public static final String ERR_MESSAGE_DESTINATION_NAME_EMPTY = "ERR_MESSAGE_DESTINATION_NAME_EMPTY"; //$NON-NLS-1$ - public static final String ERR_MESSAGE_DESTINATION_NAME_EXIST = "ERR_MESSAGE_DESTINATION_NAME_EXIST"; //$NON-NLS-1$ - - // Security Identity Wizard, EJB EDITOR - public static final String ERR_EXCEPTION_SECURITY_ID_EMPTY_ROLE_NAME = "ERR_EXCEPTION_ROLE_NAME_EMPTY"; //$NON-NLS-1$ - public static final String ERR_EXCEPTION_SECURITY_ID_NO_BEANS = "ERR_EXCEPTION_SECURITY_ID_NO_BEANS"; //$NON-NLS-1$ - - //Method Permission Wizard, EJB EDITOR - public static final String ERR_EXCEPTION_SECURITY_ROLES_EMPTY = ERR_EXCEPTION_SECURITY_ID_EMPTY_ROLE_NAME; - public static final String ERR_EXCEPTION_METHOD_ELEMENTS_EMPTY = "ERR_EXCEPTION_METHOD_ELEMENT_EMPTY"; //$NON-NLS-1$ - - //Method Transaction Wizard, EJB EDITOR - public static final String ERR_EXCEPTION_METHOD_TRANSACTION_EMPTY = "ERR_EXCEPTION_METHOD_TRANSACTION_ATTRIBUTES_EMPTY"; //$NON-NLS-1$ - - public static final String ERR_SERVLET_LIST_EMPTY = "ERR_SERVLET_LIST_EMPTY"; //$NON-NLS-1$ - public static final String ERR_FILTER_LIST_EMPTY = "ERR_FILTER_LIST_EMPTY"; //$NON-NLS-1$ - public static final String ERR_LISTENER_LIST_EMPTY = "ERR_LISTENER_LIST_EMPTY"; //$NON-NLS-1$ - - private static final WebMessages INSTANCE = new WebMessages(); - - /** - * Returns the string from the resource bundle, or 'key' if not found. - */ - public static String getResourceString(String key) { - return INSTANCE.doGetResourceString(key); - } - - public static String getResourceString(String key, Object[] args) { - return INSTANCE.doGetResourceString(key, args); - } - - protected WebMessages() { - super(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.frameworks.internal.Messages#initializeBundle() - */ - protected void initializeBundle() { - try { - this.resourceBundle = ResourceBundle.getBundle("web"); //$NON-NLS-1$ - } catch (MissingResourceException x) { - //Do nothing - } - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/plugin/WebModuleExtensionImpl.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/plugin/WebModuleExtensionImpl.java deleted file mode 100644 index 3f9640ed4..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/plugin/WebModuleExtensionImpl.java +++ /dev/null @@ -1,257 +0,0 @@ -/*************************************************************************************************** - * Copyright (c) 2003, 2004 IBM Corporation and others. All rights reserved. This program and the - * accompanying materials are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: IBM Corporation - initial API and implementation - **************************************************************************************************/ -/* - * Created on Sep 29, 2003 - * - * To change the template for this generated file go to Window>Preferences>Java>Code - * Generation>Code and Comments - */ -package org.eclipse.jst.j2ee.internal.web.plugin; - -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jst.j2ee.application.Module; -import org.eclipse.jst.j2ee.application.WebModule; -import org.eclipse.jst.j2ee.application.internal.operations.J2EEComponentCreationDataModel; -import org.eclipse.jst.j2ee.application.internal.operations.J2EEComponentCreationOperation; -import org.eclipse.jst.j2ee.application.internal.operations.J2EEModuleImportDataModel; -import org.eclipse.jst.j2ee.commonarchivecore.internal.Archive; -import org.eclipse.jst.j2ee.internal.earcreation.UpdateModuleReferencesInEARProjectCommand; -import org.eclipse.jst.j2ee.internal.moduleextension.EarModuleExtensionImpl; -import org.eclipse.jst.j2ee.internal.moduleextension.WebModuleExtension; -import org.eclipse.jst.j2ee.internal.project.IWebNatureConstants; -import org.eclipse.jst.j2ee.internal.project.J2EEJavaProjectInfo; -import org.eclipse.jst.j2ee.internal.project.J2EENature; -import org.eclipse.jst.j2ee.internal.web.archive.operations.WebComponentCreationDataModel; -import org.eclipse.jst.j2ee.internal.web.archive.operations.WebComponentCreationDataModelProvider; -import org.eclipse.jst.j2ee.internal.web.archive.operations.WebComponentCreationOperation; -import org.eclipse.jst.j2ee.internal.web.archive.operations.WebModuleImportDataModel; -import org.eclipse.jst.j2ee.internal.web.operations.WebProjectInfo; -import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit; -import org.eclipse.jst.j2ee.webapplication.WebApp; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - - - -public class WebModuleExtensionImpl extends EarModuleExtensionImpl implements WebModuleExtension { - - /** - * - */ - public WebModuleExtensionImpl() { - super(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.WebModuleExtension#createProjectInfo() - */ - public J2EEJavaProjectInfo createProjectInfo() { - // TODO Auto-generated method stub - return null; - } - - public void initializeEjbReferencesToModule(J2EENature moduleNature, UpdateModuleReferencesInEARProjectCommand command) { -// WebEditModel editModel; -// try { -// editModel = ((J2EEWebNatureRuntime) moduleNature).getWebAppEditModelForWrite(this); -// } catch (Exception e) { -// return; -// } - WebArtifactEdit webEdit = null; - WebApp webApp = null; - try{ - //TODO migrate to flex project - //webEdit = (WebArtifactEdit) StructureEdit.getFirstArtifactEditForRead( moduleNature.getProject()); - if(webEdit != null) - webApp = (WebApp) webEdit.getDeploymentDescriptorRoot(); - if (webApp != null) { - command.initializeEjbReferencesToModule(webApp.getEjbRefs()); - command.initializeEjbReferencesToModule(webApp.getEjbLocalRefs()); - } - } finally{ - if( webEdit != null ) - webEdit.dispose(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.WebModuleExtension#addWLPProjects(org.eclipse.core.resources.IProject, - * java.util.Set) - */ - public void addWLPProjects(IProject aProject, Set projectsToBuild) { -// J2EEWebNatureRuntime nature = J2EEWebNatureRuntime.getRuntime(aProject); -// if (nature == null) -// return; -// ILibModule[] libModules = nature.getLibModules(); -// for (int i = 0; i < libModules.length; i++) { -// IProject p = libModules[i].getProject(); -// if (p.isAccessible()) -// projectsToBuild.add(libModules[i].getProject()); -// } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.WebModuleExtension#createWebProjectInfo(org.eclipse.jst.j2ee.internal.internal.commonarchivecore.Archive) - */ - public J2EEJavaProjectInfo createWebProjectInfo(Archive anArchive) { - WebProjectInfo info = new WebProjectInfo(); - //Moved this code below to EARProjectSaveStrategyImpl, to defer the - // work - //and avoid hangs in the wizard right after finish pressed - /* - * boolean isVersion2_2 = !ArchiveUtil.isJ2EE13FastCheck((WARFile)anArchive); if - * (isVersion2_2) { info.setJSPLevel(IJ2EEWebNature.JSPLEVEL_1_1); - * info.setServletLevel(IJ2EEWebNature.SERVLETLEVEL_2_2); - */ - return info; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.WebModuleExtension#setContextRootForModuleMapping(org.eclipse.jst.j2ee.internal.internal.application.WebModule, - * org.eclipse.core.resources.IProject) - */ - public void setContextRootForModuleMapping(WebModule webModule, IProject nestedProject) throws CoreException { - WebArtifactEdit webEdit = null; - try{ - //TODO migrate to flex project - //webEdit = (WebArtifactEdit) StructureEdit.getFirstArtifactEditForRead( nestedProject ); - if(webEdit != null) { - webEdit.setServerContextRoot(webModule.getContextRoot()); - } - } finally{ - if( webEdit != null ) - webEdit.dispose(); - } -// if (wnr != null) { -// wnr.setContextRoot(webModule.getContextRoot()); -// } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.WebModuleExtension#hasRuntime(org.eclipse.core.resources.IProject) - */ - public boolean hasRuntime(IProject project) { - //return J2EEWebNatureRuntimeUtilities.hasJ2EERuntime(project); - //To do: work based on module - return false; - } - - // public J2EEImportOperationOLD createImportOperation(IProject - // nestedProject, WARFile warFile, EARImportConfiguration importConfig){ - // WarImportOperation op = new WarImportOperation(nestedProject, warFile); - // //op.setServerTarget(info.getServerTarget()); - // HashMap opMap = importConfig.createProjectOption; - // if(opMap != null && !opMap.isEmpty()) - // op.createWLProjectOptions = opMap; - // return op; - // } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.WebModuleExtension#getContentFolder(org.eclipse.core.resources.IProject, - * org.eclipse.jst.j2ee.internal.internal.commonarchivecore.File) - */ - - public String getContentFolder(IProject project, IFile webSettingsFile) { - String contentFolder = null; - -// WebSettings webSettings = new WebSettings(project, webSettingsFile); -// if (webSettings != null) { -// contentFolder = webSettings.getWebContentName(); -// } - //To do: Needs work here, no content folder exists now - WebArtifactEdit webEdit = null; - try{ - //TODO migrate to flex project - //webEdit = (WebArtifactEdit) StructureEdit.getFirstArtifactEditForRead(project); - if(webEdit != null) { - - } - } finally { - if( webEdit != null ) - webEdit.dispose(); - } - - return contentFolder; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.WebModuleExtension#compareWebContextRoot(org.eclipse.jst.j2ee.internal.internal.application.Module, - * org.eclipse.core.resources.IProject) - */ - public boolean compareWebContextRoot(Module module, IProject project) throws CoreException { - String contextRoot = ((WebModule) module).getContextRoot(); - if (contextRoot != null) - return ((contextRoot).equals(getServerContextRoot(project))); - return false; - } - - protected String getServerContextRoot(IProject project) { - WebArtifactEdit webEdit = null; - try{ - //TODO migrate to flex project - //webEdit = (WebArtifactEdit) StructureEdit.getFirstArtifactEditForRead(project); - if(webEdit != null) { - return webEdit.getServerContextRoot(); - } - } finally { - if( webEdit != null ) - webEdit.dispose(); - } - return ""; //$NON-NLS-1$ - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.EarModuleExtension#createProjectCreationOperation(org.eclipse.jst.j2ee.internal.internal.application.operations.J2EEModuleCreationDataModel) - */ - public J2EEComponentCreationOperation createProjectCreationOperation(J2EEComponentCreationDataModel dataModel) { - return new WebComponentCreationOperation((WebComponentCreationDataModel) dataModel); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.EarModuleExtension#createProjectDataModel() - */ - public IDataModel createProjectDataModel() { - return DataModelFactory.createDataModel(new WebComponentCreationDataModelProvider()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.EarModuleExtension#createImportDataModel() - */ - public J2EEModuleImportDataModel createImportDataModel() { - return new WebModuleImportDataModel(); - } - - public String getNatureID() { - return IWebNatureConstants.J2EE_NATURE_ID; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/plugin/WebPlugin.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/plugin/WebPlugin.java deleted file mode 100644 index 665883c9c..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/plugin/WebPlugin.java +++ /dev/null @@ -1,328 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.web.plugin; - -import java.io.IOException; -import java.net.URL; -import java.text.MessageFormat; -import java.util.List; -import java.util.Vector; - -import org.eclipse.core.internal.boot.PlatformURLConnection; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceStatus; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IAdapterManager; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.common.util.ResourceLocator; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPluginResourceHandler; -import org.eclipse.jst.j2ee.internal.web.operations.WebContentResourceChangeListener; -import org.eclipse.jst.j2ee.internal.web.taglib.ITaglibRegistryManager; -import org.eclipse.jst.j2ee.internal.web.taglib.TaglibRegistryManager; -import org.eclipse.jst.j2ee.internal.web.util.WebEditAdapterFactory; -import org.eclipse.jst.j2ee.internal.webapplication.impl.WebAppResourceFactory; -import org.eclipse.wst.common.componentcore.internal.ArtifactEditModel; -import org.eclipse.wst.common.componentcore.internal.impl.WTPResourceFactoryRegistry; -import org.eclipse.wst.common.frameworks.internal.WTPPlugin; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; - - -/** - * This is a top-level class of the j2ee plugin. - * - */ - -public class WebPlugin extends WTPPlugin implements ResourceLocator { - // Default instance of the receiver - private static WebPlugin inst; - protected final IPath iconsFolder = new Path(Platform.getBundle(PLUGIN_ID).getEntry("icons").getPath()); //$NON-NLS-1$ - // Links View part of the plugin - //public static final String LINKS_BUILDER_ID = - // "com.ibm.etools.links.management.linksbuilder";//$NON-NLS-1$ - public static final String LINKS_BUILDER_ID = "com.ibm.etools.webtools.additions.linksbuilder"; //$NON-NLS-1$ - // LibDir Change Listener - public static final String LIBDIRCHANGE_BUILDER_ID = "com.ibm.etools.webtools.LibDirBuilder"; //$NON-NLS-1$ - public static final String PLUGIN_ID = "org.eclipse.jst.j2ee.web"; //$NON-NLS-1$ - // LibCopy builder ID - public static final String LIBCOPY_BUILDER_ID = "org.eclipse.jst.j2ee.LibCopyBuilder"; //$NON-NLS-1$ - // Validation part of the plugin - //Global ResourceSet (somewhat global) - protected ITaglibRegistryManager taglibRegistryManager; - private static IPath location; - private IResourceChangeListener fWebContentListener; - - public static final String[] ICON_DIRS = new String[]{"icons/full/obj16", //$NON-NLS-1$ - "icons/full/cview16", //$NON-NLS-1$ - "icons/full/ctool16", //$NON-NLS-1$ - "icons/full/clcl16", //$NON-NLS-1$ - "icons/full/ovr16", //$NON-NLS-1$ - "icons/full/extra", //$NON-NLS-1$ - "icons/full/wizban", //$NON-NLS-1$ - "icons", //$NON-NLS-1$ - ""}; //$NON-NLS-1$ - - /** - * Create the J2EE plugin and cache its default instance - */ - public WebPlugin() { - super(); - if (inst == null) - inst = this; - } - - /** - * Get the plugin singleton. - */ - static public WebPlugin getDefault() { - return inst; - } - - /* - * Javadoc copied from interface. - */ - public URL getBaseURL() { - return getBundle().getEntry("/"); //$NON-NLS-1$ - } - - public Object[] getJ2EEWebProjectMigrationExtensions() { - - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint pct = registry.getExtensionPoint(getBundle().getSymbolicName(), "J2EEWebProjectMigrationExtension"); //$NON-NLS-1$ - - IExtension[] extension = pct.getExtensions(); - List ret = new Vector(); - for (int l = 0; l < extension.length; ++l) { - IExtension config = extension[l]; - - IConfigurationElement[] cElems = config.getConfigurationElements(); - for (int i = 0; i < cElems.length; i++) { - IConfigurationElement d = cElems[i]; - if (d.getName().equals("migration")) { //$NON-NLS-1$ - try { - Object me = d.createExecutableExtension("run"); //$NON-NLS-1$ - - ret.add(me); - } catch (Exception ex) { - // ignore this extension, keep going - } - } - } - } - - return ret.toArray(); - } - - /** - * This gets a .gif from the icons folder. - */ - public Object getImage(String key) { - return J2EEPlugin.getImageURL(key, getBundle()); - } - - public static IPath getInstallLocation() { - if (location == null) { - URL url = getInstallURL(); - try { - String installLocation = ((PlatformURLConnection) url.openConnection()).getURLAsLocal().getFile(); - location = new Path(installLocation); - } catch (IOException e) { - org.eclipse.jem.util.logger.proxy.Logger.getLogger().logWarning(J2EEPluginResourceHandler.getString("Install_Location_Error_", new Object[]{url}) + e); //$NON-NLS-1$ - } - } - return location; - } - - public static URL getInstallURL() { - return getDefault().getBundle().getEntry("/"); //$NON-NLS-1$ - } - - /** - * Get the singleton instance. - */ - public static WebPlugin getPlugin() { - return inst; - } - - /** - * Return the plugin directory location- the directory that all the plugins are located in (i.e. - * d:\installdir\plugin) - */ - public static IPath getPluginLocation(String pluginId) { - IExtensionRegistry registry = Platform.getExtensionRegistry(); - Bundle bundle = Platform.getBundle(pluginId); - if (bundle != null) { - try { - IPath installPath = new Path(bundle.getEntry("/").toExternalForm()).removeTrailingSeparator(); //$NON-NLS-1$ - String installStr = Platform.asLocalURL(new URL(installPath.toString())).getFile(); - return new Path(installStr); - } catch (IOException e) { - //Do nothing - } - } - return null; - } - - /** - * Return the Servlets Jar file path preference. - * - * @return String the file path to the servlets jar, or null if never specified. - * @deprecated - the preference store is no longer on this plugin because of the UI dependency. - */ - public String getPreferenceServletsJar() { - // return getPreferenceStore().getString(IWebToolingCoreConstants.PROP_SERVLET_JAR); - return "THIS IS THE WRONG PATH - NEED TO CHANGE IMPLEMENTATION!!!!!"; //$NON-NLS-1$ - } - - /** - * Return the Servlets Jar file path preference. - * - * @return String the file path to the servlets jar, or null if never specified. - * @deprecated - the preference store is no longer on this plugin because of the UI dependency. - */ - public String getPreferenceWebASJar() { - //return getPreferenceStore().getString(IWebToolingCoreConstants.PROP_WEBAS_JAR); - return "THIS IS THE WRONG PATH - NEED TO CHANGE IMPLEMENTATION!!!!!"; //$NON-NLS-1$ - } - - public ITaglibRegistryManager getTaglibRegistryManager() { - if (this.taglibRegistryManager == null) - this.taglibRegistryManager = createTaglibRegistryManager(); - return this.taglibRegistryManager; - } - - public static IWorkspace getWorkspace() { - return ResourcesPlugin.getWorkspace(); - } - - /** - * If this is called from an operation, in response to some other exception that was caught, - * then the client code should throw {@link com.ibm.etools.wft.util.WFTWrappedException}; - * otherwise this can still be used to signal some other error condition within the operation, - * or to throw a core exception in a context other than executing an operation - * - * Create a new IStatus of type ERROR using the J2EEPlugin ID. aCode is just an internal code. - */ - public static IStatus newErrorStatus(int aCode, String aMessage, Throwable exception) { - return newStatus(IStatus.ERROR, aCode, aMessage, exception); - } - - /** - * If this is called from an operation, in response to some other exception that was caught, - * then the client code should throw {@link com.ibm.etools.wft.util.WFTWrappedException}; - * otherwise this can still be used to signal some other error condition within the operation, - * or to throw a core exception in a context other than executing an operation - * - * Create a new IStatus of type ERROR, code OPERATION_FAILED, using the J2EEPlugin ID - */ - public static IStatus newErrorStatus(String aMessage, Throwable exception) { - return newErrorStatus(0, aMessage, exception); - } - - /** - * If this is called from an operation, in response to some other exception that was caught, - * then the client code should throw {@link com.ibm.etools.wft.util.WFTWrappedException}; - * otherwise this can still be used to signal some other error condition within the operation. - * - * Create a new IStatus of type ERROR, code OPERATION_FAILED, using the J2EEPlugin ID - */ - public static IStatus newOperationFailedStatus(String aMessage, Throwable exception) { - return newStatus(IStatus.ERROR, IResourceStatus.OPERATION_FAILED, aMessage, exception); - } - - /** - * Create a new IStatus with a severity using the J2EEPlugin ID. aCode is just an internal code. - */ - public static IStatus newStatus(int severity, int aCode, String aMessage, Throwable exception) { - return new Status(severity, PLUGIN_ID, aCode, aMessage, exception); - } - - /* - * Javadoc copied from interface. - */ - public String getString(String key) { - return Platform.getResourceString(getBundle(), key); - } - - /* - * Javadoc copied from interface. - */ - public String getString(String key, Object[] substitutions) { - return MessageFormat.format(getString(key), substitutions); - } - - /* - * Add the web content listener. This listener is used to detect when a web project's web - * content folder has been renamed. - */ - private void addWebContentListener() { - this.fWebContentListener = new WebContentResourceChangeListener(); - getWorkspace().addResourceChangeListener(this.fWebContentListener, IResourceChangeEvent.PRE_BUILD); - } - - /* - * Remove the web content listener. - */ - private void removeWebContentListener() { - if (this.fWebContentListener != null) { - if (getWorkspace() == null) - return; - getWorkspace().removeResourceChangeListener(this.fWebContentListener); - this.fWebContentListener = null; - } - } - - - - public void stop(BundleContext context) throws Exception { - super.stop(context); - if (this.taglibRegistryManager != null) - this.taglibRegistryManager.dispose(); - - // remove listener for web content changes - removeWebContentListener(); - } - - protected ITaglibRegistryManager createTaglibRegistryManager() { - return new TaglibRegistryManager(); - } - - public void start(BundleContext context) throws Exception { - super.start(context); - // register the listener for link refactoring of moved/renamed files - // add listener for web content changes - addWebContentListener(); - WebAppResourceFactory.register(WTPResourceFactoryRegistry.INSTANCE); - IAdapterManager manager = Platform.getAdapterManager(); - manager.registerAdapters(new WebEditAdapterFactory(), ArtifactEditModel.class); - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.frameworks.internal.WTPPlugin#getPluginID() - */ - public String getPluginID() { - return PLUGIN_ID; - } -}
\ No newline at end of file |