[jbosstools-commits] JBoss Tools SVN: r42381 - in trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb: include and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Tue Jul 3 19:03:36 EDT 2012


Author: scabanovich
Date: 2012-07-03 19:03:36 -0400 (Tue, 03 Jul 2012)
New Revision: 42381

Added:
   trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeModel.java
   trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/PageInclude.java
Modified:
   trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java
   trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/FaceletPageContextImpl.java
Log:
JBIDE-3526
https://issues.jboss.org/browse/JBIDE-3526
Vars are loaded from ui:param.





Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java	2012-07-03 23:02:25 UTC (rev 42380)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java	2012-07-03 23:03:36 UTC (rev 42381)
@@ -10,6 +10,7 @@
  ******************************************************************************/ 
 package org.jboss.tools.jst.web.kb;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
@@ -24,6 +25,7 @@
 import org.eclipse.core.filebuffers.FileBuffers;
 import org.eclipse.core.filebuffers.ITextFileBuffer;
 import org.eclipse.core.internal.resources.ICoreConstants;
+import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
@@ -74,6 +76,7 @@
 import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
 import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
 import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
 import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
 import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
 import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
@@ -93,7 +96,10 @@
 import org.jboss.tools.common.util.EclipseUIUtil;
 import org.jboss.tools.common.util.FileUtil;
 import org.jboss.tools.common.validation.ValidationELReference;
+import org.jboss.tools.jst.web.WebUtils;
 import org.jboss.tools.jst.web.kb.include.IncludeContextBuilder;
+import org.jboss.tools.jst.web.kb.include.IncludeModel;
+import org.jboss.tools.jst.web.kb.include.PageInclude;
 import org.jboss.tools.jst.web.kb.internal.FaceletPageContextImpl;
 import org.jboss.tools.jst.web.kb.internal.JspContextImpl;
 import org.jboss.tools.jst.web.kb.internal.ResourceBundle;
@@ -415,6 +421,10 @@
 									// Fill JSP namespaces defined in TLDCMDocumentManager 
 									fillJSPNameSpaces((JspContextImpl)context, document);
 								}
+								
+								if(file != null) {
+									IncludeModel.getInstance().clean(file.getFullPath());
+								}
 								// The subsequently called functions may use the file and document
 								// already stored in context for their needs
 								fillContextForChildNodes(model.getStructuredDocument(), domDocument, context, parents);
@@ -604,6 +614,9 @@
 		}
 
 		if (context instanceof FaceletPageContextImpl) {
+			if(node instanceof IDOMElement && context.getResource() != null && context.getResource().exists()) {
+				fillUIParamsForNode((IDOMElement)node, (ELContextImpl)context);
+			}
 			// Insert here the initialization code for FaceletPage context elements which may exist in Text nodes
 		}
 
@@ -633,6 +646,88 @@
 		}
 	}
 
