Author: akazakov
Date: 2009-06-18 10:52:48 -0400 (Thu, 18 Jun 2009)
New Revision: 16040
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/text/TextProposal.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml
trunk/jst/plugins/org.jboss.tools.jst.web.kb/schema/tagLib.exsd
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/CustomComponentExtension.java
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/CustomTagLibrary.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/ELFunction.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/CustomTagLibManager.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2808
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/text/TextProposal.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/text/TextProposal.java 2009-06-18
12:31:56 UTC (rev 16039)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/text/TextProposal.java 2009-06-18
14:52:48 UTC (rev 16040)
@@ -32,6 +32,7 @@
private static final long serialVersionUID = 3257007635692926512L;
+ private Object source;
private String label;
private String contextInfo;
private Image image;
@@ -287,8 +288,22 @@
if(postProcessing != null) postProcessing.process(this, value, offset);
}
- public static final Comparator<TextProposal> KB_PROPOSAL_ORDER = new
TextProposalComparator();
+ /**
+ * @return the source
+ */
+ public Object getSource() {
+ return source;
+ }
+ /**
+ * @param source the source to set
+ */
+ public void setSource(Object source) {
+ this.source = source;
+ }
+
+ public static final Comparator<TextProposal> KB_PROPOSAL_ORDER = new
TextProposalComparator();
+
private static class TextProposalComparator implements Comparator<TextProposal>
{
public int compare(TextProposal p1, TextProposal p2) {
int n1=p1.replacementString.length(), n2=p2.replacementString.length();
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml 2009-06-18 12:31:56 UTC (rev
16039)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml 2009-06-18 14:52:48 UTC (rev
16040)
@@ -27,5 +27,38 @@
id="org.jboss.tools.jst.web.kb.kbbuilder">
</builder>
</extension>
+ <extension
+ point="org.jboss.tools.jst.web.kb.tagLib">
+ <tag-lib
+ location="taglibs/Ajax4jsf.xml"
+ name="JBoss Ajax4jsf"
+
uri="http://richfaces.org/a4j"/>
+ <tag-lib
+ location="taglibs/Richfaces.xml"
+ name="JBoss RichFaces"
+
uri="http://richfaces.org/rich"/>
+ <tag-lib
+ location="taglibs/JsfCore.xml"
+ name="JSF Core"
+
uri="http://java.sun.com/jsf/core"/>
+ <tag-lib
+ location="taglibs/JsfHtmlBasic.xml"
+ name="JSF HTML Basic"
+
uri="http://java.sun.com/jsf/html"/>
+ <tag-lib
+ location="taglibs/Facelets.xml"
+ name="Facelets UI"
+
uri="http://java.sun.com/jsf/facelets"/>
+ <tag-lib
+ location="taglibs/FaceletsHtml.xml"
+ name="Facelets Html"
+
uri="http://www.w3.org/1999/xhtml/facelets"/>
+ <tag-lib
+ location="taglibs/JBossSeam.xml"
+ name="JBoss Seam"
+
uri="http://jboss.com/products/seam/taglib"/>
+ <component-extension
+ location="taglibs/componentExtension.xml"/>
+ </extension>
</plugin>
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/schema/tagLib.exsd
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/schema/tagLib.exsd 2009-06-18 12:31:56
UTC (rev 16039)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/schema/tagLib.exsd 2009-06-18 14:52:48
UTC (rev 16040)
@@ -18,7 +18,8 @@
</annotation>
<complexType>
<sequence>
- <element ref="tag-lib" minOccurs="1"
maxOccurs="unbounded"/>
+ <element ref="tag-lib" minOccurs="0"
maxOccurs="unbounded"/>
+ <element ref="component-extension" minOccurs="0"
maxOccurs="1"/>
</sequence>
<attribute name="point" type="string"
use="required">
<annotation>
@@ -83,6 +84,21 @@
</complexType>
</element>
+ <element name="component-extension">
+ <complexType>
+ <attribute name="location" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="resource"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
<annotation>
<appInfo>
<meta.section type="since"/>
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-18
12:31:56 UTC (rev 16039)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageProcessor.java 2009-06-18
14:52:48 UTC (rev 16040)
@@ -11,6 +11,8 @@
package org.jboss.tools.jst.web.kb;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
import org.jboss.tools.common.el.core.resolver.ELResolver;
import org.jboss.tools.common.text.TextProposal;
@@ -57,8 +59,28 @@
proposals.add(libProposals[j]);
}
}
+ if (query.getType() == KbQuery.Type.ATTRIBUTE_VALUE) {
+ Map<String, IAttribute> attrbMap = new HashMap<String, IAttribute>();
+ for (TextProposal proposal : proposals) {
+ if(proposal.getSource()!=null && proposal.getSource() instanceof IAttribute)
{
+ IAttribute att = (IAttribute)proposal.getSource();
+ attrbMap.put(att.getName(), att);
+ }
+ }
+ for (int i = 0; i < componentExtensions.length; i++) {
+ if(attrbMap.containsKey(componentExtensions[i].getName())) {
+ TextProposal[] attProposals = componentExtensions[i].getProposals(query, context);
+ for (int j = 0; j < attProposals.length; j++) {
+ proposals.add(attProposals[j]);
+ }
+ }
+ }
+ }
for (int i = 0; customTagLibs != null && i < customTagLibs.length; i++) {
- // TODO
+ TextProposal[] libProposals = customTagLibs[i].getProposals(query, context);
+ for (int j = 0; libProposals != null && j < libProposals.length; j++) {
+ proposals.add(libProposals[j]);
+ }
}
} else {
String value = query.getValue();
@@ -90,17 +112,33 @@
* @return components
*/
public IComponent[] getComponents(KbQuery query, IPageContext context) {
+ return getComponents(query, context, false);
+ }
+
+ private IComponent[] getComponents(KbQuery query, IPageContext context, boolean
includeComponentExtensions) {
ArrayList<IComponent> components = new ArrayList<IComponent>();
ITagLibrary[] libs = context.getLibraries();
for (int i = 0; i < libs.length; i++) {
IComponent[] libComponents = libs[i].getComponents(query, context);
for (int j = 0; j < libComponents.length; j++) {
- components.add(libComponents[i]);
+ if(includeComponentExtensions || !libComponents[i].isExtended()) {
+ components.add(libComponents[i]);
+ }
}
}
+ for (int i = 0; customTagLibs != null && i < customTagLibs.length; i++) {
+ IComponent[] libComponents = customTagLibs[i].getComponents(query, context);
+ for (int j = 0; j < libComponents.length; j++) {
+ if(includeComponentExtensions || !libComponents[i].isExtended()) {
+ components.add(libComponents[i]);
+ }
+ }
+ }
return components.toArray(new IComponent[components.size()]);
}
+ private final static IAttribute[] EMPTY_ATTRIBUTE_ARRAY = new IAttribute[0];
+
/**
* Returns attributes
* @param query
@@ -108,16 +146,24 @@
* @return attributes
*/
public IAttribute[] getAttributes(KbQuery query, IPageContext context) {
- ArrayList<IAttribute> attributes = new ArrayList<IAttribute>();
if(query.getType() == KbQuery.Type.ATTRIBUTE_NAME || query.getType() ==
KbQuery.Type.ATTRIBUTE_VALUE) {
- IComponent[] components = getComponents(query, context);
+ ArrayList<IAttribute> attributes = new ArrayList<IAttribute>();
+ Map<String, IAttribute> attrbMap = new HashMap<String, IAttribute>();
+ IComponent[] components = getComponents(query, context, true);
for (int i = 0; i < components.length; i++) {
IAttribute[] libAttributess = components[i].getAttributes(query, context);
for (int j = 0; j < libAttributess.length; j++) {
attributes.add(libAttributess[i]);
+ attrbMap.put(libAttributess[i].getName(), libAttributess[i]);
}
}
+ for (int i = 0; i < componentExtensions.length; i++) {
+ if(attrbMap.containsKey(componentExtensions[i].getName())) {
+ attributes.add(componentExtensions[i]);
+ }
+ }
+ return attributes.toArray(new IAttribute[attributes.size()]);
}
- return attributes.toArray(new IAttribute[attributes.size()]);
+ return EMPTY_ATTRIBUTE_ARRAY;
}
}
\ 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/AbstractAttribute.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractAttribute.java 2009-06-18
12:31:56 UTC (rev 16039)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractAttribute.java 2009-06-18
14:52:48 UTC (rev 16040)
@@ -34,7 +34,7 @@
* @author Alexey Kazakov
*/
public abstract class AbstractAttribute extends KbObject implements IAttribute {
- public static final String REQUIRED = "required";
+ public static final String REQUIRED = "required"; //$NON-NLS-1$
protected String description;
protected String name;
@@ -100,7 +100,7 @@
}
public void setRequired(IValueInfo s) {
- required = s != null && "true".equals(s.getValue());
+ required = s != null && "true".equals(s.getValue()); //$NON-NLS-1$
attributesInfo.put(REQUIRED, s);
}
@@ -117,19 +117,24 @@
*/
public TextProposal[] getProposals(KbQuery query, IPageContext context) {
List<TextProposal> proposals = null;
- ELResolver[] resolvers = context.getElResolvers();
- for (int i = 0; i < resolvers.length; i++) {
- List<TextProposal> list = resolvers[i].getCompletions(query.getValue(), false,
query.getValue().length(), context);
- if(list == null || list.isEmpty()) continue;
- if(proposals == null) {
- proposals = new ArrayList<TextProposal>();
- }
- proposals.addAll(list);
- }
- if(proposals == null || proposals.isEmpty()) {
- return EMPTY_PROPOSAL_LIST;
- }
- return proposals.toArray(new TextProposal[proposals.size()]);
+// ELResolver[] resolvers = context.getElResolvers();
+// for (int i = 0; i < resolvers.length; i++) {
+// List<TextProposal> list = resolvers[i].getCompletions(query.getValue(), false,
query.getValue().length(), context);
+// if(list == null || list.isEmpty()) continue;
+// if(proposals == null) {
+// proposals = new ArrayList<TextProposal>();
+// }
+// for (TextProposal textProposal : list) {
+// textProposal.setSource(this);
+// proposals.add(textProposal);
+// }
+// }
+// if(proposals == null || proposals.isEmpty()) {
+// return EMPTY_PROPOSAL_LIST;
+// }
+// return proposals.toArray(new TextProposal[proposals.size()]);
+ // TODO
+ return EMPTY_PROPOSAL_LIST;
}
/*
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-18
12:31:56 UTC (rev 16039)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractComponent.java 2009-06-18
14:52:48 UTC (rev 16040)
@@ -334,6 +334,7 @@
proposals = new ArrayList<TextProposal>();
for (int i = 0; i < attributes.length; i++) {
TextProposal proposal = new TextProposal();
+ proposal.setSource(attributes[i]);
proposal.setContextInfo(attributes[i].getDescription());
proposal.setReplacementString(attributes[i].getName());
proposal.setLabel(attributes[i].getName());
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-18
12:31:56 UTC (rev 16039)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java 2009-06-18
14:52:48 UTC (rev 16040)
@@ -51,6 +51,7 @@
protected boolean hasExtendedComponents = false;
private Map<String, IComponent> components = new HashMap<String,
IComponent>();
private IComponent[] componentsArray;
+ protected CustomComponentExtension componentExtension;
/* (non-Javadoc)
* @see org.jboss.tools.jst.web.kb.taglib.TagLibrary#getAllComponents()
@@ -82,7 +83,7 @@
List<IComponent> list = new ArrayList<IComponent>();
IComponent[] comps = getComponents();
for (int i = 0; i < comps.length; i++) {
- if(comps[i].getName().startsWith(nameTemplate) && (context==null ||
checkExtended(comps[i], context))) {
+ if(!(comps[i] instanceof CustomComponentExtension) &&
comps[i].getName().startsWith(nameTemplate) && (context==null ||
checkExtended(comps[i], context))) {
list.add(comps[i]);
}
}
@@ -158,10 +159,14 @@
return EMPTY_ARRAY;
}
IComponent comp = getComponent(tagName);
+ List<IComponent> result = new ArrayList<IComponent>();
if(comp != null && checkExtended(comp, context)) {
- return new IComponent[]{comp};
+ result.add(comp);
}
- return EMPTY_ARRAY;
+ if(componentExtension!=null) {
+ result.add(componentExtension);
+ }
+ return result.isEmpty()?EMPTY_ARRAY:result.toArray(new IComponent[0]);
}
protected IComponent[] getExtendedComponents(IPageContext context) {
@@ -180,7 +185,7 @@
}
protected boolean checkExtended(IComponent component, IPageContext context) {
- if(!component.isExtended()) {
+ if(!component.isExtended() || component instanceof CustomComponentExtension) {
return true;
}
ITagLibrary[] libs = context.getLibraries();
@@ -315,7 +320,9 @@
IComponent[] components = getComponents(query, prefix, context);
if(query.getType() == KbQuery.Type.TAG_NAME) {
for (int i = 0; i < components.length; i++) {
- proposals.add(getProposal(prefix, components[i]));
+ if(!(components[i] instanceof CustomComponentExtension)) {
+ proposals.add(getProposal(prefix, components[i]));
+ }
}
} else {
for (int i = 0; i < components.length; i++) {
@@ -333,6 +340,7 @@
protected TextProposal getProposal(String prefix, IComponent component) {
TextProposal proposal = new TextProposal();
proposal.setContextInfo(component.getDescription());
+ proposal.setSource(component);
StringBuffer label = new StringBuffer();
if(prefix!=null) {
label.append(prefix + KbQuery.PREFIX_SEPARATOR);
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomComponentExtension.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomComponentExtension.java 2009-06-18
12:31:56 UTC (rev 16039)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomComponentExtension.java 2009-06-18
14:52:48 UTC (rev 16040)
@@ -15,6 +15,10 @@
*/
public class CustomComponentExtension extends CustomTagLibComponent {
+ public CustomComponentExtension() {
+ setName("*");
+ }
+
/*
* (non-Javadoc)
* @see org.jboss.tools.jst.web.kb.taglib.IComponent#isExtended()
Modified:
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 2009-06-18
12:31:56 UTC (rev 16039)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomTagLibAttribute.java 2009-06-18
14:52:48 UTC (rev 16040)
@@ -10,6 +10,12 @@
******************************************************************************/
package org.jboss.tools.jst.web.kb.internal.taglib;
+import java.util.ArrayList;
+import java.util.List;
+
+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.IComponent;
/**
@@ -17,6 +23,8 @@
*/
public class CustomTagLibAttribute extends AbstractAttribute {
+ private final static String ENUMERATION_TYPE = "enumeration"; //$NON-NLS-1$
+
protected boolean extended = true;
protected String defaultValue;
protected Proposal[] proposals;
@@ -54,6 +62,20 @@
this.defaultValue = defaultValue;
}
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.internal.taglib.AbstractAttribute#getProposals(org.jboss.tools.jst.web.kb.KbQuery,
org.jboss.tools.jst.web.kb.IPageContext)
+ */
+ @Override
+ public TextProposal[] getProposals(KbQuery query, IPageContext context) {
+ Proposal[] prDefs = getProposals();
+ List<TextProposal> proposals = new ArrayList<TextProposal>();
+ for (int i = 0; i < prDefs.length; i++) {
+ // TODO
+ }
+ return proposals.toArray(new TextProposal[0]);
+ }
+
/**
* @return the proposals
*/
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-18
12:31:56 UTC (rev 16039)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/CustomTagLibrary.java 2009-06-18
14:52:48 UTC (rev 16040)
@@ -58,7 +58,6 @@
protected String name;
protected String defaultPrefix;
- protected CustomComponentExtension componentExtension;
public CustomTagLibrary(File file, String uri, String version, String name) {
setURI(uri);
@@ -87,8 +86,7 @@
} else if (child.getNodeName().equals(COMPONET_EXTENSION)) {
if(componentExtension==null) {
componentExtension = new CustomComponentExtension();
- // TODO what we should do with this fake components?
-// addComponent(componentExtension);
+ addComponent(componentExtension);
componentExtension.setParentTagLib(this);
}
componentExtension.addAttributes(getAttributes((Element)child));
@@ -120,7 +118,7 @@
return newComponent;
}
- protected CustomTagLibAttribute[] getAttributes(Element component) {
+ public static CustomTagLibAttribute[] getAttributes(Element component) {
Set<CustomTagLibAttribute> newAttributes = new
HashSet<CustomTagLibAttribute>();
NodeList children = component.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
@@ -175,7 +173,7 @@
return newAttributes.toArray(new CustomTagLibAttribute[0]);
}
- private String getDescription(Element element) {
+ public static String getDescription(Element element) {
NodeList list = element.getChildNodes();
for(int i=0; i<list.getLength(); i++) {
Node node = list.item(i);
@@ -188,7 +186,7 @@
return null;
}
- private String getElementBody(Element element) {
+ public static String getElementBody(Element element) {
StringBuffer sb = new StringBuffer();
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
@@ -201,7 +199,7 @@
return sb.toString();
}
- private DocumentBuilder createDocumentBuilder(boolean validate) throws
ParserConfigurationException {
+ public static DocumentBuilder createDocumentBuilder(boolean validate) throws
ParserConfigurationException {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setValidating(validate);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/ELFunction.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/ELFunction.java 2009-06-18
12:31:56 UTC (rev 16039)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/ELFunction.java 2009-06-18
14:52:48 UTC (rev 16040)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * 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.Properties;
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-18
12:31:56 UTC (rev 16039)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/taglib/CustomTagLibManager.java 2009-06-18
14:52:48 UTC (rev 16040)
@@ -15,6 +15,9 @@
import java.util.HashSet;
import java.util.Set;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
@@ -25,6 +28,9 @@
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;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
/**
* @author Alexey Kazakov
@@ -34,10 +40,14 @@
private static final CustomTagLibManager INSTANCE = new CustomTagLibManager();
private ICustomTagLibrary[] libs = null;
+ private CustomTagLibAttribute[] extensions = null;
private CustomTagLibManager() {
}
+ /**
+ * @return an instance of this manager.
+ */
public static CustomTagLibManager getInstance() {
return INSTANCE;
}
@@ -50,48 +60,97 @@
*/
public ICustomTagLibrary[] getLibraries() {
if(libs==null) {
- Set<ICustomTagLibrary> libSet = new HashSet<ICustomTagLibrary>();
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IExtensionPoint extensionPoint =
registry.getExtensionPoint("org.jboss.tools.jst.web.kb.KbTagLib");
//$NON-NLS-1$
- if (extensionPoint == null)
- return null;
+ init();
+ }
+ return libs;
+ }
+
+ /**
+ * @return Array of attributes witch should be used only if they are present in other
tag libraries.
+ */
+ public CustomTagLibAttribute[] getComponentExtensions() {
+ if(extensions==null) {
+ init();
+ }
+ return extensions;
+ }
+
+ private void init() {
+ Set<ICustomTagLibrary> libSet = new HashSet<ICustomTagLibrary>();
+ Set<CustomTagLibAttribute> extensionSet = new
HashSet<CustomTagLibAttribute>();
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint extensionPoint =
registry.getExtensionPoint("org.jboss.tools.jst.web.kb.KbTagLib");
//$NON-NLS-1$
+ if (extensionPoint != null) {
IExtension[] extensions = extensionPoint.getExtensions();
for (int i=0; i<extensions.length; i++) {
IExtension extension = extensions[i];
IConfigurationElement[] elements = extension.getConfigurationElements();
for(int j=0; j<elements.length; j++) {
- String uri = elements[j].getAttribute("uri"); //$NON-NLS-1$
- String location = elements[j].getAttribute("location"); //$NON-NLS-1$
- String version = elements[j].getAttribute("version"); //$NON-NLS-1$
- String name = elements[j].getAttribute("version"); //$NON-NLS-1$
- Bundle sourcePlugin = Platform.getBundle(elements[j].getNamespaceIdentifier());
- File schemaLocation = null;
- try {
- String pluginPath =
FileLocator.resolve(sourcePlugin.getEntry("/")).getPath();
- if(uri==null || uri.length()==0 || location==null || location.length()==0) {
- WebKbPlugin.getDefault().logWarning("Incorrect
org.jboss.tools.jst.web.kb.KbTagLib extension in " + pluginPath + " plugin. URI
or location can't be empty."); //$NON-NLS-1$ $NON-NLS-2$
+ String elementName = elements[j].getName();
+ if("tag-lib".equals(elementName)) {
+ String uri = elements[j].getAttribute("uri"); //$NON-NLS-1$
+ String location = elements[j].getAttribute("location"); //$NON-NLS-1$
+ String version = elements[j].getAttribute("version"); //$NON-NLS-1$
+ String name = elements[j].getAttribute("name"); //$NON-NLS-1$
+ Bundle sourcePlugin = Platform.getBundle(elements[j].getNamespaceIdentifier());
+ File schemaLocation = null;
+ try {
+ String pluginPath =
FileLocator.resolve(sourcePlugin.getEntry("/")).getPath();
+ if(uri==null || uri.length()==0 || location==null || location.length()==0) {
+ WebKbPlugin.getDefault().logWarning("Incorrect
org.jboss.tools.jst.web.kb.KbTagLib extension in " + pluginPath + " plugin. URI
or location can't be empty."); //$NON-NLS-1$ $NON-NLS-2$
+ continue;
+ }
+ schemaLocation = new File(pluginPath, location);
+ } catch (IOException e) {
+ WebKbPlugin.getDefault().logError(e);
continue;
}
- schemaLocation = new File(pluginPath, location);
- } catch (IOException e) {
- WebKbPlugin.getDefault().logError(e);
- continue;
+ if(schemaLocation.isFile()) {
+ CustomTagLibrary lib = new CustomTagLibrary(schemaLocation, uri, version, name);
+ libSet.add(lib);
+ } else {
+ WebKbPlugin.getDefault().logWarning("Can't load KB schema: " +
schemaLocation); //$NON-NLS-1$
+ }
+ } else if("component-extension".equals(elementName)) {
+ String location = elements[j].getAttribute("location"); //$NON-NLS-1$
+ Bundle sourcePlugin = Platform.getBundle(elements[j].getNamespaceIdentifier());
+ File schemaLocation = null;
+ try {
+ String pluginPath =
FileLocator.resolve(sourcePlugin.getEntry("/")).getPath();
+ if(location==null || location.length()==0) {
+ WebKbPlugin.getDefault().logWarning("Incorrect
org.jboss.tools.jst.web.kb.KbTagLib extension in " + pluginPath + " plugin.
Location can't be empty."); //$NON-NLS-1$ $NON-NLS-2$
+ continue;
+ }
+ schemaLocation = new File(pluginPath, location);
+ } catch (IOException e) {
+ WebKbPlugin.getDefault().logError(e);
+ continue;
+ }
+ if(schemaLocation.isFile()) {
+ Document document = null;
+ try {
+ DocumentBuilder builder = CustomTagLibrary.createDocumentBuilder(false);
+ document = builder.parse(schemaLocation);
+ } catch (SAXException e) {
+ WebKbPlugin.getDefault().logError(e);
+ } catch (IOException e) {
+ WebKbPlugin.getDefault().logError(e);
+ } catch (ParserConfigurationException e) {
+ WebKbPlugin.getDefault().logError(e);
+ }
+ Element root = document.getDocumentElement();
+ CustomTagLibAttribute[] attributes = CustomTagLibrary.getAttributes(root);
+ for (int k = 0; k < attributes.length; k++) {
+ extensionSet.add(attributes[k]);
+ }
+ } else {
+ WebKbPlugin.getDefault().logWarning("Can't load KB schema: " +
schemaLocation); //$NON-NLS-1$
+ }
}
- if(schemaLocation.isFile()) {
- CustomTagLibrary lib = new CustomTagLibrary(schemaLocation, uri, version, name);
- libSet.add(lib);
- } else {
- WebKbPlugin.getDefault().logWarning("Can't load KB schema: " +
schemaLocation); //$NON-NLS-1$
- }
}
}
- libs = libSet.toArray(new ICustomTagLibrary[0]);
}
- return libs;
+ libs = libSet.toArray(new ICustomTagLibrary[0]);
+ extensions = extensionSet.toArray(new CustomTagLibAttribute[0]);
}
-
- public CustomTagLibAttribute[] getComponentExtensions() {
- //TODO
- return null;
- }
}
\ No newline at end of file