Author: akazakov
Date: 2009-06-05 09:35:44 -0400 (Fri, 05 Jun 2009)
New Revision: 15731
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomTagLibAttribute.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomTagLibComponent.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/ICustomTagLibComponent.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/resources/kbCustomTagLibSchema-1.0.dtd
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageProcessor.java
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
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomTagLibrary.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/CustomTagLibManager.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IAttribute.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IComponent.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/ICustomTagLibrary.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/ITagLibrary.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2808
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/resources/kbCustomTagLibSchema-1.0.dtd
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/resources/kbCustomTagLibSchema-1.0.dtd 2009-06-05
13:25:00 UTC (rev 15730)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/resources/kbCustomTagLibSchema-1.0.dtd 2009-06-05
13:35:44 UTC (rev 15731)
@@ -22,14 +22,12 @@
closeTag - "true" - Component can have a body.
"false" - Component cannot have a body. Used by default.
extended - "true" - Component is relevant only if this component exists in
other tag-libs (tld, faclets, ...). Set to "true" by default.
- description
-->
-<!ELEMENT component (component*, attribute*)>
+<!ELEMENT component (description?, component*, attribute*)>
<!ATTLIST component name CDATA #REQUIRED>
<!ATTLIST component closeTag %Boolean; #IMPLIED>
<!ATTLIST component extended %Boolean; #IMPLIED>
-<!ATTLIST component description CDATA #IMPLIED>
<!--
Describes attribute of component.
@@ -38,15 +36,13 @@
required - "true" - attribute of element is required. "false" by
default.
defaultValue - default value of attribute.
extended - "true" - Attribute is relevant only if this attribute exists in
other tag-libs (tld, faclets, ...). Set to "true" by default.
- description
-->
-<!ELEMENT attribute (proposal*)>
+<!ELEMENT attribute (description?, proposal*)>
<!ATTLIST attribute name CDATA #REQUIRED>
<!ATTLIST attribute required %Boolean; #REQUIRED>
<!ATTLIST attribute defaultValue CDATA #IMPLIED>
<!ATTLIST attribute extended %Boolean; #IMPLIED>
-<!ATTLIST attribute description CDATA #IMPLIED>
<!--
Describe content assist proposal for value of attribute.
@@ -68,6 +64,8 @@
<!ATTLIST param value CDATA #REQUIRED>
<!ATTLIST param name CDATA #IMPLIED>
+<!ELEMENT description ()>
+
<!--
component extension describes common attributes with additional meta information
for component attributes in case these attributes are present in other types of tag
libs.
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageProcessor.java 2009-06-05
13:25:00 UTC (rev 15730)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageProcessor.java 2009-06-05
13:35:44 UTC (rev 15731)
@@ -14,8 +14,11 @@
import org.jboss.tools.common.el.core.resolver.ELResolver;
import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.jst.web.kb.internal.taglib.CustomTagLibAttribute;
+import org.jboss.tools.jst.web.kb.taglib.CustomTagLibManager;
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.ICustomTagLibrary;
import org.jboss.tools.jst.web.kb.taglib.ITagLibrary;
/**
@@ -24,6 +27,8 @@
public class PageProcessor implements IProposalProcessor {
private static final PageProcessor INSTANCE = new PageProcessor();
+ private ICustomTagLibrary[] customTagLibs;
+ private CustomTagLibAttribute[] componentExtensions;
/**
* @return instance of PageProcessor
@@ -33,6 +38,8 @@
}
private PageProcessor() {
+ customTagLibs = CustomTagLibManager.getInstance().getLibraries();
+ componentExtensions = CustomTagLibManager.getInstance().getComponentExtensions();
}
/*
@@ -48,6 +55,9 @@
proposals.add(libProposals[j]);
}
}
+ for (int i = 0; i < customTagLibs.length; i++) {
+ // TODO
+ }
if(query.getType() == KbQuery.Type.ATTRIBUTE_VALUE || ((query.getType() ==
KbQuery.Type.TEXT )&& context instanceof IFaceletPageContext)) {
String value = query.getValue();
//TODO convert value to EL string.
Modified:
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 2009-06-05
13:25:00 UTC (rev 15730)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractAttribute.java 2009-06-05
13:35:44 UTC (rev 15731)
@@ -226,4 +226,21 @@
super.loadAttributesInfo(element, context);
}
}
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IAttribute#isExtended()
+ */
+ public boolean isExtended() {
+ // Return false by default
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IAttribute#setExtended(boolean)
+ */
+ public void setExtended(boolean extended) {
+ // Do nothing by default
+ }
}
\ No newline at end of file
Modified:
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 2009-06-05
13:25:00 UTC (rev 15730)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractComponent.java 2009-06-05
13:35:44 UTC (rev 15731)
@@ -45,9 +45,12 @@
protected String componentType;
protected String description;
protected String name;
- 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>();
+ private Map<String, IAttribute> attributes = new HashMap<String,
IAttribute>();
+ private IAttribute[] attributesArray;
+ private Map<String, IAttribute> preferableAttributes = new HashMap<String,
IAttribute>();
+ private IAttribute[] preferableAttributesArray;
+ private Map<String, IAttribute> requiredAttributes = new HashMap<String,
IAttribute>();
+ private IAttribute[] requiredAttributesArray;
/* (non-Javadoc)
* @see org.jboss.tools.jst.web.kb.taglib.IComponent#canHaveBody()
@@ -79,9 +82,12 @@
* @see org.jboss.tools.jst.web.kb.taglib.IComponent#getAttributes()
*/
public IAttribute[] getAttributes() {
- synchronized (attributes) {
- return attributes.values().toArray(new IAttribute[attributes.size()]);
+ if(attributesArray==null) {
+ synchronized (attributes) {
+ attributesArray = attributes.values().toArray(new IAttribute[attributes.size()]);
+ }
}
+ return attributesArray;
}
/* (non-Javadoc)
@@ -199,18 +205,24 @@
* @see org.jboss.tools.jst.web.kb.taglib.IComponent#getPreferableAttributes()
*/
public IAttribute[] getPreferableAttributes() {
- synchronized (preferableAttributes) {
- return preferableAttributes.values().toArray(new
IAttribute[preferableAttributes.size()]);
+ if(preferableAttributesArray==null) {
+ synchronized (preferableAttributes) {
+ preferableAttributesArray = preferableAttributes.values().toArray(new
IAttribute[preferableAttributes.size()]);
+ }
}
+ return preferableAttributesArray;
}
/* (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()]);
+ if(requiredAttributesArray==null) {
+ synchronized (requiredAttributes) {
+ requiredAttributesArray = requiredAttributes.values().toArray(new
IAttribute[requiredAttributes.size()]);
+ }
}
+ return requiredAttributesArray;
}
/**
@@ -280,8 +292,15 @@
if(attribute.isRequired()) {
requiredAttributes.put(attribute.getName(), attribute);
}
+ clearAttributeArrays();
}
+ private void clearAttributeArrays() {
+ attributesArray = null;
+ preferableAttributesArray = null;
+ requiredAttributesArray = null;
+ }
+
/**
* Removes the attribute from the component
* @param attribute
@@ -290,8 +309,25 @@
attributes.remove(attribute.getName());
preferableAttributes.remove(attribute.getName());
requiredAttributes.remove(attribute.getName());
+ clearAttributeArrays();
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IComponent#isExtended()
+ */
+ public boolean isExtended() {
+ // Return false by default
+ return false;
+ }
+
+ /**
+ * @param extended
+ */
+ public void setExtended(boolean extended) {
+ // Do nothing
+ }
+
public AbstractComponent clone() throws CloneNotSupportedException {
AbstractComponent copy = (AbstractComponent)super.clone();
copy.attributes = new HashMap<String, IAttribute>();
@@ -357,6 +393,7 @@
attributes.remove(removed.getName());
Change change = new Change(this, null, removed, null);
children.addChildren(Change.addChange(null, change));
+ clearAttributeArrays();
}
}
}
@@ -408,5 +445,4 @@
}
}
}
-
}
\ No newline at end of file
Modified:
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 2009-06-05
13:25:00 UTC (rev 15730)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java 2009-06-05
13:35:44 UTC (rev 15731)
@@ -45,15 +45,20 @@
protected INameSpace nameSpace;
protected String uri;
- protected Map<String, IComponent> components = new HashMap<String,
IComponent>();
+ protected String version;
+ private Map<String, IComponent> components = new HashMap<String,
IComponent>();
+ private IComponent[] componentsArray;
/* (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()]);
+ if(componentsArray==null) {
+ synchronized (components) {
+ componentsArray = components.values().toArray(new IComponent[components.size()]);
+ }
}
+ return componentsArray;
}
/* (non-Javadoc)
@@ -85,7 +90,7 @@
return getComponents(query, prefix, context);
}
- private String getPrefix(KbQuery query, IPageContext context) {
+ protected String getPrefix(KbQuery query, IPageContext context) {
String prefix = null;
Map<String, INameSpace> nameSpaces = context.getNameSpaces(query.getOffset());
if(nameSpaces!=null) {
@@ -99,7 +104,7 @@
private static final IComponent[] EMPTY_ARRAY = new IComponent[0];
- private IComponent[] getComponents(KbQuery query, String prefix, IPageContext context)
{
+ protected IComponent[] getComponents(KbQuery query, String prefix, IPageContext context)
{
String fullTagName = null;
boolean mask = false;
if(query.getType()==KbQuery.Type.TAG_NAME) {
@@ -155,6 +160,7 @@
public void addComponent(IComponent component) {
adopt((KbObject)component);
components.put(component.getName(), component);
+ componentsArray=null;
}
/**
@@ -162,6 +168,7 @@
*/
protected void setComponents(Map<String, IComponent> components) {
this.components = components;
+ componentsArray=null;
}
/*
@@ -233,6 +240,21 @@
attributesInfo.put(URI, s);
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.ITagLibrary#getVersion()
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * @param version the version to set
+ */
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
/* (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)
*/
@@ -242,35 +264,9 @@
IComponent[] components = getComponents(query, prefix, 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(prefix!=null) {
- label.append(prefix + KbQuery.PREFIX_SEPARATOR);
+ if(!components[i].isExtended() || checkExtended(components[i], prefix, query,
context)) {
+ proposals.add(getProposal(prefix, components[i]));
}
- 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++) {
@@ -285,6 +281,43 @@
return proposals.toArray(new TextProposal[proposals.size()]);
}
+ protected boolean checkExtended(IComponent component, String prefix, KbQuery query,
IPageContext context) {
+ // TODO
+ return false;
+ }
+
+ protected TextProposal getProposal(String prefix, IComponent component) {
+ TextProposal proposal = new TextProposal();
+ proposal.setContextInfo(component.getDescription());
+ StringBuffer label = new StringBuffer();
+ if(prefix!=null) {
+ label.append(prefix + KbQuery.PREFIX_SEPARATOR);
+ }
+ label.append(component.getName());
+ proposal.setLabel(label.toString());
+
+ IAttribute[] attributes = component.getPreferableAttributes();
+ StringBuffer attributeSB = new StringBuffer();
+ for (int j = 0; j < attributes.length; j++) {
+ attributeSB.append("
").append(attributes[j].getName()).append("=\"\"");
+ }
+ label.append(attributeSB);
+ if(!component.canHaveBody()) {
+ label.append(" /");
+ }
+
+ proposal.setReplacementString(label.toString());
+
+ int position = proposal.getReplacementString().indexOf('"');
+ if(position!=-1) {
+ position ++;
+ } else {
+ position = proposal.getReplacementString().length();
+ }
+ proposal.setPosition(position);
+ return proposal;
+
+ }
/*
* (non-Javadoc)
* @see org.jboss.tools.jst.web.kb.internal.KbObject#clone()
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomTagLibAttribute.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomTagLibAttribute.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomTagLibAttribute.java 2009-06-05
13:35:44 UTC (rev 15731)
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class CustomTagLibAttribute extends AbstractAttribute {
+
+ protected boolean extended = true;
+ protected String defaultValue;
+ protected Proposal[] proposals;
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IAttribute#isExtended()
+ */
+ @Override
+ public boolean isExtended() {
+ return extended;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IAttribute#setExtended(boolean)
+ */
+ @Override
+ public void setExtended(boolean extended) {
+ this.extended = extended;
+ }
+
+ /**
+ * @return the defaultValue
+ */
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ /**
+ * @param defaultValue the defaultValue to set
+ */
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ /**
+ * @return the proposals
+ */
+ public Proposal[] getProposals() {
+ if(proposals==null) {
+ proposals = new Proposal[0];
+ }
+ return proposals;
+ }
+
+ /**
+ * @param proposals the proposals to set
+ */
+ public void setProposals(Proposal[] proposals) {
+ this.proposals = proposals;
+ }
+
+ /**
+ * @author Alexey Kazakov
+ */
+ public static class Proposal {
+
+ private Param[] params;
+ private String type;
+
+ /**
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * @param type the type to set
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * @return the params
+ */
+ public Param[] getParams() {
+ if(params==null) {
+ params = new Param[0];
+ }
+ return params;
+ }
+
+ /**
+ * @param params the params to set
+ */
+ public void setParams(Param[] params) {
+ this.params = params;
+ }
+ }
+
+ public static class Param {
+
+ private String name;
+ private String value;
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the value
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * @param value the value to set
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+ }
+}
\ 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/CustomTagLibAttribute.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/CustomTagLibComponent.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomTagLibComponent.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomTagLibComponent.java 2009-06-05
13:35:44 UTC (rev 15731)
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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 org.jboss.tools.jst.web.kb.taglib.ICustomTagLibComponent;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class CustomTagLibComponent extends AbstractComponent implements
ICustomTagLibComponent {
+
+ protected boolean extended = true;
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.taglib.IComponent#isExtended()
+ */
+ public boolean isExtended() {
+ return extended;
+ }
+
+ /**
+ * @param extended
+ */
+ public void setExtended(boolean extended) {
+ this.extended = extended;
+ }
+}
\ 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/CustomTagLibComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomTagLibrary.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomTagLibrary.java 2009-06-05
13:25:00 UTC (rev 15730)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomTagLibrary.java 2009-06-05
13:35:44 UTC (rev 15731)
@@ -13,13 +13,22 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.KbQuery;
import org.jboss.tools.jst.web.kb.WebKbPlugin;
+import org.jboss.tools.jst.web.kb.taglib.IComponent;
+import org.jboss.tools.jst.web.kb.taglib.ICustomTagLibComponent;
import org.jboss.tools.jst.web.kb.taglib.ICustomTagLibrary;
+import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -33,27 +42,32 @@
*/
public class CustomTagLibrary extends AbstractTagLib implements ICustomTagLibrary {
- private static final String DEFAULT_PREFIX = "defaultPrefix"; //$NON-NLS-1$
- private static final String TAG_LIB = "tag-lib"; //$NON-NLS-1$
- private static final String COMPONENT = "component"; //$NON-NLS-1$
- private static final String CLOSE_TAG = "closeTag"; //$NON-NLS-1$
- private static final String TRUE = "true"; //$NON-NLS-1$
- private static final String NAME = "name"; //$NON-NLS-1$
- private static final String ATTRIBUTE = "attribute"; //$NON-NLS-1$
- private static final String REQUIRED = "required"; //$NON-NLS-1$
- private static final String PROPOSAL = "proposal"; //$NON-NLS-1$
- private static final String TYPE = "type"; //$NON-NLS-1$
- private static final String ENUMERATION = "enumeration"; //$NON-NLS-1$
- private static final String PARAM = "param"; //$NON-NLS-1$
- private static final String VALUE = "value"; //$NON-NLS-1$
- private static final String COMPONET_EXTENSION = "componentExtension";
//$NON-NLS-1$
- private static final String DEFAULT_VALUE = "defaultValue"; //$NON-NLS-1$
- private static final String EXTENDED = "extended"; //$NON-NLS-1$
- private static final String DESCRIPTION = "description"; //$NON-NLS-1$
+ protected static final String DEFAULT_PREFIX = "defaultPrefix"; //$NON-NLS-1$
+ protected static final String TAG_LIB = "tag-lib"; //$NON-NLS-1$
+ protected static final String COMPONENT = "component"; //$NON-NLS-1$
+ protected static final String CLOSE_TAG = "closeTag"; //$NON-NLS-1$
+ protected static final String TRUE = "true"; //$NON-NLS-1$
+ protected static final String NAME = "name"; //$NON-NLS-1$
+ protected static final String ATTRIBUTE = "attribute"; //$NON-NLS-1$
+ protected static final String REQUIRED = "required"; //$NON-NLS-1$
+ protected static final String PROPOSAL = "proposal"; //$NON-NLS-1$
+ protected static final String TYPE = "type"; //$NON-NLS-1$
+ protected static final String ENUMERATION = "enumeration"; //$NON-NLS-1$
+ protected static final String PARAM = "param"; //$NON-NLS-1$
+ protected static final String VALUE = "value"; //$NON-NLS-1$
+ protected static final String COMPONET_EXTENSION = "componentExtension";
//$NON-NLS-1$
+ protected static final String DEFAULT_VALUE = "defaultValue"; //$NON-NLS-1$
+ protected static final String EXTENDED = "extended"; //$NON-NLS-1$
+ protected static final String DESCRIPTION = "description"; //$NON-NLS-1$
+ protected String name;
protected String defaultPrefix;
+ protected CustomTagLibAttribute[] extendedAttributes;
public CustomTagLibrary(File file, String uri, String version, String name) {
+ setURI(uri);
+ setVersion(version);
+ this.name = name;
Document document = null;
try {
DocumentBuilder builder = createDocumentBuilder(false);
@@ -72,17 +86,38 @@
Node child = children.item(i);
if(child instanceof Element) {
if(child.getNodeName().equals(COMPONENT)) {
- parseComponent((Element)child);
+ CustomTagLibComponent component = parseComponent((Element)child);
+ addComponent(component);
} else if (child.getNodeName().equals(COMPONET_EXTENSION)) {
- parseComponentExtension((Element)child);
+ extendedAttributes = getAttributes((Element)child);
}
}
}
}
- private void parseComponent(Element component) {
+ private CustomTagLibComponent parseComponent(Element component) {
String name = component.getAttribute(NAME);
boolean closeTag = TRUE.equalsIgnoreCase(component.getAttribute(CLOSE_TAG));
+ String description = getDescription(component);
+ String extendedStr = component.getAttribute(EXTENDED);
+ Boolean extended = extendedStr==null || extendedStr.length()==0 ||
TRUE.equals(extendedStr);
+ CustomTagLibComponent newComponent = new CustomTagLibComponent();
+ newComponent.setName(name);
+ newComponent.setCanHaveBody(!closeTag);
+ newComponent.setDescription(description);
+ newComponent.setExtended(extended);
+
+ // Extract attributes
+ CustomTagLibAttribute[] attributes = getAttributes(component);
+ for (int i = 0; i < attributes.length; i++) {
+ newComponent.addAttribute(attributes[i]);
+ }
+
+ return newComponent;
+ }
+
+ protected CustomTagLibAttribute[] getAttributes(Element component) {
+ Set<CustomTagLibAttribute> newAttributes = new
HashSet<CustomTagLibAttribute>();
NodeList children = component.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
@@ -91,15 +126,75 @@
Element attribute = (Element)child;
String attributeName = attribute.getAttribute(NAME);
boolean required = TRUE.equalsIgnoreCase(attribute.getAttribute(REQUIRED));
+ CustomTagLibAttribute newAttribute = new CustomTagLibAttribute();
+ newAttribute.setName(attributeName);
+ newAttribute.setRequired(required);
+ String atrDescription = getDescription(attribute);
+ newAttribute.setDescription(atrDescription);
+ String extendedAtrStr = attribute.getAttribute(EXTENDED);
+ Boolean extendedAtr = extendedAtrStr==null || extendedAtrStr.length()==0 ||
TRUE.equals(extendedAtrStr);
+ newAttribute.setExtended(extendedAtr);
+ String defaultValue = attribute.getAttribute(DEFAULT_VALUE);
+ newAttribute.setDefaultValue(defaultValue);
+ newAttributes.add(newAttribute);
+
+ // Extract proposals
+ List<CustomTagLibAttribute.Proposal> newProposals = new
ArrayList<CustomTagLibAttribute.Proposal>();
+ NodeList proposals = attribute.getElementsByTagName(PROPOSAL);
+ for (int j = 0; j < proposals.getLength(); j++) {
+ Element proposal = (Element)proposals.item(j);
+ String type = proposal.getAttribute(TYPE);
+ CustomTagLibAttribute.Proposal newProposal = new CustomTagLibAttribute.Proposal();
+ newProposal.setType(type);
+ newProposals.add(newProposal);
+
+ List<CustomTagLibAttribute.Param> newParams = new
ArrayList<CustomTagLibAttribute.Param>();
+ // Extract params
+ NodeList params = proposal.getElementsByTagName(PARAM);
+ for (int c = 0; c < params.getLength(); c++) {
+ Element param = (Element)params.item(c);
+ String paramName = param.getAttribute(NAME);
+ String paramValue = param.getAttribute(VALUE);
+ CustomTagLibAttribute.Param newParam = new CustomTagLibAttribute.Param();
+ if(paramName!=null && paramName.length()>0) {
+ newParam.setName(paramName);
+ }
+ newParam.setValue(paramValue);
+ newParams.add(newParam);
+ }
+ newProposal.setParams(newParams.toArray(new CustomTagLibAttribute.Param[0]));
+ }
+ newAttribute.setProposals(newProposals.toArray(new
CustomTagLibAttribute.Proposal[0]));
}
}
}
+ return newAttributes.toArray(new CustomTagLibAttribute[0]);
+ }
- //TODO
+ private String getDescription(Element element) {
+ NodeList list = element.getChildNodes();
+ for(int i=0; i<list.getLength(); i++) {
+ Node node = list.item(i);
+ if(node instanceof Element) {
+ if(DESCRIPTION.equals(node.getNodeName())) {
+ return getElementBody((Element)node);
+ }
+ }
+ }
+ return null;
}
- private void parseComponentExtension(Element extension) {
- //TODO
+ private String getElementBody(Element element) {
+ StringBuffer sb = new StringBuffer();
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node n = nl.item(i);
+ short nodeType = n.getNodeType();
+ if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) {
+ sb.append(((CharacterData)n).getData());
+ }
+ }
+ return sb.toString();
}
private DocumentBuilder createDocumentBuilder(boolean validate) throws
ParserConfigurationException {
@@ -120,4 +215,41 @@
}
return documentBuilder;
}
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return the defaultPrefix
+ */
+ public String getDefaultPrefix() {
+ return defaultPrefix;
+ }
+
+ /**
+ * @return the extendedAttributes
+ */
+ public CustomTagLibAttribute[] getExtendedAttributes() {
+ return extendedAttributes;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.taglib.ICustomTagLibrary#getExtendedComponents(org.jboss.tools.jst.web.kb.KbQuery,
org.jboss.tools.jst.web.kb.IPageContext)
+ */
+ public Set<ICustomTagLibComponent> getExtendedComponents(KbQuery query,
IPageContext context) {
+ Set<ICustomTagLibComponent> set = new HashSet<ICustomTagLibComponent>();
+ IComponent[] components = getComponents(query, context);
+ for (int i = 0; i < components.length; i++) {
+ ICustomTagLibComponent component = (ICustomTagLibComponent)components[i];
+ if(component.isExtended()) {
+ set.add(component);
+ }
+ }
+ return set;
+ }
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/CustomTagLibManager.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/CustomTagLibManager.java 2009-06-05
13:25:00 UTC (rev 15730)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/CustomTagLibManager.java 2009-06-05
13:35:44 UTC (rev 15731)
@@ -22,6 +22,7 @@
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.jboss.tools.jst.web.kb.WebKbPlugin;
+import org.jboss.tools.jst.web.kb.internal.taglib.CustomTagLibAttribute;
import org.jboss.tools.jst.web.kb.internal.taglib.CustomTagLibrary;
import org.osgi.framework.Bundle;
@@ -86,4 +87,9 @@
}
return libs;
}
+
+ public CustomTagLibAttribute[] getComponentExtensions() {
+ //TODO
+ return null;
+ }
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IAttribute.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IAttribute.java 2009-06-05
13:25:00 UTC (rev 15730)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IAttribute.java 2009-06-05
13:35:44 UTC (rev 15731)
@@ -36,4 +36,16 @@
* @return true if the attribute is preferable. E.g. <h:outputText
value=""/>
*/
boolean isPreferable();
+
+ /**
+ * Returns "true" if the attribute is relevant only if this attribute exists
in other components with the same name in other tag-libs (tld, faclets, ...).
+ * If there are not any other attributes with the same name in the same component in
other tag libs then this attribute should be ignored.
+ * @return
+ */
+ boolean isExtended();
+
+ /**
+ * @param extended
+ */
+ void setExtended(boolean extended);
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IComponent.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IComponent.java 2009-06-05
13:25:00 UTC (rev 15730)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/IComponent.java 2009-06-05
13:35:44 UTC (rev 15731)
@@ -98,4 +98,11 @@
* @return facet by name
*/
Facet getFacet(String name);
+
+ /**
+ * Returns "true" if the component is relevant only if this component exists
in other tag-libs (tld, faclets, ...).
+ * If there are not any other components with the same name in other tag libs then this
component should be ignored.
+ * @return
+ */
+ boolean isExtended();
}
\ No newline at end of file
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/ICustomTagLibComponent.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/ICustomTagLibComponent.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/ICustomTagLibComponent.java 2009-06-05
13:35:44 UTC (rev 15731)
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * 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.taglib;
+
+/**
+ * @author Alexey Kazakov
+ */
+public interface ICustomTagLibComponent extends IComponent {
+}
\ 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/taglib/ICustomTagLibComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/ICustomTagLibrary.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/ICustomTagLibrary.java 2009-06-05
13:25:00 UTC (rev 15730)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/ICustomTagLibrary.java 2009-06-05
13:35:44 UTC (rev 15731)
@@ -10,9 +10,20 @@
******************************************************************************/
package org.jboss.tools.jst.web.kb.taglib;
+import java.util.Set;
+
+import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.KbQuery;
+
/**
* @author Alexey Kazakov
*/
public interface ICustomTagLibrary extends ITagLibrary {
+ /**
+ * @param query
+ * @param context
+ * @return Components with "extended" flag. See
org.jboss.tools.jst.web.kb.taglib.ICustomTagLibComponent#isExtended()
+ */
+ Set<ICustomTagLibComponent> getExtendedComponents(KbQuery query, IPageContext
context);
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/ITagLibrary.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/ITagLibrary.java 2009-06-05
13:25:00 UTC (rev 15730)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/ITagLibrary.java 2009-06-05
13:35:44 UTC (rev 15731)
@@ -22,18 +22,27 @@
*/
public interface ITagLibrary extends IProposalProcessor {
+ /**
+ * @return source path
+ */
public IPath getSourcePath();
/**
* @return name space
*/
INameSpace getDefaultNameSpace();
+
/**
* @return URI of the tag lib.
*/
String getURI();
/**
+ * @return version of the tag lib.
+ */
+ String getVersion();
+
+ /**
* @return resource of this tag lib.
*/
IResource getResource();
@@ -62,6 +71,10 @@
*/
public IComponent[] getComponents(KbQuery query, IPageContext context);
+ /**
+ * Clone the lib
+ * @return
+ * @throws CloneNotSupportedException
+ */
public ITagLibrary clone() throws CloneNotSupportedException;
-
-}
+}
\ No newline at end of file