Changeset 8959
- Timestamp:
- 2005-02-04T11:48:14+13:00 (19 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3/service
- Files:
-
- 7 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java
r8955 r8959 1 1 /* 2 2 * GS2MGPPRetrieve.java 3 * Copyright (C) 200 2New Zealand Digital Library, http://www.nzdl.org3 * Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 19 19 package org.greenstone.gsdl3.service; 20 20 21 22 21 // Greenstone classes 23 22 import org.greenstone.mgpp.*; 24 import org.greenstone.gsdl3.util.*; 23 import org.greenstone.gsdl3.util.GSFile; 24 import org.greenstone.gsdl3.util.GSXML; 25 25 26 26 // XML classes 27 import org.w3c.dom.Element; 27 import org.w3c.dom.Element; 28 import org.w3c.dom.Text; 28 29 29 30 // General Java classes 30 31 import java.io.File; 31 32 32 33 /** 34 * A ServiceRack class for retrieval in greenstone 2 MGPP collections 35 * 36 * @author <a href="mailto:[email protected]">Katherine Don</a> 37 * @version $Revision$ 38 * @see ServiceRack 39 */ 40 public class GS2MGPPRetrieve 41 extends GS2Retrieve { 42 43 // Parameters used 33 public class GS2MGPPRetrieve 34 extends AbstractGS2DocumentRetrieve 35 { 36 // Parameters used 44 37 private static final String LEVEL_PARAM = "level"; 45 38 … … 50 43 51 44 private String default_level = null; 52 53 54 /** constructor */ 55 public GS2MGPPRetrieve() 56 { 45 private String mgpp_textdir = null; 46 47 public GS2MGPPRetrieve() { 57 48 this.mgpp_src = new MGPPWrapper(); 58 // only the classifier service has strings at present59 this.dictionary_name = "ClassifierBrowse";60 61 49 } 62 63 50 64 51 /** configure this service */ … … 78 65 } 79 66 // System.out.println("Default level: " + default_level_); 67 68 // The location of the MGPP text files 69 mgpp_textdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + 70 File.separatorChar + GSFile.collectionTextPath(this.cluster_name); 80 71 81 72 // Do generic configuration 82 73 return super.configure(info, extra_info); 74 75 } 76 77 /** returns the content of a node 78 * should return a nodeContent element: 79 * <nodeContent>text content or other elements</nodeContent> 80 */ 81 protected Element getNodeContent(String doc_id) { 82 String lang = "en"; // ********** 83 long doc_num = this.gdbm_src.OID2Docnum(doc_id); 84 if (doc_num == -1) { 85 System.err.println("OID "+doc_id +" couldn't be converted to mgpp num"); 86 return null; 87 } 88 Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM); 89 90 String doc_content = ""; 91 try { 92 doc_content = this.mgpp_src.getDocument(this.mgpp_textdir, 93 this.default_level, 94 doc_num); 95 if (doc_content != null) { 96 doc_content = resolveTextMacros(doc_content, doc_id, lang); 97 } 98 } catch (Exception e) { 99 System.out.println("exception happended with mgpp_src.getDocument()" + e); 100 doc_content = "this is the content for section hash id "+ doc_id+", mgpp doc num "+doc_num+"\n"; 101 102 } 103 Text t = this.doc.createTextNode(doc_content); 104 content_node.appendChild(t); 105 return content_node; 106 83 107 } 84 108 85 86 /** Retrieve the content of a document */87 protected Element processDocumentContentRetrieve(Element request)88 {89 // Create a new (empty) result message90 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);91 result.setAttribute(GSXML.FROM_ATT,DOCUMENT_CONTENT_RETRIEVE_SERVICE );92 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);93 109 94 // Get the parameters of the request95 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);96 Element extlink_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, EXTLINK_PARAM);97 boolean extlink = false;98 if (extlink_param != null && GSXML.getValue(extlink_param).equals("1")) {99 extlink = true;100 }101 102 // Get the request doc_list103 Element query_doc_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);104 if (query_doc_list == null) {105 System.err.println("Error: DocumentContentRetrieve request specified no doc nodes.\n");106 return result;107 }108 String lang = request.getAttribute(GSXML.LANG_ATT);109 Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);110 result.appendChild(doc_list);111 112 // The location of the MGPP text files113 String textdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) +114 File.separatorChar + GSFile.collectionTextPath(this.cluster_name);115 116 // Get the documents117 String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list,118 GSXML.NODE_ID_ATT);119 for (int i = 0; i < doc_ids.length; i++) {120 String doc_id = doc_ids[i];121 Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);122 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);123 doc_list.appendChild(doc);124 125 if (extlink) {126 doc_id = this.gdbm_src.extlink2OID(doc_id);127 if (doc_id==null) {128 continue;129 }130 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);131 }132 else if (OID.needsTranslating(doc_id)) {133 doc_id = this.gdbm_src.translateOID(doc_id);134 if (doc_id==null) {135 continue;136 }137 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);138 }139 140 long doc_num = this.gdbm_src.OID2Docnum(doc_id);141 if (doc_num == -1) {142 continue;143 }144 String doc_content = this.mgpp_src.getDocument(textdir, this.default_level, doc_num);145 doc_content = resolveTextMacros(doc_content, doc_id, lang);146 147 // For now, stick it in a text node - eventually should be parsed as xml??148 GSXML.addDocText(this.doc, doc, doc_content);149 150 151 }152 153 return result;154 }155 110 } 156 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java
r8955 r8959 1 1 /* 2 2 * GS2MGRetrieve.java 3 * Copyright (C) 200 2New Zealand Digital Library, http://www.nzdl.org3 * Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 19 19 package org.greenstone.gsdl3.service; 20 20 21 22 21 // Greenstone classes 23 22 import org.greenstone.mg.*; 24 import org.greenstone.gsdl3.util.*; 23 import org.greenstone.gsdl3.util.GSFile; 24 import org.greenstone.gsdl3.util.GSXML; 25 25 26 26 // XML classes 27 27 import org.w3c.dom.Element; 28 import org.w3c.dom.Text; 28 29 29 30 // General Java classes 30 31 import java.io.File; 31 32 32 33 /**34 *35 * @author <a href="mailto:[email protected]">Katherine Don</a>36 *37 */38 39 33 public class GS2MGRetrieve 40 extends GS2Retrieve { 41 42 // Parameters used 43 private static final String INDEX_PARAM = "index"; 44 34 extends AbstractGS2DocumentRetrieve 35 { 45 36 // Elements used in the config file that are specific to this class 46 37 private static final String DEFAULT_INDEX_ELEM = "defaultIndex"; 47 38 48 39 private MGWrapper mg_src = null; 49 40 private String mg_basedir = null; 41 private String mg_textdir = null; 50 42 private String default_index = null; 51 52 53 /** constructor */ 54 public GS2MGRetrieve() 55 { 43 44 public GS2MGRetrieve() { 56 45 this.mg_src = new MGWrapper(); 57 // only the classifier service has strings at present58 this.dictionary_name = "ClassifierBrowse";59 46 } 60 61 47 62 48 /** configure this service */ … … 79 65 // System.out.println("Default index: " + this.default_index); 80 66 67 // The location of the MG index and text files 68 mg_basedir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar; // Needed by MG 69 mg_textdir = GSFile.collectionTextPath(this.cluster_name); 70 // index is only needed to start up MG, not used so just use the default index 71 String indexpath = GSFile.collectionIndexPath(this.cluster_name, this.default_index); 72 this.mg_src.setIndex(indexpath); 73 81 74 // Do generic configuration 82 75 return super.configure(info, extra_info); 83 76 } 77 78 /** returns the content of a node 79 * should return a nodeContent element: 80 * <nodeContent>text content or other elements</nodeContent> 81 */ 82 protected Element getNodeContent(String doc_id) { 83 String lang = "en"; // ********** 84 long doc_num = this.gdbm_src.OID2Docnum(doc_id); 85 if (doc_num == -1) { 86 System.err.println("OID "+doc_id +" couldn't be converted to mg num"); 87 return null; 88 } 89 Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM); 90 91 String doc_content = this.mg_src.getDocument(this.mg_basedir, 92 this.mg_textdir, doc_num); 93 94 if (doc_content!=null) { 95 // remove any ctrl-c or ctrl-b 96 doc_content = doc_content.replaceAll("\u0002|\u0003", ""); 97 // replace _httpimg_ with the correct address 98 doc_content = resolveTextMacros(doc_content, doc_id, lang); 99 //GSXML.addDocText(this.doc, doc, doc_content); 100 } else { 101 System.err.println("the doc content was null, not getting that section\n"); 102 doc_content = "couldn't retrieve content for this section\n"; 103 } 104 Text t = this.doc.createTextNode(doc_content); 105 content_node.appendChild(t); 106 return content_node; 107 108 } 84 109 85 110 86 /** Retrieve the content of a document */87 protected Element processDocumentContentRetrieve(Element request)88 {89 // Create a new (empty) result message90 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);91 result.setAttribute(GSXML.FROM_ATT, DOCUMENT_CONTENT_RETRIEVE_SERVICE);92 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);93 94 // Get the parameters of the request - no parameters at this stage95 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);96 Element extlink_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, EXTLINK_PARAM);97 boolean extlink = false;98 if (extlink_param != null && GSXML.getValue(extlink_param).equals("1")) {99 extlink = true;100 }101 // Get the request content102 Element query_doc_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);103 if (query_doc_list == null) {104 System.err.println("Error: DocumentContentRetrieve request specified no doc nodes.\n");105 return result;106 }107 108 String lang = request.getAttribute(GSXML.LANG_ATT);109 Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);110 result.appendChild(doc_list);111 112 // The location of the MG index and text files113 String basedir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar; // Needed by MG114 String textdir = GSFile.collectionTextPath(this.cluster_name);115 // index is only needed to start up MG, not used so just use the default index116 String indexpath = GSFile.collectionIndexPath(this.cluster_name, this.default_index);117 this.mg_src.setIndex(indexpath);118 119 // Get the documents120 String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list,121 GSXML.NODE_ID_ATT);122 for (int i = 0; i < doc_ids.length; i++) {123 String doc_id = doc_ids[i];124 // Create the document node125 Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);126 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);127 doc_list.appendChild(doc);128 129 if (extlink) {130 if (OID.needsTranslating(doc_id)) {131 132 // just ignore the extension cos it has no meaning here133 // or should it be added back on for the next step???134 doc_id = this.gdbm_src.extlink2OID(doc_id.substring(0,doc_id.length()-3));135 } else {136 doc_id = this.gdbm_src.extlink2OID(doc_id);137 }138 if (doc_id == null) {139 System.err.println("extlink "+doc_id +" couldn't be converted to proper id");140 continue;141 }142 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); // reset the att cos it may have changed143 144 }145 else if (OID.needsTranslating(doc_id)) {146 doc_id = this.gdbm_src.translateOID(doc_id);147 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); // reset the att cos it may have changed148 }149 150 long doc_num = this.gdbm_src.OID2Docnum(doc_id);151 if (doc_num == -1) {152 System.err.println("OID "+doc_id +" couldn't be converted to mg num");153 continue;154 }155 String doc_content = this.mg_src.getDocument(basedir, textdir, doc_num);156 157 if (doc_content!=null) {158 // remove any ctrl-c or ctrl-b (I hope these are the right codes)159 doc_content = doc_content.replaceAll("\u0002|\u0003", "");160 // replace _httpimg_ with the correct address161 doc_content = resolveTextMacros(doc_content, doc_id, lang);162 GSXML.addDocText(this.doc, doc, doc_content);163 } else {164 System.err.println("the doc content was null, not getting that section\n");165 GSXML.addDocText(this.doc, doc, "couldn't retrieve content for this section\n");166 }167 }168 169 return result;170 }171 111 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Retrieve.java
r8955 r8959 73 73 protected static final String INFO_SIB_POS = "siblingPosition"; 74 74 75 protected static final String EXT LINK_PARAM = "ext";75 protected static final String EXTID_PARAM = "ext"; 76 76 77 77 protected static final int DOCUMENT=1; … … 462 462 node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF); 463 463 } else { 464 node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTER IOR);464 node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERNAL); 465 465 } 466 466 } … … 794 794 } 795 795 metadata_list.add(metadata); 796 } else if (param.getAttribute(GSXML.NAME_ATT).equals(EXT LINK_PARAM)&& GSXML.getValue(param).equals("1")) {796 } else if (param.getAttribute(GSXML.NAME_ATT).equals(EXTID_PARAM)&& GSXML.getValue(param).equals("1")) { 797 797 extlink = true; 798 798 } … … 824 824 // just ignore the extension cos it has no meaning here 825 825 // or should it be added back on for the next step??? 826 node_id = this.gdbm_src.ext link2OID(node_id.substring(0,node_id.length()-3));826 node_id = this.gdbm_src.externalId2OID(node_id.substring(0,node_id.length()-3)); 827 827 } else { 828 node_id = this.gdbm_src.ext link2OID(node_id);828 node_id = this.gdbm_src.externalId2OID(node_id); 829 829 } 830 830 } … … 850 850 String key = (String)it.next(); 851 851 String value = info.getInfo(key); 852 GSXML.addMetadata(this.doc, node_meta_list, key, this.macro_resolver.resolve(value, lang, GS2MacroResolver.SCOPE_META, node_id , info));852 GSXML.addMetadata(this.doc, node_meta_list, key, this.macro_resolver.resolve(value, lang, GS2MacroResolver.SCOPE_META, node_id)); 853 853 } 854 854 } else { // just get the selected ones … … 875 875 if (pos ==-1) { 876 876 // just a plain meta entry eg dc.Title 877 return macro_resolver.resolve((String)info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, node_id , info);877 return macro_resolver.resolve((String)info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, node_id); 878 878 } 879 879 … … 935 935 936 936 if (!multiple) { 937 result.append(this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, relation_id , relation_info));937 result.append(this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, relation_id)); 938 938 } else { 939 939 // we have multiple meta … … 947 947 result.append(separator); 948 948 } 949 result.append(this.macro_resolver.resolve((String)values.elementAt(i), lang, GS2MacroResolver.SCOPE_META, relation_id , relation_info));949 result.append(this.macro_resolver.resolve((String)values.elementAt(i), lang, GS2MacroResolver.SCOPE_META, relation_id)); 950 950 } 951 951 } … … 964 964 if (!multiple) { 965 965 result.insert(0, separator); 966 result.insert(0, this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, relation_id , relation_info));966 result.insert(0, this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, relation_id)); 967 967 } else { 968 968 Vector values = relation_info.getMultiInfo(metadata); … … 970 970 for (int i=values.size()-1; i>=0; i--) { 971 971 result.insert(0, separator); 972 result.insert(0, this.macro_resolver.resolve((String)values.elementAt(i), lang, GS2MacroResolver.SCOPE_META, relation_id , relation_info));972 result.insert(0, this.macro_resolver.resolve((String)values.elementAt(i), lang, GS2MacroResolver.SCOPE_META, relation_id)); 973 973 } 974 974 } … … 1005 1005 } 1006 1006 // resolve any collection specific macros 1007 doc_content = macro_resolver.resolve(doc_content, lang, GS2MacroResolver.SCOPE_TEXT, doc_id , info);1007 doc_content = macro_resolver.resolve(doc_content, lang, GS2MacroResolver.SCOPE_TEXT, doc_id); 1008 1008 return doc_content; 1009 1009 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGRetrieve.java
r8925 r8959 1 1 /* 2 2 * GS3MGRetrieve.java 3 * Copyright (C) 200 2New Zealand Digital Library, http://www.nzdl.org3 * Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 19 19 package org.greenstone.gsdl3.service; 20 20 21 22 21 // Greenstone classes 23 22 import org.greenstone.mg.*; 24 import org.greenstone.gsdl3.util.*; 23 import org.greenstone.gsdl3.util.GSFile; 24 import org.greenstone.gsdl3.util.GSXML; 25 import org.greenstone.gsdl3.util.GS3OID; 25 26 26 27 // XML classes 27 28 import org.w3c.dom.Element; 29 import org.w3c.dom.Text; 28 30 29 31 // General Java classes 30 32 import java.io.File; 31 33 32 33 /** The content retrieval class for GS3 building34 *35 * @author <a href="mailto:[email protected]">Katherine Don</a>36 * @version $Revision$37 */38 39 34 public class GS3MGRetrieve 40 extends ServiceRack { 41 // the services on offer 42 protected static final String DOCUMENT_CONTENT_RETRIEVE_SERVICE = "DocumentContentRetrieve"; 43 44 // Parameters used 45 private static final String INDEX_PARAM = "index"; 46 35 extends AbstractGS3DocumentRetrieve 36 { 47 37 // Elements used in the config file that are specific to this class 48 38 private static final String DEFAULT_INDEX_ELEM = "defaultIndex"; 49 39 50 40 private MGWrapper mg_src = null; 51 protected SQLQuery database = null; 52 53 protected Element config_info = null; // the xml from the config file 54 41 private String mg_basedir = null; 42 private String mg_textdir = null; 55 43 private String default_index = null; 56 57 /** constructor */ 58 public GS3MGRetrieve() 59 { 60 this.database = new SQLQuery(); 44 45 public GS3MGRetrieve() { 61 46 this.mg_src = new MGWrapper(); 62 47 } 63 64 48 65 49 /** configure this service */ 66 50 public boolean configure(Element info, Element extra_info) 67 51 { 68 this.config_info = info;69 52 // Do specific configuration 70 53 System.out.println("Configuring GS3MGRetrieve..."); … … 81 64 return false; 82 65 } 66 // System.out.println("Default index: " + this.default_index); 83 67 84 // System.out.println("Default index: " + this.default_index); 85 Element dcr_service = this.doc.createElement(GSXML.SERVICE_ELEM); 86 dcr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE); 87 dcr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_CONTENT_RETRIEVE_SERVICE); 88 this.short_service_info.appendChild(dcr_service); 68 // The location of the MG index and text files 69 mg_basedir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar; // Needed by MG 70 mg_textdir = GSFile.collectionTextPath("index"); 71 // index is only needed to start up MG, not used so just use the default index 72 String indexpath = GSFile.collectionIndexPath("index", this.default_index); 73 this.mg_src.setIndex(indexpath); 89 74 90 // check that site_home is set 91 if (this.site_home == null || this.site_home.equals("")) { 92 System.err.println("GS3Retrieve Error: site_home is not set, so cannot work out the site name and cannot determine the database name"); 93 return false; 94 } 95 String site_name = this.site_home.substring(this.site_home.lastIndexOf(File.separator)+1); 96 if (site_name.equals("")) { 97 System.err.println("GS3Retrieve Error: Cannot extract the site name from site home: "+this.site_home); 98 return false; 99 } 100 if (!database.setDatabase(site_name+"_"+this.cluster_name)) { 101 System.err.println("GS3Retrieve Error: Could not open SQL database!"); 102 return false; 75 // Do generic configuration 76 return super.configure(info, extra_info); 77 } 78 79 /** returns the content of a node. 80 * node_id should already have been translated if necessary 81 * should return a nodeContent element: 82 * <nodeContent>text content or other elements</nodeContent> 83 */ 84 protected Element getNodeContent(String doc_id) { 85 86 if (GS3OID.isDocTop(doc_id) && database.isHierarchicalDocument(doc_id)) { 87 // if we have a whole doc id, and the document is hierarchical, 88 // we want to change the id to be the top id of the section 89 // hierarchy 90 doc_id = GS3OID.createOID(doc_id, "1"); 103 91 } 104 92 105 // look for document display format 106 String path = GSPath.appendLink(GSXML.DISPLAY_ELEM, GSXML.FORMAT_ELEM); 107 Element display_format = (Element)GSXML.getNodeByPath(extra_info, path); 108 if (display_format != null) { 109 this.format_info_map.put(DOCUMENT_CONTENT_RETRIEVE_SERVICE, this.doc.importNode(display_format, true)); 110 // should we make a copy? 93 String doc_num = this.database.OID2MGNum(doc_id); 94 // doc nums have the index prefixed 95 doc_num = doc_num.substring(doc_num.indexOf(".")+1); 96 int doc_int = Integer.parseInt(doc_num); 97 98 String doc_content = ""; 99 try { 100 doc_content = this.mg_src.getDocument(this.mg_basedir, 101 this.mg_textdir, 102 doc_int); 103 // remove any ctrl-c or ctrl-b 104 doc_content = doc_content.replaceAll("\u0002|\u0003", ""); 105 doc_content = resolveRelativeLinks(doc_content, doc_id); 106 107 } catch (Exception e) { 108 System.out.println("exception happended with mg_src.getDocument()"); 109 doc_content = "this is the content for section hash id "+ doc_id+", mg doc num "+doc_int+"\n"; 111 110 } 111 112 Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM); 113 114 Text t = this.doc.createTextNode(doc_content); 115 content_node.appendChild(t); 116 return content_node; 112 117 113 return true;114 118 } 115 119 116 protected Element getServiceDescription(String service_id, String lang, String subset) {117 if (service_id.equals(DOCUMENT_CONTENT_RETRIEVE_SERVICE)) {118 Element dcr_service = this.doc.createElement(GSXML.SERVICE_ELEM);119 dcr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);120 dcr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_CONTENT_RETRIEVE_SERVICE);121 return dcr_service;122 }123 124 return null;125 }126 /** Retrieve the content of a document */127 protected Element processDocumentContentRetrieve(Element request)128 {129 // Create a new (empty) result message130 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);131 result.setAttribute(GSXML.FROM_ATT, DOCUMENT_CONTENT_RETRIEVE_SERVICE);132 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);133 134 // Get the parameters of the request - no parameters at this stage135 //Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);136 137 // Get the request content138 139 Element query_doc_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);140 if (query_doc_list == null) {141 System.err.println("Error: DocumentContentRetrieve request specified no doc nodes.\n");142 return result;143 }144 145 Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);146 result.appendChild(doc_list);147 148 // The location of the MG index and text files149 String basedir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar; // Needed by MG150 String textdir = GSFile.collectionTextPath("index");//this.cluster_name);151 // index is only needed to start up MG, not used so just use the default index152 String indexpath = GSFile.collectionIndexPath("index"/*this.cluster_name*/, this.default_index);153 this.mg_src.setIndex(indexpath);154 155 // Get the documents156 String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list,157 GSXML.NODE_ID_ATT);158 for (int i = 0; i < doc_ids.length; i++) {159 //ystem.out.println("getting doc id "+doc_ids[i]);160 String doc_id = doc_ids[i];161 if (GS3OID.needsTranslating(doc_id)) {162 //doc_id = this.gdbm_src.translateOID(doc_id);163 doc_id = GS3OID.translateOID(doc_id);164 //ystem.out.println("translated id = "+doc_id);165 }166 if (GS3OID.isDocTop(doc_id) && database.isHierarchicalDocument(doc_id)) {167 // if we have a whole doc id, and the document is hierarchical,168 // we want to change the id to be the top id of the section169 // hierarchy170 doc_id = GS3OID.createOID(doc_id, "1");171 }172 String doc_num = this.database.OID2MGNum(doc_id);173 // doc nums have the index prefixed174 doc_num = doc_num.substring(doc_num.indexOf(".")+1);175 int doc_int = Integer.parseInt(doc_num);176 177 String doc_content = "";178 try {179 doc_content = this.mg_src.getDocument(basedir, textdir, doc_int);180 } catch (Exception e) {181 System.out.println("exception happended with mg_src.getDocument()");182 doc_content = "this is the content for section hash id "+ doc_id+", mg doc num "+doc_int+"\n";183 }184 185 //ystem.out.println("Doc content: " + doc_content + "|");186 //ystem.out.println("Doc ID: " + doc_id);187 // remove any ctrl-c or ctrl-b (I hope these are the right codes)188 doc_content = doc_content.replaceAll("\u0002|\u0003", "");189 doc_content = resolveRelativeLinks(doc_content, doc_id);190 // replace _httpimg_ with the correct address191 //doc_content = resolveImages(doc_content, doc_id);192 // Stick it in a text node193 Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);194 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);195 GSXML.addDocText(this.doc, doc, doc_content);196 Element nodeContent = (Element)GSXML.getChildByTagName(doc, "nodeContent");197 //Element file_elem = this.doc.createElement("file");198 //file_elem.setAttribute("mimeType", "image/jpeg");199 //file_elem.setAttribute("href", "import/meinahole.jpg");200 //nodeContent.appendChild(file_elem);201 doc_list.appendChild(doc);202 }203 204 return result;205 }206 protected String resolveRelativeLinks(String doc_content, String doc_id) {207 208 String http_path = this.site_http_address + "/collect/"+this.cluster_name;209 doc_content = doc_content.replaceAll("_httpcollection_", http_path);210 return doc_content;211 212 }213 120 214 121 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3Retrieve.java
r8955 r8959 351 351 node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_ROOT); 352 352 } else if (parent || database.documentHasChildren(node_id)){ 353 node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTER IOR);353 node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERNAL); 354 354 } else { 355 355 node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF);
Note:
See TracChangeset
for help on using the changeset viewer.