/* * MacroResolver.java * Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.greenstone.gsdl3.util; import java.util.ArrayList; import org.w3c.dom.Element; import org.w3c.dom.NodeList; abstract public class MacroResolver { public static final String SCOPE_TEXT = "text"; public static final String SCOPE_META = "metadata"; public static final String SCOPE_ALL = "all"; public static final int TYPE_TEXT = 0; public static final int TYPE_META = 1; public static final int TYPE_DICT = 2; protected ArrayList text_macros = null; protected ArrayList metadata_macros = null; String lang = null; public MacroResolver() { this.text_macros = new ArrayList(); this.metadata_macros = new ArrayList(); } public void setSiteDetails(String site_address, String cluster_name, String library_name) { if (site_address != null) { addMacro(TYPE_TEXT, "_httpsite_", site_address, SCOPE_ALL, false); } if (cluster_name != null) { addMacro(TYPE_TEXT, "_clustername_", cluster_name, SCOPE_ALL, false); } if (library_name!=null){ addMacro(TYPE_TEXT, "_libraryname_", library_name, SCOPE_ALL, false); } } public void addMacro(int type, String macro, String text_or_metadata, String scope, boolean resolve) { Macro m = new Macro(); m.type = type; m.macro = macro; m.text = text_or_metadata; m.resolve = resolve; addMacro(m, scope); } public void addMacro(int type, String macro, String bundle, String key, String scope, boolean resolve) { Macro m = new Macro(); m.type = type; m.macro = macro; m.bundle = bundle; m.key = key; m.resolve = resolve; addMacro(m, scope); } public void addMacros(Element replace_list_elem) { NodeList replaces = replace_list_elem.getElementsByTagName(GSXML.REPLACE_ELEM); for (int i=0; i