Skip to main content
summaryrefslogtreecommitdiffstats
blob: 073140fd8d1be834809edaea7939b85143ac6799 (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
package org.eclipse.jst.jsf.facelet.core.internal.registry.taglib;

import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jst.jsf.facelet.core.internal.FaceletCorePlugin;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.IFaceletTagRecord.TagRecordDescriptor;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib.FaceletTaglib;

/**
 * @author cbateman
 * 
 */
public class DefaultStandardTaglibLocator extends AbstractFaceletTaglibLocator
{
    private static final Set<String> taglibLocations;
    static
    {
        final Set<String> set = new HashSet<String>();
        set.add("/std-taglibs/html_basic.taglib.xml"); //$NON-NLS-1$
        set.add("/std-taglibs/html_basic_jcp.taglib.xml"); //$NON-NLS-1$
        set.add("/std-taglibs/composite.taglib.xml"); //$NON-NLS-1$
        set.add("/std-taglibs/composite_jcp.taglib.xml"); //$NON-NLS-1$
        set.add("/std-taglibs/facelets_jsf_core.taglib.xml"); //$NON-NLS-1$
        set.add("/std-taglibs/facelets_jsf_core_jcp.taglib.xml"); //$NON-NLS-1$
        set.add("/std-taglibs/jstl-core.taglib.xml"); //$NON-NLS-1$
        set.add("/std-taglibs/jstl-fn.taglib.xml"); //$NON-NLS-1$
        set.add("/std-taglibs/ui.taglib.xml"); //$NON-NLS-1$
        set.add("/std-taglibs/ui_jcp.taglib.xml"); //$NON-NLS-1$
        taglibLocations = Collections.unmodifiableSet(set);
    }
    private static final Set<MyTagRecordDescriptor> DEFAULT_TAGLIBS;
    static
    {
        Set<MyTagRecordDescriptor>  taglibs = new HashSet<MyTagRecordDescriptor>();
        for (final String location : taglibLocations)
        {
            try
            {
                final URL url = FaceletCorePlugin.getDefault().getBundle()
                        .getEntry(location);
                final URL fileURL = FileLocator.toFileURL(url);
                File file = new File(fileURL.getPath());
                final InputStream openStream = fileURL.openStream();
                final TagModelLoader loader = new TagModelLoader(
                        file.getAbsolutePath());
                loader.loadFromInputStream(openStream);
                final FaceletTaglib taglib = loader.getTaglib();
                MyTagRecordDescriptor desc = new MyTagRecordDescriptor(new Path(fileURL.toString()), taglib);
                taglibs.add(desc);
            } catch (final Exception e)
            {
                FaceletCorePlugin.log(
                        "Trying to load default taglib for: " + location, e); //$NON-NLS-1$
            }
        }
        DEFAULT_TAGLIBS = Collections.unmodifiableSet(taglibs);
    }
    private HashMap<String, IFaceletTagRecord> _defaultRecords;

    /**
     * 
     */
    public DefaultStandardTaglibLocator()
    {
        super("", ""); //$NON-NLS-1$//$NON-NLS-2$
        _defaultRecords = new HashMap<String, IFaceletTagRecord>();
    }

    @Override
    public void start(IProject project)
    {
        final TagRecordFactory factory = new TagRecordFactory(project,
                false);
        
        for (final MyTagRecordDescriptor desc : DEFAULT_TAGLIBS)
        {
            final IFaceletTagRecord record = factory.createRecords(desc.getTaglib(),
                    desc);
            if (record != null)
            {
                _defaultRecords.put(record.getURI(), record);
            }
        }
        super.start(project);
    }

    @Override
    protected Map<String, ? extends IFaceletTagRecord> doLocate(IProject context)
    {
        return Collections.unmodifiableMap(_defaultRecords);
    }

    private static class MyTagRecordDescriptor extends TagRecordDescriptor
    {
        private final IPath _path;
        private final FaceletTaglib  _taglib;
        
        public MyTagRecordDescriptor(final IPath path, final FaceletTaglib taglib)
        {
            super(Source.JAR);
            _path = path;
            _taglib = taglib;
        }

        @Override
        public IResource getResource()
        {
            return null;
        }

        @Override
        public IPath getPath()
        {
            return _path;
        }

        public FaceletTaglib getTaglib()
        {
            return _taglib;
        }
    }
}

Back to the top