Changeset 32071
- Timestamp:
- 2017-11-14T23:50:42+13:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java
r32070 r32071 158 158 // what if it is null here?? Anu to check... 159 159 160 160 161 boolean editing_document = false; 161 162 String doc_edit = (String) params.get(DOC_EDIT_ARG); … … 192 193 // convert the archive format into the internal format that the page response requires 193 194 194 Element doc_elem = doc.createElement(GSXML.DOCUMENT_ELEM); 195 // work out doctype 196 // create a basic doc list containing the current node 197 Element basic_doc_list = doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER); 198 Element current_doc = doc.createElement(GSXML.DOC_NODE_ELEM); 199 basic_doc_list.appendChild(current_doc); 200 current_doc.setAttribute(GSXML.NODE_ID_ATT, document_id); 201 basic_doc_list.appendChild(current_doc); 202 if (document_type == null) { 203 document_type = getDocumentType(basic_doc_list, collection, userContext, page_response); 204 } 205 if (document_type == null) { 206 logger.debug("@@@ doctype is null, setting to simple"); 207 document_type = GSXML.DOC_TYPE_SIMPLE; 208 } 209 210 Element doc_elem = doc.createElement(GSXML.DOCUMENT_ELEM); 195 211 doc_elem.setAttribute(GSXML.DOC_TYPE_ATT, document_type); 196 212 page_response.appendChild(doc_elem); 197 213 section.setAttribute(GSXML.NODE_ID_ATT, document_id); 198 214 215 199 216 Element transformed_section = transformArchiveToDocument(section); 217 // In docEdit mode, we obtain the text from archives, from doc.xml 218 // Now the transformation has replaced <Section> with <documentNode> 219 // Need to add nodeID, nodeType and docType attributes to each docNode 220 // as doc.xml doesn't store that. 221 insertDocNodeAttributes(transformed_section, document_type, null); 200 222 doc_elem.appendChild(doc.importNode(transformed_section, true)); 201 logger.error("dx result = "+XMLConverter.getPrettyString(result)); 223 logger.debug("dx result = "+XMLConverter.getPrettyString(result)); 224 202 225 return result; 203 226 } 204 227 205 228 //whether to retrieve siblings or not 206 229 boolean get_siblings = false; … … 246 269 247 270 if (!expand_document && nt_arg!=null && nt_arg.equals("1")) { 248 logger. error("SETTING GET TEXT TO FALSE");271 logger.debug("SETTING GET TEXT TO FALSE"); 249 272 get_text = false; 250 273 } else { 251 logger. error("GET TEXT REMAINS TRUE");274 logger.debug("GET TEXT REMAINS TRUE"); 252 275 } 253 276 … … 271 294 current_doc.setAttribute(GSXML.ID_MOD_ATT, doc_id_modifier); 272 295 } 273 296 274 297 if (document_type == null) 275 298 { … … 278 301 if (document_type == null) 279 302 { 280 logger.debug(" doctype is null, setting to simple");303 logger.debug("##### doctype is null, setting to simple"); 281 304 document_type = GSXML.DOC_TYPE_SIMPLE; 282 305 } … … 284 307 the_document.setAttribute(GSXML.DOC_TYPE_ATT, document_type); 285 308 286 287 309 // Create a parameter list to specify the required structure information 288 310 Element ds_param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); … … 890 912 } 891 913 914 // Recursive method to set the docType, nodeType and nodeID attributes of each docNode 915 // The docType remains constant as in parameter document_type 916 // The nodeID for the first (root) docNode is already set. For all children, the rootNode id 917 // is updated to be <parent-id>.<num-child>, where the first parent-id is rootNode id. 918 // The nodeType is root if rootNode, internal if there are children and leaf if no children 919 protected void insertDocNodeAttributes(Element docNode, String document_type, String id) { 920 921 boolean isRoot = false; 922 if(id == null) { // rootNode, get the root nodeID to work with recursively 923 id = docNode.getAttribute(GSXML.NODE_ID_ATT); 924 isRoot = true; 925 } else { // for all but the root node, need to still set the nodeID 926 docNode.setAttribute(GSXML.NODE_ID_ATT, id); 927 } 928 929 docNode.setAttribute(GSXML.DOC_TYPE_ATT, document_type); 930 931 NodeList docNodes = GSXML.getChildrenByTagName(docNode, GSXML.DOC_NODE_ELEM); 932 if(docNodes.getLength() > 0) { 933 docNode.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERNAL); 934 for(int i = 0; i < docNodes.getLength(); i++) { 935 Element childDocNode = (Element)docNodes.item(i); 936 937 // work out the child docNode's nodeID based on current id 938 String nodeID = id + "." + (i+1); 939 insertDocNodeAttributes(childDocNode, document_type, nodeID); //recursion step 940 } 941 } else { 942 docNode.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF); 943 } 944 945 // rootNode's nodeType is a special case: it's "root", not "leaf" or "internal" 946 if(isRoot) docNode.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_ROOT); 947 948 } 949 892 950 /** run the XSLT transform which converts from doc.xml format to our internal document format */ 893 951 protected Element transformArchiveToDocument(Element section) { … … 903 961 section_doc.appendChild(section_doc.importNode(section, true)); 904 962 Node result = this.transformer.transform(stylesheet_doc, section_doc); 905 logger. error("transform result = "+XMLConverter.getPrettyString(result));963 logger.debug("transform result = "+XMLConverter.getPrettyString(result)); 906 964 907 965 Element new_element; 908 if (result.getNodeType() == Node.DOCUMENT_NODE) 909 { 966 if (result.getNodeType() == Node.DOCUMENT_NODE) { 910 967 new_element = ((Document) result).getDocumentElement(); 911 } 912 else 913 { 968 } else { 914 969 new_element = (Element) result; 915 970 } 916 971 917 972
Note:
See TracChangeset
for help on using the changeset viewer.