[jbosstools-commits] JBoss Tools SVN: r42415 - 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
Thu Jul 5 14:43:26 EDT 2012
Author: scabanovich
Date: 2012-07-05 14:43:26 -0400 (Thu, 05 Jul 2012)
New Revision: 42415
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IIncludeModel.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/IKbProject.java
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/include/IncludeModel.java
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/KbProject.java
Log:
JBIDE-3526
https://issues.jboss.org/browse/JBIDE-3526
Store/load include model.
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/IKbProject.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/IKbProject.java 2012-07-05 18:27:02 UTC (rev 42414)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/IKbProject.java 2012-07-05 18:43:26 UTC (rev 42415)
@@ -13,6 +13,7 @@
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.IPath;
import org.jboss.tools.common.validation.IProjectValidationContext;
+import org.jboss.tools.jst.web.kb.include.IIncludeModel;
import org.jboss.tools.jst.web.kb.taglib.ITagLibrary;
/**
@@ -50,4 +51,9 @@
* @return validation context which is associated with this KB project.
*/
IProjectValidationContext getValidationContext();
+
+ /**
+ * @return model object that collects <ui:include> elements from pages
+ */
+ IIncludeModel getIncludeModel();
}
\ No newline at end of file
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-05 18:27:02 UTC (rev 42414)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java 2012-07-05 18:43:26 UTC (rev 42415)
@@ -423,7 +423,10 @@
}
if(file != null) {
- IncludeModel.getInstance().clean(file.getFullPath());
+ IKbProject kbProject = KbProjectFactory.getKbProject(project, true);
+ if(kbProject != null) {
+ kbProject.getIncludeModel().clean(file.getFullPath());
+ }
}
// The subsequently called functions may use the file and document
// already stored in context for their needs
@@ -646,11 +649,12 @@
}
}
+ static String ATTR_SRC = "src"; //$NON-NLS-1$
+ static String NODE_PARAM = "param"; //$NON-NLS-1$
+ static String ATTR_NAME = "name"; //$NON-NLS-1$
+ static String ATTR_VALUE = "value"; //$NON-NLS-1$
+
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) {
@@ -695,8 +699,11 @@
}
}
if(vars != null && !vars.isEmpty()) {
- PageInclude include = new PageInclude(context.getResource().getFullPath(), includedFile.getFullPath(), vars);
- IncludeModel.getInstance().addInclude(context.getResource().getFullPath(), include);
+ IKbProject kbProject = KbProjectFactory.getKbProject(context.getResource().getProject(), true);
+ if(kbProject != null) {
+ PageInclude include = new PageInclude(context.getResource().getFullPath(), includedFile.getFullPath(), vars);
+ kbProject.getIncludeModel().addInclude(context.getResource().getFullPath(), include);
+ }
}
}
}
Added: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IIncludeModel.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IIncludeModel.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IIncludeModel.java 2012-07-05 18:43:26 UTC (rev 42415)
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Keeps data from <ui:include> elements.
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public interface IIncludeModel {
+
+ /**
+ * Returns list of parameters defined by <ui:param> nodes to be used at the page with the given path.
+ *
+ * @param page
+ * @return
+ */
+ public List<Var> getVars(IPath path);
+
+ /**
+ * Cleans data collected for the path.
+ *
+ * @param path
+ */
+ public void clean(IPath path);
+
+ /**
+ * Adds to the model data defined by <ui:include> at path.
+ *
+ * @param parent
+ * @param include
+ */
+ public void addInclude(IPath path, PageInclude include);
+
+}
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IIncludeModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: 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 2012-07-05 18:27:02 UTC (rev 42414)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeModel.java 2012-07-05 18:43:26 UTC (rev 42415)
@@ -17,34 +17,32 @@
import java.util.Map;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.jboss.tools.common.el.core.ELReference;
+import org.jboss.tools.common.el.core.parser.ELParserUtil;
import org.jboss.tools.common.el.core.resolver.Var;
+import org.jboss.tools.common.xml.XMLUtilities;
+import org.w3c.dom.Element;
/**
*
* @author Viacheslav Kabanovich
*
*/
-public class IncludeModel {
-
- private final static IncludeModel instance = new IncludeModel();
-
- public static IncludeModel getInstance() {
- return instance;
- }
-
+public class IncludeModel implements IIncludeModel {
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 IncludeModel() {}
- public synchronized void clean(IPath parent) {
- List<PageInclude> old = directReferences.remove(parent);
+ public synchronized void clean(IPath path) {
+ List<PageInclude> old = directReferences.remove(path);
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)) {
+ if(i.getParent().equals(path)) {
is.remove();
}
}
@@ -52,11 +50,11 @@
}
}
- public synchronized void addInclude(IPath parent, PageInclude include) {
- List<PageInclude> current = directReferences.get(parent);
+ public synchronized void addInclude(IPath path, PageInclude include) {
+ List<PageInclude> current = directReferences.get(path);
if(current == null) {
current = new ArrayList<PageInclude>();
- directReferences.put(parent, current);
+ directReferences.put(path, current);
}
current.add(include);
IPath child = include.getPath();
@@ -68,9 +66,9 @@
is.add(include);
}
- public synchronized List<Var> getVars(IPath page) {
+ public synchronized List<Var> getVars(IPath path) {
List<Var> result = new ArrayList<Var>();
- List<PageInclude> is = parentReferences.get(page);
+ List<PageInclude> is = parentReferences.get(path);
if(is != null) {
for (PageInclude i: is) {
result.addAll(i.getVars());
@@ -78,6 +76,98 @@
}
return result;
}
-
+ static final String STORE_ELEMENT_INCLUDES = "includes"; //$NON-NLS-1$
+ static final String STORE_ELEMENT_PAGE = "page"; //$NON-NLS-1$
+ static final String STORE_ELEMENT_INCLUDE = "include"; //$NON-NLS-1$
+ static final String STORE_ELEMENT_VAR = "var"; //$NON-NLS-1$
+
+ static final String STORE_ATTR_PATH = "path"; //$NON-NLS-1$
+ static final String STORE_ATTR_NAME = "name"; //$NON-NLS-1$
+ static final String STORE_ATTR_VALUE = "value"; //$NON-NLS-1$
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.validation.IValidationContext#store(org.w3c.dom.Element)
+ */
+ public void store(Element root) {
+ Map<String, String> pathAliases = loadAliases(root);
+ Element includes = XMLUtilities.createElement(root, STORE_ELEMENT_INCLUDES);
+ for (IPath path : directReferences.keySet()) {
+ Element page = XMLUtilities.createElement(includes, STORE_ELEMENT_PAGE);
+ String pathAlias = ELReference.getAlias(pathAliases, path.toString());
+ page.setAttribute(STORE_ATTR_PATH, pathAlias);
+ List<PageInclude> is = directReferences.get(path);
+ for (PageInclude i: is) {
+ Element includeElement = XMLUtilities.createElement(page, STORE_ELEMENT_INCLUDE);
+ String pathAlias1 = ELReference.getAlias(pathAliases, i.getPath().toString());
+ includeElement.setAttribute(STORE_ATTR_PATH, pathAlias1);
+ List<Var> vars = i.getVars();
+ for (Var var: vars) {
+ Element varElement = XMLUtilities.createElement(includeElement, STORE_ELEMENT_VAR);
+ varElement.setAttribute(STORE_ATTR_NAME, var.getName());
+ varElement.setAttribute(STORE_ATTR_VALUE, var.getValue());
+ }
+ }
+ }
+
+ Element aliases = XMLUtilities.getUniqueChild(root, "aliases"); //$NON-NLS-1$
+ if(aliases == null) {
+ aliases = XMLUtilities.createElement(root, "aliases"); //$NON-NLS-1$
+ }
+ for (String path: pathAliases.keySet()) {
+ String value = pathAliases.get(path);
+ Element alias = XMLUtilities.createElement(aliases, "alias"); //$NON-NLS-1$
+ alias.setAttribute(STORE_ATTR_PATH, path);
+ alias.setAttribute(STORE_ATTR_VALUE, value);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.validation.IValidationContext#load(org.w3c.dom.Element)
+ */
+ public void load(Element root) {
+ Map<String, String> pathAliases = loadAliases(root);
+
+ Element includes = XMLUtilities.getUniqueChild(root, STORE_ELEMENT_INCLUDES);
+ if(includes == null) return;
+ Element[] pages = XMLUtilities.getChildren(includes, STORE_ELEMENT_PAGE);
+ for (Element page : pages) {
+ String spath = page.getAttribute(STORE_ATTR_PATH);
+ if(spath == null || spath.trim().length() == 0) continue;
+ spath = ELReference.getPath(pathAliases, spath);
+ IPath path = new Path(spath);
+ clean(path);
+ Element[] is = XMLUtilities.getChildren(page, STORE_ELEMENT_INCLUDE);
+ for (Element includeElement: is) {
+ List<Var> vars = new ArrayList<Var>();
+ String path1 = includeElement.getAttribute(STORE_ATTR_PATH);
+ if(path1 == null || path1.trim().length() == 0) continue;
+ Element[] vs = XMLUtilities.getChildren(includeElement, STORE_ELEMENT_VAR);
+ for (Element v: vs) {
+ String name = v.getAttribute(STORE_ATTR_NAME);
+ String value = v.getAttribute(STORE_ATTR_VALUE);
+ Var var = new Var(ELParserUtil.getJbossFactory(), name, value, 0, 0); //TODO
+ vars.add(var);
+ }
+ path1 = ELReference.getPath(pathAliases, path1);
+ addInclude(path, new PageInclude(path, new Path(path1), vars));
+ }
+ }
+ }
+
+ Map<String, String> loadAliases(Element root) {
+ Map<String, String> pathAliases = new HashMap<String, String>();
+ Element aliases = XMLUtilities.getUniqueChild(root, "aliases"); //$NON-NLS-1$
+ if(aliases != null) {
+ Element[] aliasArray = XMLUtilities.getChildren(aliases, "alias"); //$NON-NLS-1$
+ for (Element alias: aliasArray) {
+ String path = alias.getAttribute(STORE_ATTR_PATH);
+ String value = alias.getAttribute(STORE_ATTR_VALUE);
+ pathAliases.put(value, path);
+ }
+ }
+ return pathAliases;
+ }
}
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-05 18:27:02 UTC (rev 42414)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/FaceletPageContextImpl.java 2012-07-05 18:43:26 UTC (rev 42415)
@@ -15,6 +15,8 @@
import org.jboss.tools.common.el.core.resolver.Var;
import org.jboss.tools.jst.web.kb.IFaceletPageContext;
+import org.jboss.tools.jst.web.kb.IKbProject;
+import org.jboss.tools.jst.web.kb.KbProjectFactory;
import org.jboss.tools.jst.web.kb.include.IncludeModel;
/**
@@ -27,7 +29,11 @@
private Map<String, String> params;
public List<Var> getExternalVars() {
- List<Var> res = IncludeModel.getInstance().getVars(getResource().getFullPath());
+ List<Var> res = null;
+ IKbProject kbProject = KbProjectFactory.getKbProject(getResource().getProject(), true);
+ if(kbProject != null) {
+ res = kbProject.getIncludeModel().getVars(getResource().getFullPath());
+ }
return res == null ? super.getExternalVars() : res;
}
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java 2012-07-05 18:27:02 UTC (rev 42414)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java 2012-07-05 18:43:26 UTC (rev 42415)
@@ -45,6 +45,8 @@
import org.jboss.tools.jst.web.kb.KbMessages;
import org.jboss.tools.jst.web.kb.KbProjectFactory;
import org.jboss.tools.jst.web.kb.WebKbPlugin;
+import org.jboss.tools.jst.web.kb.include.IIncludeModel;
+import org.jboss.tools.jst.web.kb.include.IncludeModel;
import org.jboss.tools.jst.web.kb.internal.scanner.ClassPathMonitor;
import org.jboss.tools.jst.web.kb.internal.scanner.LibraryProxy;
import org.jboss.tools.jst.web.kb.internal.scanner.LoadedDeclarations;
@@ -91,6 +93,8 @@
Map<String, Object> extensionModels = new HashMap<String, Object>();
+ IncludeModel includeModel = new IncludeModel();
+
public KbProject() {}
public void setMock() {
@@ -124,6 +128,10 @@
return libraries.getLibrariesArray(path);
}
+ public IIncludeModel getIncludeModel() {
+ return includeModel;
+ }
+
/*
* (non-Javadoc)
* @see org.eclipse.core.resources.IProjectNature#configure()
@@ -333,6 +341,7 @@
if(root != null) {
getValidationContext().load(root);
+ includeModel.load(root);
}
} finally {
@@ -438,6 +447,7 @@
storeSourcePaths2(root);
if(validationContext != null) validationContext.store(root);
+ includeModel.store(root);
XMLUtilities.serialize(root, file.getAbsolutePath());
More information about the jbosstools-commits
mailing list