Changeset 14532


Ignore:
Timestamp:
2007-09-17T15:43:24+12:00 (14 years ago)
Author:
qq6
Message:

updated replacing macros

File:
1 edited

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/util/GS2MacroResolver.java

    r11264 r14532  
    2020
    2121import java.util.ArrayList;
     22import java.util.regex.Matcher;
     23import java.util.regex.Pattern;
     24import java.net.URLDecoder;
    2225
    2326public class GS2MacroResolver
    24     extends MacroResolver 
     27    extends MacroResolver
    2528{
    2629
     
    7174        // the (?s) treats the string as a single line, cos .
    7275        // doesn't necessarily match line breaks
    73         if (text.matches("(?s).*"+m.macro+".*")) {
     76        //if (text.matches("(?s).*"+m.macro+".*")) {
     77        Pattern p_text = Pattern.compile(".*" + m.macro + ".*",Pattern.DOTALL);
     78        Matcher match_text = p_text.matcher(text);
     79        if (match_text.matches()) {
    7480            if (m.resolve) {
    7581            new_text = this.resolve(m.text, lang, scope, doc_oid);
     
    7884            }
    7985            text = text.replaceAll(m.macro, new_text);
     86            if (m.macro.endsWith("\\\\")){ // to get rid of "\" from the string likes: "src="http://www.greenstone.org:80/.../mw.gif\">"
     87            Pattern p_back_slash = Pattern.compile("\\\"");// create a pattern "\\\"", but it matches both " and \"
     88            Matcher m_slash = p_back_slash.matcher(text);
     89            String clean_str = "";
     90            int s=0;
     91            while (m_slash.find()){
     92                if (!text.substring(m_slash.end()-2,m_slash.end()-1).equals("\\")){
     93                clean_str = clean_str + text.substring(s,m_slash.end()-1); // it matches ", so get a substring before "
     94                }else{
     95                clean_str = clean_str + text.substring(s,m_slash.end()-2);// it matches \", so get a substring before \
     96                }
     97                s = m_slash.end();// get the index of the last match
     98                clean_str = clean_str + "\"";
     99            }
     100            text = clean_str + text.substring(s,text.length());
     101            }
    80102        }
    81103        break;
    82104        case TYPE_META:
    83         if (text.matches(".*"+m.macro+".*")) {
     105        Pattern p = Pattern.compile(".*" + m.macro + ".*",Pattern.DOTALL);
     106        Matcher match = p.matcher(text);
     107        if (match.matches()) {
    84108            if (node_info == null) {
    85109            node_info = gdbm_src.getInfo(doc_oid);
Note: See TracChangeset for help on using the changeset viewer.