summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbateman2013-04-01 14:57:10 (EDT)
committercbateman2013-04-08 21:15:36 (EDT)
commitce51c5139d280671f84c64edd5862f3e08c8be8b (patch)
treebaa732f95566b5321b236c075785d342b91b85a5
parentb5e6517f30892caf2566fa05d1b6c5a73acef2d9 (diff)
downloadwebtools.jsf-ce51c5139d280671f84c64edd5862f3e08c8be8b.zip
webtools.jsf-ce51c5139d280671f84c64edd5862f3e08c8be8b.tar.gz
webtools.jsf-ce51c5139d280671f84c64edd5862f3e08c8be8b.tar.bz2
PMC approved fix for 404418 (see patch).
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/cm/attributevalues/TemplateWebPathType.java130
1 files changed, 51 insertions, 79 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/cm/attributevalues/TemplateWebPathType.java b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/cm/attributevalues/TemplateWebPathType.java
index 572d7d5..ea81dbb 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/cm/attributevalues/TemplateWebPathType.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/cm/attributevalues/TemplateWebPathType.java
@@ -19,6 +19,8 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.jsf.common.internal.componentcore.AbstractCompCoreQueryFactory;
+import org.eclipse.jst.jsf.common.internal.componentcore.AbstractVirtualComponentQuery;
import org.eclipse.jst.jsf.context.resolver.structureddocument.IDOMContextResolver;
import org.eclipse.jst.jsf.context.resolver.structureddocument.IStructuredDocumentContextResolverFactory;
import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext;
@@ -26,9 +28,7 @@ import org.eclipse.jst.jsf.facelet.core.internal.FaceletCorePlugin;
import org.eclipse.jst.jsf.metadataprocessors.features.IPossibleValues;
import org.eclipse.jst.jsf.metadataprocessors.features.PossibleValue;
import org.eclipse.jst.jsf.taglibprocessing.attributevalues.WebPathType;
-import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualContainer;
-import org.eclipse.wst.common.componentcore.resources.IVirtualResource;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
@@ -38,27 +38,22 @@ import org.w3c.dom.Node;
* @author cbateman
*
*/
-public class TemplateWebPathType extends WebPathType implements IPossibleValues
-{
+public class TemplateWebPathType extends WebPathType implements IPossibleValues {
- public List getPossibleValues()
- {
+ public List getPossibleValues() {
final IStructuredDocumentContext context = getStructuredDocumentContext();
final IDOMContextResolver resolver = IStructuredDocumentContextResolverFactory.INSTANCE
.getDOMContextResolver(context);
- if (resolver != null)
- {
+ if (resolver != null) {
final Node node = resolver.getNode();
- if (node instanceof Attr)
- {
+ if (node instanceof Attr) {
return createPossibleValues((Attr) node);
}
}
return Collections.EMPTY_LIST;
}
- private List createPossibleValues(final Attr node)
- {
+ private List createPossibleValues(final Attr node) {
String currentPathString = node.getNodeValue();
final List possibleValues = new ArrayList();
@@ -72,95 +67,70 @@ public class TemplateWebPathType extends WebPathType implements IPossibleValues
final IVirtualContainer webRoot = getWebRoot();
- final IVirtualResource deepestElement = findDeepestCommonElement(
- currentPath, webRoot);
-
- if (deepestElement == null)
+ if (webRoot == null)
{
+ return possibleValues;
+ }
+
+ final IResource deepestElement = findDeepestCommonElement(currentPath,
+ (IContainer) webRoot.getUnderlyingResource());
+
+ if (deepestElement == null) {
// empty
return possibleValues;
}
- final IResource[] allResources = deepestElement
- .getUnderlyingResources();
- for (final IResource res : allResources)
- {
- if (res instanceof IContainer)
- {
- try
- {
- for (final IResource child : ((IContainer) res).members())
- {
- if (child.exists())
- {
- IPath childPath = child.getProjectRelativePath();
- int numLeadingSegments = webRoot
- .getProjectRelativePath()
- .matchingFirstSegments(childPath);
- childPath = childPath
- .removeFirstSegments(numLeadingSegments);
- String pathName = null;
- if (currentPath.isAbsolute())
- {
- pathName = childPath.makeAbsolute()
- .toString();
- }
- else
- {
- pathName = childPath.makeRelative().toString();
- }
-
- final PossibleValue pv = new PossibleValue(
- pathName, pathName);
- possibleValues.add(pv);
+ if (deepestElement instanceof IContainer) {
+ try {
+ for (final IResource child : ((IContainer) deepestElement).members()) {
+ if (child.exists()) {
+ IPath childPath = child.getProjectRelativePath();
+ int numLeadingSegments = webRoot.getProjectRelativePath().matchingFirstSegments(childPath);
+ childPath = childPath.removeFirstSegments(numLeadingSegments);
+ String pathName = null;
+ if (currentPath.isAbsolute()) {
+ pathName = childPath.makeAbsolute().toString();
+ } else {
+ pathName = childPath.makeRelative().toString();
}
+
+ final PossibleValue pv = new PossibleValue(pathName, pathName);
+ possibleValues.add(pv);
}
}
- catch (final CoreException ce)
- {
- FaceletCorePlugin.log("While trying possible values", ce); //$NON-NLS-1$
- }
+ } catch (final CoreException ce) {
+ FaceletCorePlugin.log("While trying possible values", ce); //$NON-NLS-1$
}
}
return possibleValues;
}
- private IVirtualResource findDeepestCommonElement(
- final IPath currentPath, final IVirtualContainer webRoot)
- {
+ private IResource findDeepestCommonElement(final IPath currentPath, final IContainer webRoot) {
final String[] segments = currentPath.segments();
- IVirtualResource deepestElement = null;
- if (segments != null)
- {
+ IResource deepestElement = null;
+ if (segments != null) {
IPath longestSubPath = new Path(""); //$NON-NLS-1$
- for (final String segment : segments)
- {
+ for (final String segment : segments) {
longestSubPath = longestSubPath.append(segment);
deepestElement = webRoot.findMember(longestSubPath);
- if (deepestElement == null)
- {
+ if (deepestElement == null) {
longestSubPath = longestSubPath.removeLastSegments(1);
break;
}
}
deepestElement = webRoot.findMember(longestSubPath);
- if (deepestElement == null)
- {
+ if (deepestElement == null) {
deepestElement = webRoot;
- }
- else
- {
+ } else {
int avoidInfiniteLoopCount = 0;
- while(avoidInfiniteLoopCount < 1000 && // we timeout in cause of circular chains.
- deepestElement != null &&
- ! (deepestElement.getUnderlyingResource() instanceof IContainer))
- {
+ while (avoidInfiniteLoopCount < 1000 && // we timeout in cause
+ // of circular chains.
+ deepestElement != null && !(deepestElement instanceof IContainer)) {
deepestElement = deepestElement.getParent();
}
-
- if (avoidInfiniteLoopCount == 1000)
- {
+
+ if (avoidInfiniteLoopCount == 1000) {
throw new IllegalStateException();
}
}
@@ -169,11 +139,13 @@ public class TemplateWebPathType extends WebPathType implements IPossibleValues
}
private IVirtualContainer getWebRoot()
-
{
- final IVirtualContainer webRoot = ComponentCore.createComponent(
- getProject()).getRootFolder();
-
- return webRoot;
+ AbstractCompCoreQueryFactory compCoreQueryFactory = FaceletCorePlugin.getDefault().getCompCoreQueryFactory();
+ AbstractVirtualComponentQuery virtualComponentQuery = compCoreQueryFactory.createVirtualComponentQuery(getProject());
+ if (virtualComponentQuery != null)
+ {
+ return virtualComponentQuery.getWebContentFolder(getProject());
+ }
+ return null;
}
}