Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7ba62383a32e5d5c9621f16a3038b413bbf9f475 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package org.eclipse.jst.jsf.facelet.core.internal.registry;

import org.eclipse.core.resources.IProject;
import org.eclipse.jem.internal.proxy.core.IConfigurationContributor;
import org.eclipse.jst.jsf.common.dom.TagIdentifier;
import org.eclipse.jst.jsf.common.runtime.internal.model.component.ComponentTypeInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.decorator.ConverterTypeInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.decorator.ValidatorTypeInfo;
import org.eclipse.jst.jsf.common.runtime.internal.view.model.common.ITagElement;
import org.eclipse.jst.jsf.core.internal.tld.TagIdentifierFactory;
import org.eclipse.jst.jsf.designtime.internal.view.DTComponentIntrospector;
import org.eclipse.jst.jsf.designtime.internal.view.mapping.ViewMetadataLoader;
import org.eclipse.jst.jsf.designtime.internal.view.model.jsp.AbstractTagResolvingStrategy;
import org.eclipse.jst.jsf.designtime.internal.view.model.jsp.IAttributeAdvisor;
import org.eclipse.jst.jsf.facelet.core.internal.cm.FaceletDocumentFactory;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib.FaceletTaglibTag;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib_1_0.ComponentTagDefn;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib_1_0.ConverterTagDefn;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib_1_0.HandlerTagDefn;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib_1_0.SourceTagDefn;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib_1_0.ValidatorTagDefn;
import org.eclipse.jst.jsf.facelet.core.internal.tagmodel.ComponentTag;
import org.eclipse.jst.jsf.facelet.core.internal.tagmodel.ConverterTag;
import org.eclipse.jst.jsf.facelet.core.internal.tagmodel.FaceletTag;
import org.eclipse.jst.jsf.facelet.core.internal.tagmodel.HandlerTag;
import org.eclipse.jst.jsf.facelet.core.internal.tagmodel.NoArchetypeFaceletTag;
import org.eclipse.jst.jsf.facelet.core.internal.tagmodel.SourceTag;
import org.eclipse.jst.jsf.facelet.core.internal.tagmodel.ValidatorTag;

/*package*/class FaceletTagResolvingStrategy
        extends
        AbstractTagResolvingStrategy<IFaceletTagResolvingStrategy.TLDWrapper, String>
        implements IFaceletTagResolvingStrategy
{
    public final static String           ID = "org.eclipse.jst.jsf.facelet.core.FaceletTagResolvingStrategy"; //$NON-NLS-1$
    private final IProject               _project;
    private final FaceletDocumentFactory _factory;
    private final ViewMetadataLoader     _viewLoader;

    public FaceletTagResolvingStrategy(final IProject project,
            final FaceletDocumentFactory factory)
    {
        _project = project;
        _factory = factory;
        _viewLoader = new ViewMetadataLoader(project);
    }

    @Override
    public final String getId()
    {
        return ID;
    }

    @Override
    public final ITagElement resolve(final TLDWrapper tldWrapper)
    {
        return createFaceletTag(tldWrapper.getUri(), tldWrapper.getTagDefn());
    }

    public final String getDisplayName()
    {
        return Messages.FaceletTagResolvingStrategy_FACELET_TAG_RESOLVER_DISPLAY_NAME;
    }

    private FaceletTag createFaceletTag(final String uri, final FaceletTaglibTag tagDefn)
    {
        final String tagName = tagDefn.getTagName();
        final TagIdentifier tagId = TagIdentifierFactory.createJSPTagWrapper(
                uri, tagName);

        final IAttributeAdvisor advisor = new MetadataAttributeAdvisor(tagId,
                _viewLoader, tagDefn.getAttribute());

        if (tagDefn instanceof ComponentTagDefn)
        {
            final ComponentTagDefn componentTagDefn = (ComponentTagDefn) tagDefn;
            final String componentType = componentTagDefn.getComponentType();
            final String componentClass = DTComponentIntrospector
                    .findComponentClass(componentType, _project);

            ComponentTypeInfo typeInfo = null;

            if (componentClass != null)
            {
                typeInfo = DTComponentIntrospector.getComponent(componentType,
                        componentClass, _project,
                        new IConfigurationContributor[]
                        { new ELProxyContributor(_project) });
            }
            return new ComponentTag(uri, tagName, typeInfo, safeGetString(componentTagDefn.getHandlerClass()), _factory, advisor);
        }
        // render type is optional, but must have component type
        else if (tagDefn instanceof ValidatorTagDefn)
        {
            final ValidatorTagDefn validatorTagDefn = (ValidatorTagDefn) tagDefn;
            final String validatorId = validatorTagDefn.getValidatorId();

            ValidatorTypeInfo typeInfo;

            if (validatorId != null)
            {
                final String validatorClass = DTComponentIntrospector
                        .findValidatorClass(validatorId, _project);
                typeInfo = new ValidatorTypeInfo(validatorClass, validatorId);
            }
            else
            {
                typeInfo = ValidatorTypeInfo.UNKNOWN;
            }

            return new ValidatorTag(uri, tagName, typeInfo, safeGetString(validatorTagDefn.getHandlerClass()), _factory,
                    advisor);
        }
        // render type is optional, but must have converter id
        else if (tagDefn instanceof ConverterTagDefn)
        {
            final ConverterTagDefn converterTagDefn = (ConverterTagDefn) tagDefn;
            final String converterId = converterTagDefn.getConverterId();

            ConverterTypeInfo typeInfo;

            if (converterId != null)
            {
                final String converterClass = DTComponentIntrospector
                        .findConverterClass(converterId, _project);
                typeInfo = new ConverterTypeInfo(converterClass, converterId);
            }
            else
            {
                typeInfo = ConverterTypeInfo.UNKNOWN;
            }

            // for now, all converters are unknown
            return new ConverterTag(uri, tagName, typeInfo, 
                    safeGetString(converterTagDefn.getHandlerClass()), _factory, advisor);
        }
        else if (tagDefn instanceof HandlerTagDefn)
        {
            final String handlerClass = safeGetString(((HandlerTagDefn)tagDefn).getHandlerClass());
            return new HandlerTag(uri, tagName, null, handlerClass, _factory, advisor);
        }
        else if (tagDefn instanceof SourceTagDefn)
        {
            final String source = ((SourceTagDefn)tagDefn).getSource();
            return new SourceTag(uri, tagName, source, _factory, advisor);
        }

        return new NoArchetypeFaceletTag(uri, tagName, _factory, advisor);
    }
    
    private static String safeGetString(final String value)
    {
        if (value == null)
        {
            return null;
        }
        
        final String trimmed = value.trim();
        
        if ("".equals(trimmed)) //$NON-NLS-1$
        {
            return null;
        }
        
        return trimmed;
    }
}

Back to the top