Author: akazakov
Date: 2009-05-15 08:43:44 -0400 (Fri, 15 May 2009)
New Revision: 15275
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/FaceletContextImpl.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/JspContextImpl.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractAttribute.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractComponent.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2808
Share project "org.jboss.tools.jst.web.kb" into
"https://svn.jboss.org/repos/jbosstools"
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/FaceletContextImpl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/FaceletContextImpl.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/FaceletContextImpl.java 2009-05-15
12:43:44 UTC (rev 15275)
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.internal;
+
+import java.util.Map;
+
+import org.jboss.tools.jst.web.kb.IFaceletPageContext;
+
+/**
+ * Facelet page context
+ * @author Alexey Kazakov
+ */
+public class FaceletContextImpl extends JspContextImpl implements IFaceletPageContext {
+
+ private IFaceletPageContext parentContext;
+ private Map<String, String> params;
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.common.kb.text.FaceletPageContext#getParentContext()
+ */
+ public IFaceletPageContext getParentContext() {
+ return parentContext;
+ }
+
+ public void setParentContext(IFaceletPageContext parentContext) {
+ this.parentContext = parentContext;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.common.kb.text.FaceletPageContext#getParams()
+ */
+ public Map<String, String> getParams() {
+ return params;
+ }
+
+ public void setParams(Map<String, String> params) {
+ this.params = params;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/FaceletContextImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/JspContextImpl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/JspContextImpl.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/JspContextImpl.java 2009-05-15
12:43:44 UTC (rev 15275)
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.internal;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Region;
+import org.jboss.tools.common.el.core.resolver.ELResolver;
+import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
+import org.jboss.tools.common.el.core.resolver.Var;
+import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.IResourceBundle;
+import org.jboss.tools.jst.web.kb.taglib.ITagLibrary;
+
+/**
+ * JSP page context
+ * @author Alexey Kazakov
+ */
+public class JspContextImpl implements IPageContext {
+
+ private IFile resource;
+ private IDocument document;
+ private ElVarSearcher varSearcher;
+ private ITagLibrary[] libs;
+ private ELResolver[] elResolvers;
+ private Map<Region, Var[]> vars = new HashMap<Region, Var[]>();
+ private Set<Var> allVars = new HashSet<Var>();
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.common.kb.text.PageContext#getResource()
+ */
+ public IFile getResource() {
+ return resource;
+ }
+
+ public void setResource(IFile resource) {
+ this.resource = resource;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.common.kb.text.PageContext#getLibraries()
+ */
+ public ITagLibrary[] getLibraries() {
+ return libs;
+ }
+
+ public void setLibraries(ITagLibrary[] libs) {
+ this.libs = libs;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.common.kb.text.PageContext#getElResolvers()
+ */
+ public ELResolver[] getElResolvers() {
+ return elResolvers;
+ }
+
+ public void setElResolvers(ELResolver[] elResolvers) {
+ this.elResolvers = elResolvers;
+ }
+
+ private final static Var[] EMPTY_VAR_ARRAY = new Var[0];
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.common.kb.text.PageContext#getVars(int)
+ */
+ public Var[] getVars(int offset) {
+ for (Region region : vars.keySet()) {
+ if(offset>=region.getOffset() && offset<=region.getOffset() +
region.getLength()) {
+ return vars.get(region);
+ }
+ }
+ return EMPTY_VAR_ARRAY;
+ }
+
+ /**
+ * Adds new Var to the context
+ * @param region
+ * @param vars
+ */
+ public void addVars(Region region, Var[] vars) {
+ this.vars.put(region, vars);
+ for (int i = 0; i < vars.length; i++) {
+ allVars.add(vars[i]);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.common.kb.text.PageContext#getResourceBundles()
+ */
+ public IResourceBundle[] getResourceBundles() {
+ // TODO
+ return null;
+ }
+
+ /**
+ * @return the libs
+ */
+ public ITagLibrary[] getLibs() {
+ return libs;
+ }
+
+ /**
+ * @param libs the libs to set
+ */
+ public void setLibs(ITagLibrary[] libs) {
+ this.libs = libs;
+ }
+
+ /**
+ * @param document the document to set
+ */
+ public void setDocument(IDocument document) {
+ this.document = document;
+ }
+
+ /**
+ * @param varSearcher the varSearcher to set
+ */
+ public void setVarSearcher(ElVarSearcher varSearcher) {
+ this.varSearcher = varSearcher;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.PageContext#getDocument()
+ */
+ public IDocument getDocument() {
+ return document;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.common.el.core.resolver.ELContext#getVarSearcher()
+ */
+ public ElVarSearcher getVarSearcher() {
+ return varSearcher;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.common.el.core.resolver.ELContext#getVars()
+ */
+ public Var[] getVars() {
+ return allVars.toArray(new Var[allVars.size()]);
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/JspContextImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractAttribute.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractAttribute.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractAttribute.java 2009-05-15
12:43:44 UTC (rev 15275)
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.internal.taglib;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.common.el.core.resolver.ELResolver;
+import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.KbQuery;
+import org.jboss.tools.jst.web.kb.taglib.IAttribute;
+
+/**
+ * Abstract implementation of IAttribute
+ * @author Alexey Kazakov
+ */
+public abstract class AbstractAttribute implements IAttribute {
+
+ protected String description;
+ protected String name;
+ protected boolean preferable;
+ protected boolean required;
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IAttribute#getDescription()
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @param description the description to set
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IAttribute#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IAttribute#isPreferable()
+ */
+ public boolean isPreferable() {
+ return preferable;
+ }
+
+ /**
+ * @param preferable the preferable to set
+ */
+ public void setPreferable(boolean preferable) {
+ this.preferable = preferable;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IAttribute#isRequired()
+ */
+ public boolean isRequired() {
+ return required;
+ }
+
+ /**
+ * @param required the required to set
+ */
+ public void setRequired(boolean required) {
+ this.required = required;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.IProposalProcessor#getProposals(org.jboss.tools.jst.web.kb.KbQuery,
org.jboss.tools.jst.web.kb.IPageContext)
+ */
+ public TextProposal[] getProposals(KbQuery query, IPageContext context) {
+ List<TextProposal> proposals = new ArrayList<TextProposal>();
+ ELResolver[] resolvers = context.getElResolvers();
+ for (int i = 0; i < resolvers.length; i++) {
+ proposals.addAll(resolvers[i].getCompletions(query.getValue(), false,
query.getValue().length(), context));
+ }
+ return proposals.toArray(new TextProposal[proposals.size()]);
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractAttribute.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractComponent.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractComponent.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractComponent.java 2009-05-15
12:43:44 UTC (rev 15275)
@@ -0,0 +1,242 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.internal.taglib;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.KbQuery;
+import org.jboss.tools.jst.web.kb.taglib.IAttribute;
+import org.jboss.tools.jst.web.kb.taglib.IComponent;
+import org.jboss.tools.jst.web.kb.taglib.INameSpace;
+
+/**
+ * Abstract implementation of IComponent
+ * @author Alexey Kazakov
+ */
+public abstract class AbstractComponent implements IComponent {
+
+ protected boolean canHaveBody;
+ protected String componentClass;
+ protected String componentType;
+ protected String description;
+ protected String name;
+ protected INameSpace nameSpace;
+ protected Map<String, IAttribute> attributes = new HashMap<String,
IAttribute>();
+ protected Map<String, IAttribute> preferableAttributes = new HashMap<String,
IAttribute>();
+ protected Map<String, IAttribute> requiredAttributes = new HashMap<String,
IAttribute>();
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IComponent#canHaveBody()
+ */
+ public boolean canHaveBody() {
+ return canHaveBody;
+ }
+
+ /**
+ * @param canHaveBody
+ */
+ public void setCanHaveBody(boolean canHaveBody) {
+ this.canHaveBody = canHaveBody;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IComponent#getAttribute(java.lang.String)
+ */
+ public IAttribute getAttribute(String name) {
+ return attributes.get(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IComponent#getAttributes()
+ */
+ public IAttribute[] getAttributes() {
+ synchronized (attributes) {
+ return attributes.values().toArray(new IAttribute[attributes.size()]);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IComponent#getAttributes(java.lang.String)
+ */
+ public IAttribute[] getAttributes(String nameTemplate) {
+ List<IAttribute> list = new ArrayList<IAttribute>();
+ IAttribute[] atts = getAttributes();
+ for (int i = 0; i < atts.length; i++) {
+ if(atts[i].getName().startsWith(nameTemplate)) {
+ list.add(atts[i]);
+ }
+ }
+ return list.toArray(new IAttribute[list.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.taglib.IComponent#getAttributes(org.jboss.tools.jst.web.kb.KbQuery,
org.jboss.tools.jst.web.kb.IPageContext)
+ */
+ public IAttribute[] getAttributes(KbQuery query, IPageContext context) {
+ String attrName = null;
+ boolean mask = false;
+ if(query.getType()==KbQuery.Type.ATTRIBUTE_NAME) {
+ attrName = query.getValue();
+ mask = query.isMask();
+ } else if(query.getType()==KbQuery.Type.ATTRIBUTE_VALUE) {
+ attrName = query.getParent();
+ }
+ if(attrName == null) {
+ return null;
+ }
+ if(mask) {
+ return getAttributes(attrName);
+ }
+ return new IAttribute[]{getAttribute(attrName)};
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IComponent#getComponentClass()
+ */
+ public String getComponentClass() {
+ return componentClass;
+ }
+
+ /**
+ * @param componentClass the component class name to set
+ */
+ public void setComponentClass(String componentClass) {
+ this.componentClass = componentClass;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IComponent#getComponentType()
+ */
+ public String getComponentType() {
+ return componentType;
+ }
+
+ /**
+ * @param componentType the component type to set
+ */
+ public void setComponentType(String componentType) {
+ this.componentType = componentType;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IComponent#getDescription()
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @param description the description to set
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IComponent#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IComponent#getNameSpace()
+ */
+ public INameSpace getNameSpace() {
+ return nameSpace;
+ }
+
+ /**
+ * @param nameSpace the name space to set
+ */
+ public void setNameSpace(INameSpace nameSpace) {
+ this.nameSpace = nameSpace;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IComponent#getPreferableAttributes()
+ */
+ public IAttribute[] getPreferableAttributes() {
+ synchronized (preferableAttributes) {
+ return preferableAttributes.values().toArray(new
IAttribute[preferableAttributes.size()]);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IComponent#getRequiredAttributes()
+ */
+ public IAttribute[] getRequiredAttributes() {
+ synchronized (requiredAttributes) {
+ return requiredAttributes.values().toArray(new
IAttribute[requiredAttributes.size()]);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.IProposalProcessor#getProposals(org.jboss.tools.jst.web.kb.KbQuery,
org.jboss.tools.jst.web.kb.IPageContext)
+ */
+ public TextProposal[] getProposals(KbQuery query, IPageContext context) {
+ List<TextProposal> proposals = new ArrayList<TextProposal>();
+ IAttribute[] attributes = getAttributes(query, context);
+ if(query.getType() == KbQuery.Type.ATTRIBUTE_NAME) {
+ for (int i = 0; i < attributes.length; i++) {
+ TextProposal proposal = new TextProposal();
+ proposal.setContextInfo(attributes[i].getDescription());
+ proposal.setReplacementString(attributes[i].getName());
+ proposal.setLabel(attributes[i].getName());
+ proposals.add(proposal);
+ }
+ } else if(query.getType() == KbQuery.Type.ATTRIBUTE_VALUE) {
+ for (int i = 0; i < attributes.length; i++) {
+ TextProposal[] attributeProposals = attributes[i].getProposals(query, context);
+ for (int j = 0; j < attributeProposals.length; j++) {
+ proposals.add(attributeProposals[j]);
+ }
+ }
+ }
+ return proposals.toArray(new TextProposal[proposals.size()]);
+ }
+
+ /**
+ * Adds the attribute to the component.
+ * @param attribute
+ */
+ public void addAttribute(IAttribute attribute) {
+ attributes.put(attribute.getName(), attribute);
+ if(attribute.isPreferable()) {
+ preferableAttributes.put(attribute.getName(), attribute);
+ }
+ if(attribute.isRequired()) {
+ requiredAttributes.put(attribute.getName(), attribute);
+ }
+ }
+
+ /**
+ * Removes the attribute from the component
+ * @param attribute
+ */
+ public void removeAttribute(IAttribute attribute) {
+ attributes.remove(attribute.getName());
+ preferableAttributes.remove(attribute.getName());
+ requiredAttributes.remove(attribute.getName());
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java 2009-05-15
12:43:44 UTC (rev 15275)
@@ -0,0 +1,179 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.internal.taglib;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.KbQuery;
+import org.jboss.tools.jst.web.kb.taglib.IAttribute;
+import org.jboss.tools.jst.web.kb.taglib.IComponent;
+import org.jboss.tools.jst.web.kb.taglib.ITagLibrary;
+
+/**
+ * Abstract implementation of ITagLibrary
+ * @author Alexey Kazakov
+ */
+public abstract class AbstractTagLib implements ITagLibrary {
+
+ protected String uri;
+ protected IFile resource;
+ protected Map<String, IComponent> components = new HashMap<String,
IComponent>();
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.TagLibrary#getAllComponents()
+ */
+ public IComponent[] getComponents() {
+ synchronized (components) {
+ return components.values().toArray(new IComponent[components.size()]);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.TagLibrary#getComponent(java.lang.String)
+ */
+ public IComponent getComponent(String name) {
+ return components.get(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.TagLibrary#getComponents(java.lang.String)
+ */
+ public IComponent[] getComponents(String nameTemplate) {
+ List<IComponent> list = new ArrayList<IComponent>();
+ IComponent[] comps = getComponents();
+ for (int i = 0; i < comps.length; i++) {
+ if(comps[i].getName().startsWith(nameTemplate)) {
+ list.add(comps[i]);
+ }
+ }
+ return list.toArray(new IComponent[list.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.taglib.TagLibrary#getComponents(org.jboss.tools.jst.web.kb.KbQuery,
org.jboss.tools.jst.web.kb.PageContext)
+ */
+ public IComponent[] getComponents(KbQuery query, IPageContext context) {
+ String tagName = null;
+ boolean mask = false;
+ if(query.getType()==KbQuery.Type.TAG_NAME) {
+ tagName = query.getValue();
+ mask = query.isMask();
+ } else {
+ tagName = query.getLastParentTag();
+ }
+ if(tagName == null) {
+ return null;
+ }
+ if(mask) {
+ return getComponents(tagName);
+ }
+ return new IComponent[]{getComponent(tagName)};
+ }
+
+ /**
+ * Adds component to tag lib.
+ * @param component
+ */
+ public void addComponent(IComponent component) {
+ components.put(component.getName(), component);
+ }
+
+ /**
+ * @param components the components to set
+ */
+ protected void setComponents(Map<String, IComponent> components) {
+ this.components = components;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.TagLibrary#getResource()
+ */
+ public IResource getResource() {
+ return resource;
+ }
+
+ /**
+ * @param resource the resource to set
+ */
+ public void setResource(IFile resource) {
+ this.resource = resource;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.TagLibrary#getURI()
+ */
+ public String getURI() {
+ return uri;
+ }
+
+ /**
+ * @param uri the URI to set
+ */
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.ProposalProcessor#getProposals(org.jboss.tools.jst.web.kb.KbQuery,
org.jboss.tools.jst.web.kb.PageContext)
+ */
+ public TextProposal[] getProposals(KbQuery query, IPageContext context) {
+ List<TextProposal> proposals = new ArrayList<TextProposal>();
+ IComponent[] components = getComponents(query, context);
+ if(query.getType() == KbQuery.Type.TAG_NAME) {
+ for (int i = 0; i < components.length; i++) {
+ TextProposal proposal = new TextProposal();
+ proposal.setContextInfo(components[i].getDescription());
+ StringBuffer label = new StringBuffer();
+ if(query.getPrefix()!=null) {
+ label.append(query.getPrefix() + KbQuery.PREFIX_SEPARATOR);
+ }
+ label.append(components[i].getName());
+ proposal.setLabel(label.toString());
+
+ IAttribute[] attributes = components[i].getPreferableAttributes();
+ StringBuffer attributeSB = new StringBuffer();
+ for (int j = 0; j < attributes.length; j++) {
+ attributeSB.append("
").append(attributes[j].getName()).append("=\"\"");
+ }
+ label.append(attributeSB);
+ if(!components[i].canHaveBody()) {
+ label.append(" /");
+ }
+
+ proposal.setReplacementString(label.toString());
+
+ int position = proposal.getReplacementString().indexOf('"');
+ if(position!=-1) {
+ position ++;
+ } else {
+ position = proposal.getReplacementString().length();
+ }
+ proposal.setPosition(position);
+ proposals.add(proposal);
+ }
+ } else {
+ for (int i = 0; i < components.length; i++) {
+ TextProposal[] componentProposals = components[i].getProposals(query, context);
+ for (int j = 0; j < componentProposals.length; j++) {
+ proposals.add(componentProposals[j]);
+ }
+ }
+ }
+ return proposals.toArray(new TextProposal[proposals.size()]);
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain