diff options
author | itrimble | 2010-04-23 15:58:37 +0000 |
---|---|---|
committer | itrimble | 2010-04-23 15:58:37 +0000 |
commit | d0f82d193872ce61bc37915d1e4d3b3d06340872 (patch) | |
tree | c673f10d18c62e1e37122780e68a291668366432 /jsf | |
parent | 06a20c3751d043d71132a481878cd23393ae5fd0 (diff) | |
download | webtools.jsf-d0f82d193872ce61bc37915d1e4d3b3d06340872.tar.gz webtools.jsf-d0f82d193872ce61bc37915d1e4d3b3d06340872.tar.xz webtools.jsf-d0f82d193872ce61bc37915d1e4d3b3d06340872.zip |
Bug 295514 - [JSF2.0] -- create content types for Facelets
Diffstat (limited to 'jsf')
3 files changed, 216 insertions, 181 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/META-INF/MANIFEST.MF b/jsf/plugins/org.eclipse.jst.jsf.core/META-INF/MANIFEST.MF index 95d3977d5..d89d2c13e 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/META-INF/MANIFEST.MF +++ b/jsf/plugins/org.eclipse.jst.jsf.core/META-INF/MANIFEST.MF @@ -38,7 +38,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)", org.eclipse.wst.css.core;bundle-version="[1.1.200,1.2.0)", org.eclipse.debug.core;bundle-version="[3.5.0,4.0.0)", org.eclipse.ui;bundle-version="3.6.0" -Bundle-ActivationPolicy: lazy +Bundle-ActivationPolicy: lazy;exclude:="org.eclipse.jst.jsf.core.internal.contenttype" Export-Package: org.eclipse.jst.jsf.core, org.eclipse.jst.jsf.core.internal;x-friends:="org.eclipse.jst.jsf.core.tests,org.eclipse.jst.jsf.ui,org.eclipse.jst.jsf.ui.tests", org.eclipse.jst.jsf.core.internal.contentassist.el;x-friends:="org.eclipse.jst.jsf.contentassist.tests", diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/plugin.xml b/jsf/plugins/org.eclipse.jst.jsf.core/plugin.xml index 44692f0b3..195a9a484 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/plugin.xml +++ b/jsf/plugins/org.eclipse.jst.jsf.core/plugin.xml @@ -483,32 +483,43 @@ </import-definitions> </extension> + <!-- Facelet Content Types --> + <extension + point="org.eclipse.core.contenttype.contentTypes"> + <content-type + base-type="org.eclipse.wst.html.core.htmlsource" + default-charset="UTF-8" + file-extensions="xhtml" + id="jsf.facelet" + name="%Facelet.name" + priority="high"> + <describer + class="org.eclipse.jst.jsf.core.internal.contenttype.XMLDocumentElementAttributeContentDescriber"> + <parameter + name="xmlns:.*" + value=".*jsf.*"> + </parameter> + <parameter + name="xmlns:.*" + value=".*faces.*"> + </parameter> + </describer> + </content-type> + <content-type + base-type="jsf.facelet" + default-charset="UTF-8" + file-extensions="xhtml" + id="jsf.facelet.composite" + name="%FaceletComposite.name" + priority="high"> + <describer + class="org.eclipse.jst.jsf.core.internal.contenttype.XMLDocumentElementAttributeContentDescriber"> + <parameter + name="xmlns:.*" + value="http://java.sun.com/jsf/composite"> + </parameter> + </describer> + </content-type> + </extension> - <!-- <extension point="org.eclipse.core.contenttype.contentTypes"> - <content-type - base-type="org.eclipse.wst.html.core.htmlsource" - default-charset="UTF-8" - describer="org.eclipse.jst.jsf.core.internal.contenttype.XMLDocumentElementAttributeContentDescriber" - file-extensions="xhtml" - id="jsf.facelet" - name="%Facelet.name" - priority="high"> - <describer class="org.eclipse.jst.jsf.core.internal.contenttype.XMLDocumentElementAttributeContentDescriber"> - <parameter name="xmlns:.*" value=".*jsf.*" /> - <parameter name="xmlns:.*" value=".*faces.*" /> - </describer> - </content-type> - <content-type - base-type="jsf.facelet" - default-charset="UTF-8" - describer="org.eclipse.jst.jsf.core.internal.contenttype.XMLDocumentElementAttributeContentDescriber" - file-extensions="xhtml" - id="jsf.facelet.composite" - name="%FaceletComposite.name" - priority="high"> - <describer class="org.eclipse.jst.jsf.core.internal.contenttype.XMLDocumentElementAttributeContentDescriber"> - <parameter name="xmlns:.*" value="http://java.sun.com/jsf/composite" /> - </describer> - </content-type> - </extension> --> </plugin> diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/contenttype/XMLDocumentElementAttributeContentDescriber.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/contenttype/XMLDocumentElementAttributeContentDescriber.java index 1521351e5..cd38062b5 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/contenttype/XMLDocumentElementAttributeContentDescriber.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/contenttype/XMLDocumentElementAttributeContentDescriber.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle Corporation and others. + * All rights reserved. This program and the accompanying materials + * are 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: + * Oracle Corporation - initial API and implementation + *******************************************************************************/ package org.eclipse.jst.jsf.core.internal.contenttype; import java.io.IOException; @@ -15,170 +25,184 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExecutableExtension; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.content.IContentDescription; import org.eclipse.core.runtime.content.ITextContentDescriber; +import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; import org.eclipse.wst.sse.core.utils.StringUtils; import org.eclipse.wst.xml.core.internal.parser.XMLTokenizer; import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; - - /** * Matches the first tag of the content using attribute/value regex pairs. - * - * Ex.:<br/> + * <br/> + * <br/> + * Example:<br/> * <describer class="XMLDocumentElementAttributeContentDescriber"><br/> - * <parameter name="xmlns:ns1" value="http://example.com/ns1" /><br/> - * <parameter name="xmlns:.*" value="http://example.com/ns2" /><br/> + * <parameter name="xmlns:ns1" value="http://example.com/ns1" /><br/> + * <parameter name="xmlns:.*" value="http://example.com/ns2" /><br/> * </describer> */ -public final class XMLDocumentElementAttributeContentDescriber implements ITextContentDescriber, IExecutableExtension { - private static class AttributeValuePatternPair { - Pattern attribute; - Pattern value; - - public AttributeValuePatternPair(Pattern attribute, Pattern value) { - super(); - this.attribute = attribute; - this.value = value; - } - - public String toString() { - return attribute + " : " + value; //$NON-NLS-1$ - } - } - private static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$ - private static final String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$ - - // TODO: support all of the options of the standard HTML content describer? - private final static QualifiedName[] SUPPORTED_OPTIONS = {IContentDescription.BYTE_ORDER_MARK}; - - /* - * Reads from from the stream. Note that the stream will not be - * repositioned when the method returns. Copied from - * org.eclipse.core.internal.content.Util - */ - private static byte[] getByteOrderMark(InputStream input) throws IOException { - int first = input.read(); - if (first == 0xEF) { - // look for the UTF-8 Byte Order Mark (BOM) - int second = input.read(); - int third = input.read(); - if (second == 0xBB && third == 0xBF) - return IContentDescription.BOM_UTF_8; - } - else if (first == 0xFE) { - // look for the UTF-16 BOM - if (input.read() == 0xFF) - return IContentDescription.BOM_UTF_16BE; - } - else if (first == 0xFF) { - if (input.read() == 0xFE) - return IContentDescription.BOM_UTF_16LE; - } - return null; - } - - private AttributeValuePatternPair[] fPairs = null; - - /** - * - */ - public XMLDocumentElementAttributeContentDescriber() { - super(); - } - - private int checkCriteria(Reader contents) throws IOException { - if (fPairs == null || fPairs.length == 0) - return INVALID; - - String attributeName = null; - String attributeValue = null; - - XMLTokenizer tokenizer = new XMLTokenizer(contents); - - String token = tokenizer.primGetNextToken(); - while (token != null && !DOMRegionContext.XML_TAG_CLOSE.equals(token) && !DOMRegionContext.XML_EMPTY_TAG_CLOSE.equals(token)) { - if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(token)) { - attributeName = tokenizer.yytext(); - } - else if (DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE.equals(token)) { - attributeValue = StringUtils.strip(tokenizer.yytext()); - for (int i = 0; i < fPairs.length; i++) { - boolean nameMatched = fPairs[i].attribute.matcher(attributeName).matches(); - if(nameMatched) { - boolean valueMatched = fPairs[i].value.matcher(attributeValue).matches(); - if(valueMatched) { - return VALID; - } - } - } - } - token = tokenizer.primGetNextToken(); - } - return INVALID; - } - - public int describe(InputStream contents, IContentDescription description) throws IOException { - contents.reset(); - byte[] bom = getByteOrderMark(contents); - if (bom != null && description != null) - description.setProperty(IContentDescription.BYTE_ORDER_MARK, bom); - - Object value = description != null ? description.getProperty(IContentDescription.CHARSET) : null; - String charsetName = null; - if (value != null) { - charsetName = value.toString(); - } - else { - if (Arrays.equals(IContentDescription.BOM_UTF_16BE, bom)) { - charsetName = "UTF-16BE"; //$NON-NLS-1$ - } - else if (Arrays.equals(IContentDescription.BOM_UTF_16LE, bom)) { - charsetName = "UTF-16LE"; //$NON-NLS-1$ - } - else { - charsetName = "UTF-8"; //$NON-NLS-1$ - } - } - contents.reset(); - // Check to see if we matched our criteria. - return checkCriteria(new InputStreamReader(contents, Charset.forName(charsetName))); - } - - public int describe(Reader contents, IContentDescription description) throws IOException { - contents.reset(); - // Check to see if we matched our criteria. - return checkCriteria(contents); - } - - public QualifiedName[] getSupportedOptions() { - return SUPPORTED_OPTIONS; - } - - @SuppressWarnings("unchecked") - public void setInitializationData(final IConfigurationElement config, final String propertyName, final Object data) throws CoreException { - if (data instanceof Hashtable) { - IConfigurationElement describerElement = config.getChildren("describer")[0]; //$NON-NLS-1$ - IConfigurationElement[] params = describerElement.getChildren("parameter"); //$NON-NLS-1$ - List<AttributeValuePatternPair> pairs = new ArrayList<AttributeValuePatternPair>(); - for (int i = 0; i < params.length; i++) { - String rawName = params[i].getAttribute(ATTRIBUTE_NAME); - String rawValue = params[i].getAttribute(ATTRIBUTE_VALUE); - if (rawName == null || rawValue == null) - continue; - Pattern attributeName = Pattern.compile(rawName); - Pattern attributeValue = Pattern.compile(rawValue); - pairs.add(new AttributeValuePatternPair(attributeName, attributeValue)); - } - fPairs = pairs.toArray(new AttributeValuePatternPair[pairs.size()]); - } - - if (fPairs == null || fPairs.length == 0) { - throw new CoreException(new Status(IStatus.ERROR, Platform.getBundle("org.eclipse.jst.jsf.contenttypes").getSymbolicName(), 0, "Attributes not specified", null)); //$NON-NLS-1$ //$NON-NLS-2$ - } - } +public final class XMLDocumentElementAttributeContentDescriber + implements ITextContentDescriber, IExecutableExtension { + + private static class AttributeValuePatternPair { + Pattern attribute; + Pattern value; + + public AttributeValuePatternPair(Pattern attribute, Pattern value) { + super(); + this.attribute = attribute; + this.value = value; + } + + public String toString() { + return attribute + " : " + value; //$NON-NLS-1$ + } + } + + private static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$ + private static final String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$ + + // TODO: support all of the options of the standard HTML content describer? + private final static QualifiedName[] SUPPORTED_OPTIONS = {IContentDescription.BYTE_ORDER_MARK}; + + /* + * Reads from from the stream. Note that the stream will not be repositioned when the method + * returns. Copied from org.eclipse.core.internal.content.Util + */ + private static byte[] getByteOrderMark(InputStream input) throws IOException { + int first = input.read(); + if (first == 0xEF) { + // look for the UTF-8 Byte Order Mark (BOM) + int second = input.read(); + int third = input.read(); + if (second == 0xBB && third == 0xBF) + return IContentDescription.BOM_UTF_8; + } + else if (first == 0xFE) { + // look for the UTF-16 BOM + if (input.read() == 0xFF) + return IContentDescription.BOM_UTF_16BE; + } + else if (first == 0xFF) { + if (input.read() == 0xFE) + return IContentDescription.BOM_UTF_16LE; + } + return null; + } + + private AttributeValuePatternPair[] fPairs = null; + + /** + * Create an instance. + */ + public XMLDocumentElementAttributeContentDescriber() { + super(); + } + + private int checkCriteria(Reader contents) throws IOException { + if (fPairs == null || fPairs.length == 0) + return INVALID; + + String attributeName = null; + String attributeValue = null; + + XMLTokenizer tokenizer = new XMLTokenizer(contents); + + String token = tokenizer.primGetNextToken(); + while (token != null && + !DOMRegionContext.XML_TAG_CLOSE.equals(token) && + !DOMRegionContext.XML_EMPTY_TAG_CLOSE.equals(token)) { + + if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(token)) { + attributeName = tokenizer.yytext(); + } + else if (DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE.equals(token)) { + attributeValue = StringUtils.strip(tokenizer.yytext()); + for (int i = 0; i < fPairs.length; i++) { + boolean nameMatched = fPairs[i].attribute.matcher(attributeName).matches(); + if(nameMatched) { + boolean valueMatched = fPairs[i].value.matcher(attributeValue).matches(); + if(valueMatched) { + return VALID; + } + } + } + } + token = tokenizer.primGetNextToken(); + } + return INVALID; + } + + public int describe(InputStream contents, IContentDescription description) throws IOException { + contents.reset(); + byte[] bom = getByteOrderMark(contents); + if (bom != null && description != null) + description.setProperty(IContentDescription.BYTE_ORDER_MARK, bom); + + Object value = + description != null ? description.getProperty(IContentDescription.CHARSET) : null; + String charsetName = null; + if (value != null) { + charsetName = value.toString(); + } + else { + if (Arrays.equals(IContentDescription.BOM_UTF_16BE, bom)) { + charsetName = "UTF-16BE"; //$NON-NLS-1$ + } + else if (Arrays.equals(IContentDescription.BOM_UTF_16LE, bom)) { + charsetName = "UTF-16LE"; //$NON-NLS-1$ + } + else { + charsetName = "UTF-8"; //$NON-NLS-1$ + } + } + contents.reset(); + // Check to see if we matched our criteria. + return checkCriteria(new InputStreamReader(contents, Charset.forName(charsetName))); + } + + public int describe(Reader contents, IContentDescription description) throws IOException { + contents.reset(); + // Check to see if we matched our criteria. + return checkCriteria(contents); + } + + public QualifiedName[] getSupportedOptions() { + return SUPPORTED_OPTIONS; + } + + @SuppressWarnings("unchecked") + public void setInitializationData( + final IConfigurationElement config, + final String propertyName, + final Object data) throws CoreException { + + if (data instanceof String) { + // TODO: why is this here? (imported verbatim from bug attachment) + } + else if (data instanceof Hashtable) { + IConfigurationElement describerElement = config.getChildren("describer")[0]; //$NON-NLS-1$ + IConfigurationElement[] params = describerElement.getChildren("parameter"); //$NON-NLS-1$ + List<AttributeValuePatternPair> pairs = new ArrayList<AttributeValuePatternPair>(); + for (int i = 0; i < params.length; i++) { + String rawName = params[i].getAttribute(ATTRIBUTE_NAME); + String rawValue = params[i].getAttribute(ATTRIBUTE_VALUE); + if (rawName == null || rawValue == null) + continue; + Pattern attributeName = Pattern.compile(rawName); + Pattern attributeValue = Pattern.compile(rawValue); + pairs.add(new AttributeValuePatternPair(attributeName, attributeValue)); + } + fPairs = pairs.toArray(new AttributeValuePatternPair[pairs.size()]); + } + + if (fPairs == null || fPairs.length == 0) { + throw new CoreException( + new Status(IStatus.ERROR, JSFCorePlugin.PLUGIN_ID, 0, + "Attributes not specified", null)); //$NON-NLS-1$ + } + } }
\ No newline at end of file |