source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/SimpleMacroResolver.java@ 26447

Last change on this file since 26447 was 26447, checked in by kjdon, 11 years ago

simple text replacement only macro resolver. used by servicecluster

File size: 1.6 KB
Line 
1/*
2 * SimpleMacroResolver.java
3 * Copyright (C) 2012 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.gsdl3.util;
20
21
22import org.apache.commons.lang3.*;
23import org.greenstone.gsdl3.util.MacroResolver.Macro;
24
25public class SimpleMacroResolver extends MacroResolver
26{
27
28 public SimpleMacroResolver()
29 {
30 super();
31 }
32
33 public void addMacro(String macro, String text) {
34 Macro m = new Macro();
35 m.type = TYPE_TEXT;
36 m.macro = macro;
37 m.text = text;
38 m.resolve = false;
39 addMacro(m, SCOPE_TEXT);
40 }
41
42 // this ignores all other considerations, is a straight text swap
43 public String resolve(String text)
44 {
45 for (int i=0; i<text_macros.size(); i++) {
46 Macro m = text_macros.get(i);
47 text = StringUtils.replace(text, m.macro, m.text);
48 }
49 return text;
50 }
51 public String resolve(String text, String lang, String scope, String doc_oid)
52 {
53 return resolve(text);
54 }
55
56
57}
Note: See TracBrowser for help on using the repository browser.