Skip to content

Commit

Permalink
Version 2.0.9: Look for AppModule between all filters in web.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrygusev committed Nov 21, 2013
1 parent 397a771 commit 0a607bd
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 141 deletions.
2 changes: 1 addition & 1 deletion com.anjlab.eclipse.e4.tapestry5.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="com.anjlab.eclipse.e4.tapestry5.feature"
label="Additional Tapestry5 Support for Eclipse4"
version="2.0.8"
version="2.0.9"
provider-name="AnjLab Team"
plugin="com.anjlab.eclipse.e4.tapestry5">

Expand Down
2 changes: 1 addition & 1 deletion com.anjlab.eclipse.e4.tapestry5/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Additional Tapestry5 Support for Eclipse4
Bundle-SymbolicName: com.anjlab.eclipse.e4.tapestry5;singleton:=true
Bundle-Version: 2.0.8
Bundle-Version: 2.0.9
Bundle-Activator: com.anjlab.eclipse.e4.tapestry5.Activator
Bundle-Vendor: AnjLab Team
Require-Bundle: org.eclipse.ui,
Expand Down
2 changes: 1 addition & 1 deletion com.anjlab.eclipse.tapestry5.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="com.anjlab.eclipse.tapestry5.feature"
label="Basic Tapestry5 Support (required)"
version="2.0.8"
version="2.0.9"
provider-name="AnjLab Team"
plugin="com.anjlab.eclipse.tapestry5">

Expand Down
2 changes: 1 addition & 1 deletion com.anjlab.eclipse.tapestry5/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Basic Tapestry5 Support (required)
Bundle-SymbolicName: com.anjlab.eclipse.tapestry5;singleton:=true
Bundle-Version: 2.0.8
Bundle-Version: 2.0.9
Bundle-Activator: com.anjlab.eclipse.tapestry5.Activator
Bundle-Vendor: AnjLab Team
Require-Bundle: org.eclipse.ui,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.anjlab.eclipse.tapestry5.watchdog.TapestryContextWatchdog;
import com.anjlab.eclipse.tapestry5.watchdog.TapestryProjectWatchdog;
import com.anjlab.eclipse.tapestry5.watchdog.WebXmlWatchdog;
import com.anjlab.eclipse.tapestry5.watchdog.WebXmlWatchdog.WebXml;

/**
* The activator class controls the plug-in life cycle
Expand Down Expand Up @@ -170,26 +171,9 @@ public void removeTapestryContextListener(IWorkbenchWindow window, ITapestryCont
tapestryContextWatchdog.removeTapestryContextListener(window, listener);
}

public String getWebXmlPropertyValue(IProject project, String propertyName)
public WebXml getWebXml(IProject project)
{
return webXmlWatchdog.getWebXmlCache(project).get(propertyName);
}

public String getWebXmlPropertyName(IProject project, String propertyName)
{
Map<String, String> cache = webXmlWatchdog.getWebXmlCache(project);

for (String key : cache.keySet())
{
String value = cache.get(key);

if (propertyName.equals(value))
{
return key;
}
}

return null;
return webXmlWatchdog.getWebXmlCache(project);
}

public TapestryProject getTapestryProject(IWorkbenchWindow window)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.jdt.core.JavaModelException;

import com.anjlab.eclipse.tapestry5.TapestryModule.ModuleReference;
import com.anjlab.eclipse.tapestry5.watchdog.WebXmlWatchdog.WebXml;

public class TapestryProject
{
Expand Down Expand Up @@ -60,25 +61,39 @@ private synchronized void findModules(IProgressMonitor monitor)
modules = new ArrayList<TapestryModule>();

String appPackage = TapestryUtils.getAppPackage(project);
String appName = TapestryUtils.getAppName(project);

if (appName == null || appPackage == null)
if (appPackage == null)
{
return;
}

TapestryModule appModule = addModule(monitor, modules, project, appPackage + ".services." + appName + "Module", new ModuleReference()
TapestryModule appModule = null;

final WebXml webXml = Activator.getDefault().getWebXml(project);

if (webXml == null)
{
@Override
public String getLabel()
{
return "Your Application's Module";
}
});
return;
}

if (appModule != null)
for (String filterName : webXml.getFilterNames())
{
appModule.setAppModule(true);
final String localFilterName = filterName;

appModule = addModule(monitor, modules, project, appPackage + ".services." + filterName + "Module", new ModuleReference()
{
@Override
public String getLabel()
{
return "Your Application's Module (via " + webXml.getFilterClassName(localFilterName) + " in web.xml)";
}
});

if (appModule != null)
{
appModule.setAppModule(true);
break;
}
}

addModule(monitor, modules, project, "org.apache.tapestry5.services.TapestryModule", new ModuleReference()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
Expand Down Expand Up @@ -160,20 +154,14 @@ public static IContainer findWebapp(IProject project)

public static boolean isTapestryAppProject(IProject project)
{
return getAppPackage(project) != null && getAppName(project) != null;
return getAppPackage(project) != null;
}

public static String getAppPackage(IProject project)
{
return Activator.getDefault().getWebXmlPropertyValue(project, TAPESTRY_APP_PACKAGE);
return Activator.getDefault().getWebXml(project).getParamValue(TAPESTRY_APP_PACKAGE);
}

public static String getAppName(IProject project)
{
return Activator.getDefault().getWebXmlPropertyName(
project, "org.apache.tapestry5.TapestryFilter");
}

public static boolean isTapestrySubModuleAnnotation(IAnnotation annotation)
{
return "org.apache.tapestry5.ioc.annotations.SubModule".equals(annotation.getElementName())
Expand Down Expand Up @@ -333,89 +321,6 @@ public static String readToEnd(InputStream stream)
return null;
}

public static Map<String, String> readWebXml(IProject project)
{
Map<String, String> params = new HashMap<String, String>();

IContainer webapp = findWebapp(project);

if (webapp == null)
{
return params;
}

IFile webXml = (IFile) webapp.findMember("/WEB-INF/web.xml");

if (webXml == null)
{
return params;
}

XMLStreamReader reader = null;
InputStream input = null;

try
{
input = webXml.getContents();

reader = Activator.getDefault().getXMLInputFactory()
.createXMLStreamReader(input);

while (nextStartElement(reader))
{
String[] tags = new String[] { "param-name", "param-value",
"filter-name", "filter-class" };

for (int i = 0; i < tags.length; i += 2)
{
if (tags[i].equals(reader.getName().getLocalPart()))
{
String key = reader.getElementText();

if (nextStartElement(reader))
{
if (tags[i+1].equals(reader.getName().getLocalPart()))
{
String value = reader.getElementText();

params.put(key, value);
}
}
}
}
}
}
catch (Exception e)
{
Activator.getDefault().logError("Error reading web.xml", e);
}
finally
{
if (reader != null)
{
try { reader.close(); } catch (Exception e) {}
}
if (input != null)
{
try { input.close(); } catch (Exception e) {}
}
}

return params;
}

private static boolean nextStartElement(XMLStreamReader reader) throws XMLStreamException
{
while (reader.hasNext())
{
if (reader.next() == XMLStreamConstants.START_ELEMENT)
{
return true;
}
}
return false;
}

public static String getSimpleName(String className)
{
String[] parts = className.split("\\.");
Expand Down
Loading

0 comments on commit 0a607bd

Please sign in to comment.