001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.parsers.bbcode;
016    
017    import com.liferay.registry.Registry;
018    import com.liferay.registry.RegistryUtil;
019    import com.liferay.registry.ServiceTracker;
020    
021    /**
022     * @author Iliyan Peychev
023     * @author Miguel Pastor
024     */
025    public class BBCodeTranslatorUtil {
026    
027            public static BBCodeTranslator getBBCodeTranslator() {
028                    return _instance._getBBCodeTranslator();
029            }
030    
031            public static String[] getEmoticonDescriptions() {
032                    return getBBCodeTranslator().getEmoticonDescriptions();
033            }
034    
035            public static String[] getEmoticonFiles() {
036                    return getBBCodeTranslator().getEmoticonFiles();
037            }
038    
039            public static String[][] getEmoticons() {
040                    return getBBCodeTranslator().getEmoticons();
041            }
042    
043            public static String[] getEmoticonSymbols() {
044                    return getBBCodeTranslator().getEmoticonSymbols();
045            }
046    
047            public static String getHTML(String bbcode) {
048                    return getBBCodeTranslator().getHTML(bbcode);
049            }
050    
051            public static String parse(String message) {
052                    return getBBCodeTranslator().parse(message);
053            }
054    
055            private BBCodeTranslatorUtil() {
056                    Registry registry = RegistryUtil.getRegistry();
057    
058                    _serviceTracker = registry.trackServices(BBCodeTranslator.class);
059    
060                    _serviceTracker.open();
061            }
062    
063            private BBCodeTranslator _getBBCodeTranslator() {
064                    return _serviceTracker.getService();
065            }
066    
067            private static final BBCodeTranslatorUtil _instance =
068                    new BBCodeTranslatorUtil();
069    
070            private final ServiceTracker<BBCodeTranslator, BBCodeTranslator>
071                    _serviceTracker;
072    
073    }