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.tools.seleniumbuilder;
016    
017    import com.liferay.portal.kernel.util.StringUtil_IW;
018    
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    /**
023     * @author Michael Hashimoto
024     */
025    public class BaseConverter {
026    
027            public BaseConverter(
028                    SeleniumBuilderContext seleniumBuilderContext,
029                    SeleniumBuilderFileUtil seleniumBuilderFileUtil) {
030    
031                    this.seleniumBuilderContext = seleniumBuilderContext;
032                    this.seleniumBuilderFileUtil = seleniumBuilderFileUtil;
033            }
034    
035            protected Map<String, Object> getContext() {
036                    Map<String, Object> context = new HashMap<>();
037    
038                    context.put("seleniumBuilderContext", seleniumBuilderContext);
039                    context.put("seleniumBuilderFileUtil", seleniumBuilderFileUtil);
040                    context.put("stringUtil", StringUtil_IW.getInstance());
041    
042                    return context;
043            }
044    
045            protected String processTemplate(String name) throws Exception {
046                    return processTemplate(name, getContext());
047            }
048    
049            protected String processTemplate(String name, Map<String, Object> context)
050                    throws Exception {
051    
052                    return seleniumBuilderFileUtil.processTemplate(name, context);
053            }
054    
055            protected SeleniumBuilderContext seleniumBuilderContext;
056            protected SeleniumBuilderFileUtil seleniumBuilderFileUtil;
057    
058    }