Ignore:
Timestamp:
2012-09-29T18:57:32+12:00 (12 years ago)
Author:
ak19
Message:

GS2MacroResolver.resolve() code had been optimised. The code duplicated from there in FedoraServiceProxy.BasicMacroResolver.resolve() has been updated to match and now the document content retrieval is also working. Next step: to work the demo collection built with fedora.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/FedoraServiceProxy.java

    r26170 r26273  
    4545import org.xml.sax.InputSource;
    4646
     47import org.apache.commons.lang3.StringUtils;
    4748
    4849/*
     
    8788{
    8889    public static class BasicTextMacroResolver extends MacroResolver { 
     90    private static final Pattern p_back_slash = Pattern.compile("\\\"");// create a pattern "\\\"", but it matches both " and \"
     91
    8992    public String resolve(String text, String lang, String scope, String doc_oid)
    9093    {
     
    101104        String new_text = null;
    102105        Macro m = (Macro)macros.get(i);
     106       
    103107        if(m.type == TYPE_TEXT) {
    104108            // make sure we resolve any macros in the text
    105             // the (?s) treats the string as a single line, cos .
    106             // doesn't necessarily match line breaks
    107             //if (text.matches("(?s).*"+m.macro+".*")) {
    108             Pattern p_text = Pattern.compile(".*" + m.macro + ".*",Pattern.DOTALL);
    109             Matcher match_text = p_text.matcher(text);
    110             if (match_text.matches()) {
     109
     110            if(text.contains(m.macro)) {
    111111            if (m.resolve) {
    112112                new_text = this.resolve(m.text, lang, scope, doc_oid);
     
    114114                new_text = m.text;
    115115            }
    116             text = text.replaceAll(m.macro, new_text);
    117             if (m.macro.endsWith("\\\\")){ // to get rid of "\" from the string likes: "src="http://www.greenstone.org:80/.../mw.gif\">"
    118                 Pattern p_back_slash = Pattern.compile("\\\"");// create a pattern "\\\"", but it matches both " and \"
     116            text = StringUtils.replace(text, m.macro, new_text);//text = text.replaceAll(m.macro, new_text);
     117            if (m.macro.endsWith("\\\\")) { // to get rid of "\" from the string like: "src="http://www.greenstone.org:80/.../mw.gif\">"
    119118                Matcher m_slash = p_back_slash.matcher(text);
    120119                String clean_str = "";
    121120                int s=0;
    122                 while (m_slash.find()){
    123                 if (!text.substring(m_slash.end()-2,m_slash.end()-1).equals("\\")){
     121                while (m_slash.find()) {
     122                if (!text.substring(m_slash.end()-2, m_slash.end()-1).equals("\\")) {
    124123                    clean_str = clean_str + text.substring(s,m_slash.end()-1); // it matches ", so get a substring before "
    125124                }else{
    126125                    clean_str = clean_str + text.substring(s,m_slash.end()-2);// it matches \", so get a substring before \
    127                     }
     126                }
    128127                s = m_slash.end();// get the index of the last match
    129128                clean_str = clean_str + "\"";
     
    132131            }
    133132            }
    134         }       
     133        }
    135134        }
    136135        return text;
     
    348347   
    349348    //logger.error("### request:");
    350     //logger.error(GSXML.nodeToFormattedString(request));
     349    //logger.error(GSXML.elementToString(request, true));
    351350
    352351    if(docIDs == null) {
     
    516515    Element response = getResponseAsDOM(fedoraServicesAPIA.retrieveBrowseMetadata(
    517516           this.cluster_name, "ClassifierBrowseMetadataRetrieve", classIDs, metafields));
     517    //logger.error("**** Response from retrieveBrowseMeta: " + GSXML.elementToString(response, true));
    518518    return (Element)response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(0);
    519519    }
     
    555555        = getResponseAsDOM(fedoraServicesAPIA.retrieveBrowseStructure(collection, "ClassifierBrowse", classifierIDs,
    556556                                      new String[] {structure}, new String[] {info}));
    557     ///logger.error("**** FedoraServiceProxy - Response from retrieveBrowseStructure: " + GSXML.nodeToFormattedString(response));   
     557    //logger.error("**** FedoraServiceProxy - Response from retrieveBrowseStructure: " + GSXML.elementToString(response, true));   
    558558   
    559559    return (Element)response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(0);
Note: See TracChangeset for help on using the changeset viewer.