+	private static void fillUIParamsForNode(IDOMElement node, ELContextImpl context) {
+		String ATTR_SRC = "src"; //$NON-NLS-1$
+		String NODE_PARAM = "param"; //$NON-NLS-1$
+		String ATTR_NAME = "name"; //$NON-NLS-1$
+		String ATTR_VALUE = "value"; //$NON-NLS-1$
+		if(IncludeContextBuilder.TAG_INCLUDE.equals(node.getLocalName()) && CustomTagLibManager.FACELETS_UI_TAG_LIB_URI.equals(node.getNamespaceURI())) {
+			String src = node.getAttribute(ATTR_SRC);
+			if(src == null || src.trim().length() == 0) {
+				return;
+			}
+			IFile includedFile = getFile(src, context.getResource());
+			if(includedFile == null) return;
+			NodeList list = node.getElementsByTagNameNS (CustomTagLibManager.FACELETS_UI_TAG_LIB_URI, NODE_PARAM);
+			List<Var> vars = null;
+			for (int i = 0; i < list.getLength(); i++) {
+				Node n = list.item(i);
+				if(n instanceof IDOMElement) {
+					IDOMElement element = (IDOMElement)n;
+					synchronized (element) {
+						if(element.hasAttribute(ATTR_NAME)) {
+							String var = element.getAttribute(ATTR_NAME);
+							int declOffset = 0;
+							int declLength = 0;
+							Node varAttr = element.getAttributeNode(ATTR_NAME); 
+							if (varAttr instanceof IDOMAttr) {
+								int varNameStart = ((IDOMAttr)varAttr).getNameRegionStartOffset();
+								int varNameEnd = ((IDOMAttr)varAttr).getNameRegionEndOffset();
+								declOffset = varNameStart;
+								declLength = varNameEnd - varNameStart;
+							}
+							var = var.trim();
+							if(!"".equals(var)) { //$NON-NLS-1$					
+								if(element.hasAttribute(ATTR_VALUE)) {
+									String value = element.getAttribute(ATTR_VALUE);
+									value = value.trim();
+									Var newVar = new Var(ELParserUtil.getJbossFactory(), var, value, declOffset, declLength);
+									if(newVar.getElToken()!=null) {
+										if(vars == null) {
+											vars = new ArrayList<Var>();
+										}
+										vars.add(newVar);
+									}
+								}
+							}
+						}
+					}
+				}
+			}
+			if(!vars.isEmpty()) {
+				PageInclude include = new PageInclude(context.getResource().getFullPath(), includedFile.getFullPath(), vars);
+				IncludeModel.getInstance().addInclude(context.getResource().getFullPath(), include);
+			}
+		}	
+	}
+
+	public static IFile getFile(String fileName, IFile includeFile) {
+		IFile file = null;
+		if (fileName.startsWith("/")) { //$NON-NLS-1$
+			IContainer[] webRootFolders = WebUtils.getWebRootFolders(includeFile.getProject());
+			if (webRootFolders.length > 0) {
+				for (IContainer webRootFolder : webRootFolders) {
+					IFile handle = webRootFolder.getFile(new Path(fileName));
+					if (handle.exists()) {
+						file = handle;
+						break;
+					}
+				}
+			} else {
+				file = resolveRelatedPath(includeFile, fileName); // ?
+			}
+		} else {
+			file = resolveRelatedPath(includeFile, fileName);
+		}
+		return file;
+	}	
+	private static IFile resolveRelatedPath(IFile baseFile,
+			String relatedFilePath) {
+		IPath currentFolder = baseFile.getParent().getFullPath();
+		IPath path = currentFolder.append(relatedFilePath);
+		return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+	}
+
 	private static void fillElReferencesForNode(IDocument document, IDOMNode node, XmlContextImpl context) {
 		IStructuredDocumentRegion regionNode = node.getFirstStructuredDocumentRegion(); 
 		if (regionNode == null) return;

Added: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeModel.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeModel.java	                        (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeModel.java	2012-07-03 23:03:36 UTC (rev 42381)
@@ -0,0 +1,83 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is 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: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+package org.jboss.tools.jst.web.kb.include;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IPath;
+import org.jboss.tools.common.el.core.resolver.Var;
+
+/**
+ * 
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class IncludeModel {
+
+	private final static IncludeModel instance = new IncludeModel();
+
+	public static IncludeModel getInstance() {
+		return instance;
+	}
+
+	private Map<IPath, List<PageInclude>> directReferences = new HashMap<IPath, List<PageInclude>>();
+	private Map<IPath, List<PageInclude>> parentReferences = new HashMap<IPath, List<PageInclude>>();
+
+	private IncludeModel() {}
+
+	public synchronized void clean(IPath parent) {
+		List<PageInclude> old = directReferences.remove(parent);
+		if(old != null && !old.isEmpty()) {
+			for (IPath child: parentReferences.keySet()) {
+				Iterator<PageInclude> is = parentReferences.get(child).iterator();
+				while(is.hasNext()) {
+					PageInclude i = is.next();
+					if(i.getParent().equals(parent)) {
+						is.remove();
+					}
+				}
+			}
+		}
+	}
+
+	public synchronized void addInclude(IPath parent, PageInclude include) {
+		List<PageInclude> current = directReferences.get(parent);
+		if(current == null) {
+			current = new ArrayList<PageInclude>();
+			directReferences.put(parent, current);
+		}
+		current.add(include);
+		IPath child = include.getPath();
+		List<PageInclude> is = parentReferences.get(child);
+		if(is == null) {
+			is = new ArrayList<PageInclude>();
+			parentReferences.put(child, is);
+		}
+		is.add(include);
+	}
+
+	public synchronized List<Var> getVars(IPath page) {
+		List<Var> result = new ArrayList<Var>();
+		List<PageInclude> is = parentReferences.get(page);
+		if(is != null) {
+			for (PageInclude i: is) {
+				result.addAll(i.getVars());
+			}
+		}
+		return result;
+	}
+	
+
+}


Property changes on: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeModel.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/PageInclude.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/PageInclude.java	                        (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/PageInclude.java	2012-07-03 23:03:36 UTC (rev 42381)
@@ -0,0 +1,45 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is 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: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+package org.jboss.tools.jst.web.kb.include;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.jboss.tools.common.el.core.resolver.Var;
+
+/**
+ * 
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class PageInclude {
+	IPath parent;
+	IPath path;
+	List<Var> vars;
+
+	public PageInclude(IPath parent, IPath path, List<Var> vars) {
+		this.parent = parent;
+		this.path = path;
+		this.vars = vars;
+	}
+
+	public IPath getParent() {
+		return parent;
+	}
+
+	public IPath getPath() {
+		return path;
+	}
+
+	public List<Var> getVars() {
+		return vars;
+	}
+}


Property changes on: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/PageInclude.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/FaceletPageContextImpl.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/FaceletPageContextImpl.java	2012-07-03 23:02:25 UTC (rev 42380)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/FaceletPageContextImpl.java	2012-07-03 23:03:36 UTC (rev 42381)
@@ -10,9 +10,12 @@
  ******************************************************************************/ 
 package org.jboss.tools.jst.web.kb.internal;
 
+import java.util.List;
 import java.util.Map;
 
+import org.jboss.tools.common.el.core.resolver.Var;
 import org.jboss.tools.jst.web.kb.IFaceletPageContext;
+import org.jboss.tools.jst.web.kb.include.IncludeModel;
 
 /**
  * Facelet page context
@@ -23,6 +26,11 @@
 	private IFaceletPageContext parentContext;
 	private Map<String, String> params;
 
+	public List<Var> getExternalVars() {
+		List<Var> res = IncludeModel.getInstance().getVars(getResource().getFullPath());
+		return res == null ? super.getExternalVars() : res;
+	}
+
 	/* (non-Javadoc)
 	 * @see org.jboss.tools.jst.web.kb.IFaceletPageContext#getParams()
 	 */



More information about the jbosstools-commits mailing list