Ignore:
Timestamp:
2014-04-10T14:39:33+12:00 (10 years ago)
Author:
kjdon
Message:

Lots of changes. Mainly to do with removing this.doc from everywhere. Document is not thread safe. Now we tend to create a new Document everytime we are starting a new page/message etc. in service this.desc_doc is available as teh document to create service info stuff. But it should only be used for this and not for other messages. newDOM is now static for XMLConverter. method param changes for some GSXML methods.

File:
1 edited

Legend:

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

    r25727 r28966  
    8888   
    8989    // set up short_service_info_ - for now just has name and type
    90     Element e = this.doc.createElement(GSXML.SERVICE_ELEM);
     90    Element e = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
    9191    e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_APPLET);
    9292    e.setAttribute(GSXML.NAME_ATT, PHIND_SERVICE);
     
    9595    // set up the static applet description
    9696   
    97     applet_description = this.doc.createElement(GSXML.SERVICE_ELEM);
     97    applet_description = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
    9898    applet_description.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_APPLET);
    9999    applet_description.setAttribute(GSXML.NAME_ATT, PHIND_SERVICE);
     
    116116    }
    117117    Element app_elem = dom.getDocumentElement();
    118     applet_description.appendChild(this.doc.importNode(app_elem, true));
     118    applet_description.appendChild(this.desc_doc.importNode(app_elem, true));
    119119   
    120120    return true;
    121121  }
    122122 
    123   protected Element getServiceDescription(String service, String lang, String subset) {
     123  protected Element getServiceDescription(Document doc, String service, String lang, String subset) {
    124124    if (!service.equals(PHIND_SERVICE)) {
    125125      return null;
    126126    }
    127127    Element describe = (Element) applet_description.cloneNode(true);
    128     describe.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME,  getTextString(PHIND_SERVICE+".name", lang)));
    129     describe.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_DESCRIPTION,  getTextString(PHIND_SERVICE+".description", lang)));
     128    describe.appendChild(GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_NAME,  getTextString(PHIND_SERVICE+".name", lang)));
     129    describe.appendChild(GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_DESCRIPTION,  getTextString(PHIND_SERVICE+".description", lang)));
    130130    return describe;
    131131  }
    132132 
    133133  protected Element processPhindApplet(Element request) {
    134    
     134    Document result_doc = XMLConverter.newDOM();
    135135    Element param_elem = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    136136    HashMap<String, Serializable> params = GSXML.extractParams(param_elem, false);
     
    156156   
    157157    // the result element
    158     Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
     158    Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
    159159    result.setAttribute(GSXML.FROM_ATT, PHIND_SERVICE);
    160160    result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
    161161   
    162162    // applet result info must be in appletInfo element
    163     Element applet_data = this.doc.createElement(GSXML.APPLET_DATA_ELEM);
     163    Element applet_data = result_doc.createElement(GSXML.APPLET_DATA_ELEM);
    164164    result.appendChild(applet_data);
    165     Element phind_data = this.doc.createElement("phindData");
     165    Element phind_data = result_doc.createElement("phindData");
    166166    applet_data.appendChild(phind_data);
    167167   
     
    170170    if (phrase == 0) {
    171171      if (word==null || word.equals("")) {
    172         Element error = phindError("no word or phrase");
     172        Element error = phindError(result_doc, "no word or phrase");
    173173        phind_data.appendChild(error);
    174174        return result;
     
    179179      // the word is not in the collection
    180180      // return a phind error string
    181       Element error = phindError("the term "+word+" is not in the collection");
     181      Element error = phindError(result_doc, "the term "+word+" is not in the collection");
    182182      phind_data.appendChild(error);
    183183      return result;
     
    215215    long last_d) {
    216216   
    217       synchronized (mgpp_retrieve_src) {
     217    synchronized (mgpp_retrieve_src) {
    218218    String record = this.mgpp_retrieve_src.getDocument(this.basepath+File.separatorChar+"pdata", "Document",
    219219      phrase);
    220220    if (record.equals("")) {
    221       Element error = phindError("somethings gone wrong - we haven't got a record for phrase number "+phrase);
     221      Element error = phindError(phind_data.getOwnerDocument(), "somethings gone wrong - we haven't got a record for phrase number "+phrase);
    222222      phind_data.appendChild(error);
    223223      return false;
     
    258258    phind_data.setAttribute("lf", lf);
    259259    phind_data.setAttribute("tf", tf);
    260     GSXML.createTextElement(this.doc, "phrase", word);
     260    // GSXML.createTextElement(result_doc, "phrase", word); ??? - this needs to be appended somewhere????
    261261   
    262262    addExpansionList(phind_data, expansions, word, ef, first_e, last_e);
     
    266266    }
    267267    return true;
    268       }
     268    } // end of synchronized (mgpp_retrieve_src)
    269269  }
    270270 
     
    273273    String freq,
    274274    long first, long last) {
    275    
    276     Element expansion_list = this.doc.createElement("expansionList");
     275    Document phind_doc = phind_data.getOwnerDocument();
     276    Element expansion_list = phind_doc.createElement("expansionList");
    277277    phind_data.appendChild(expansion_list);
    278278    expansion_list.setAttribute("length", freq);
     
    286286    for (long i = first; i < last; i++) {
    287287      long num  = Long.parseLong(expansions[(int)i]);
    288       Element expansion = getExpansion( num, word);
     288      Element expansion = getExpansion(phind_doc, num, word);
    289289      expansion.setAttribute("num", Long.toString(i));
    290290      expansion_list.appendChild(expansion);
     
    293293  }
    294294 
    295   protected Element getExpansion(long phrase_num,
     295  protected Element getExpansion(Document phind_doc, long phrase_num,
    296296    String orig_phrase) {
    297297   
     
    311311    String df = fields[3];
    312312   
    313     Element expansion = this.doc.createElement("expansion");
     313    Element expansion = phind_doc.createElement("expansion");
    314314    expansion.setAttribute("tf", tf);
    315315    expansion.setAttribute("df", df);
     
    319319    String [] ends = splitPhraseOnWord(phrase, orig_phrase);
    320320    if (!ends[0].equals("")) {
    321       expansion.appendChild(GSXML.createTextElement(this.doc, "prefix", ends[0]));
     321      expansion.appendChild(GSXML.createTextElement(phind_doc, "prefix", ends[0]));
    322322    }
    323323    if (!ends[1].equals("")) {
    324       expansion.appendChild(GSXML.createTextElement(this.doc, "suffix", ends[1]));
     324      expansion.appendChild(GSXML.createTextElement(phind_doc, "suffix", ends[1]));
    325325    }
    326326   
     
    333333    String freq,
    334334    long first, long last) {
    335    
    336     Element document_list = this.doc.createElement("documentList");
     335    Document phind_doc = phind_data.getOwnerDocument();
     336    Element document_list = phind_doc.createElement("documentList");
    337337    phind_data.appendChild(document_list);
    338338    document_list.setAttribute("length", freq);
     
    357357        doc_freq = doc_elem.substring(p+1);
    358358      }
    359       Element document = getDocument( doc_num);
     359      Element document = getDocument(phind_doc, doc_num);
    360360      document.setAttribute("freq", doc_freq);
    361361      document.setAttribute("num", Long.toString(i));
     
    368368 
    369369 
    370   protected Element getDocument(long doc_num) {
     370  protected Element getDocument(Document phind_doc, long doc_num) {
    371371   
    372372    // look up the phrase in the docs thingy
     
    383383    String title = fields[1];
    384384   
    385     Element d = this.doc.createElement("document");
     385    Element d = phind_doc.createElement("document");
    386386    d.setAttribute("hash", hash);
    387     d.appendChild(GSXML.createTextElement(this.doc, "title", title));
     387    d.appendChild(GSXML.createTextElement(phind_doc, "title", title));
    388388   
    389389    return d;
     
    395395    long first, long last) {
    396396   
    397    
    398     Element thesaurus_list = this.doc.createElement("thesaurusList");
     397    Document phind_doc = phind_data.getOwnerDocument();
     398    Element thesaurus_list = phind_doc.createElement("thesaurusList");
    399399    phind_data.appendChild(thesaurus_list);
    400400    thesaurus_list.setAttribute("length", freq);
     
    414414        if (index >= first && index < last) { // only output the ones we want
    415415          long phrase = Long.parseLong(items[j]);
    416           Element t = getThesaurus(phrase);
     416          Element t = getThesaurus(phind_doc, phrase);
    417417          t.setAttribute("type", type);
    418418          thesaurus_list.appendChild(t);
     
    424424  }
    425425 
    426   protected Element getThesaurus(long phrase_num) {
     426  protected Element getThesaurus(Document phind_doc, long phrase_num) {
    427427   
    428428    // look up the phrase in the pdata thingy
     
    441441    String df = fields[3];
    442442   
    443     Element thesaurus = this.doc.createElement("thesaurus");
     443    Element thesaurus = phind_doc.createElement("thesaurus");
    444444    thesaurus.setAttribute("tf", tf);
    445445    thesaurus.setAttribute("df", df);
    446446    thesaurus.setAttribute("id", Long.toString(phrase_num));
    447     thesaurus.appendChild(GSXML.createTextElement(this.doc, "phrase", phrase));
     447    thesaurus.appendChild(GSXML.createTextElement(phind_doc, "phrase", phrase));
    448448    return thesaurus;
    449449   
     
    464464  }
    465465 
    466   protected Element phindError(String message) {
    467     Element e = this.doc.createElement("phindError");
    468     Text t = this.doc.createTextNode(message);
     466  protected Element phindError(Document phind_doc, String message) {
     467    Element e = phind_doc.createElement("phindError");
     468    Text t = phind_doc.createTextNode(message);
    469469    e.appendChild(t);
    470470    return e;
Note: See TracChangeset for help on using the changeset viewer.