aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultResourcePackActivator.java
blob: 5944d095f59e0e10b741f98e97c6a7f532234d55 (plain)
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
/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.plugin.defaultresourcepack;

import java.net.*;
import java.util.*;

import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;

import org.osgi.framework.*;

/**
 *
 * @author damencho
 */
public class DefaultResourcePackActivator
    implements BundleActivator
{
    private Logger logger =
        Logger.getLogger(DefaultResourcePackActivator.class);

    static BundleContext bundleContext;

    // buffer for ressource files found
    private static Hashtable<String, Iterator<String>> ressourcesFiles =
        new Hashtable<String, Iterator<String>>();

    public void start(BundleContext bc) throws Exception
    {
        bundleContext = bc;

        DefaultColorPackImpl colPackImpl =
            new DefaultColorPackImpl();

        Hashtable props = new Hashtable();
        props.put(ResourcePack.RESOURCE_NAME,
                  ColorPack.RESOURCE_NAME_DEFAULT_VALUE);

        bundleContext.registerService(  ColorPack.class.getName(),
                                        colPackImpl,
                                        props);

        DefaultImagePackImpl imgPackImpl =
            new DefaultImagePackImpl();

        Hashtable imgProps = new Hashtable();
        imgProps.put(ResourcePack.RESOURCE_NAME,
                    ImagePack.RESOURCE_NAME_DEFAULT_VALUE);

        bundleContext.registerService(  ImagePack.class.getName(),
                                        imgPackImpl,
                                        imgProps);

        DefaultLanguagePackImpl langPackImpl =
            new DefaultLanguagePackImpl();

        Hashtable langProps = new Hashtable();
        langProps.put(ResourcePack.RESOURCE_NAME,
                    LanguagePack.RESOURCE_NAME_DEFAULT_VALUE);

        bundleContext.registerService(  LanguagePack.class.getName(),
                                        langPackImpl,
                                        langProps);

        DefaultSettingsPackImpl setPackImpl =
            new DefaultSettingsPackImpl();

        Hashtable setProps = new Hashtable();
        langProps.put(ResourcePack.RESOURCE_NAME,
                      SettingsPack.RESOURCE_NAME_DEFAULT_VALUE);

        bundleContext.registerService(  SettingsPack.class.getName(),
                                        setPackImpl,
                                        setProps);

        DefaultSoundPackImpl sndPackImpl =
            new DefaultSoundPackImpl();

        Hashtable sndProps = new Hashtable();
        langProps.put(ResourcePack.RESOURCE_NAME,
                      SoundPack.RESOURCE_NAME_DEFAULT_VALUE);

        bundleContext.registerService(  SoundPack.class.getName(),
                                        sndPackImpl,
                                        sndProps);

        logger.info("Default resources ... [REGISTERED]");
    }

    public void stop(BundleContext bc) throws Exception
    {

    }

    /**
     * Finds all properties files for the given path in this bundle.
     *
     * @param path the path pointing to the properties files.
     */
    protected static Iterator<String> findResourcePaths(  String path,
                                                            String pattern)
    {
        Iterator<String> bufferedResult = ressourcesFiles.get(path + pattern);
        if (bufferedResult != null) {
            return bufferedResult;
        }

        ArrayList<String> propertiesList = new ArrayList<String>();

        @SuppressWarnings ("unchecked")
        Enumeration<URL> propertiesUrls = bundleContext.getBundle()
            .findEntries(path,
                        pattern,
                        false);

        if (propertiesUrls != null)
        {
            while (propertiesUrls.hasMoreElements())
            {
                URL propertyUrl = propertiesUrls.nextElement();

                // Remove the first slash.
                String propertyFilePath
                    = propertyUrl.getPath().substring(1);

                // Replace all slashes with dots.
                propertyFilePath = propertyFilePath.replaceAll("/", ".");

                propertiesList.add(propertyFilePath);
            }
        }

        Iterator<String> result = propertiesList.iterator();
        ressourcesFiles.put(path + pattern, result);

        return result;
    }
}