Changeset 34241 for main/trunk
- Timestamp:
- 2020-07-03T12:18:35+12:00 (4 years ago)
- Location:
- main/trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java
r34185 r34241 94 94 { 95 95 Element item = (Element) item_list.get(i); 96 String text = XMLTools.getNodeText(item); 97 96 boolean isCollDescr = name_value.equals(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR); 97 98 // Sadly, XMLTools.getNodeText(item) returns empty for any HTML in displayItem 99 // so we have to do it the hard way 100 String text = isCollDescr ? preserveHTMLInDescriptionDisplayItem(item) 101 : XMLTools.getNodeText(item); // else as before for all other displayItems 102 103 98 104 //If there is nothing to display, don't bother creating the element 99 105 // Either lang or key should be set. If key set, no textnode. … … 2800 2806 } 2801 2807 2808 /** 2809 * For now it only makes sends to allow a collection's about page description to contain HTML. 2810 * Collection titles may go into a pre tag or text only context or into HTML headings, 2811 * where preserving any HTML int coll title would become meaningless or even a hindrance. 2812 * TODO: if users used HTML pre tags, they'll have wanted whitespace preserved. 2813 * TODO There's probably a better way to do this, but I'm unable to think of it. Messy but works. 2814 */ 2815 static private String preserveHTMLInDescriptionDisplayItem(Element collDescription) { 2816 // First get the <displayItem> as text 2817 String text = XMLTools.elementToString(collDescription, true); 2818 2819 // We only want the contents, not the xml processing instruction or the 2820 // <displayItem></displayItem> or self-closing(!) <displayItem/> when no text for colldescr 2821 // Remove xml processing instr too by removing <displayItem until first > after that 2822 // this will also handle self-closing tag case 2823 String lookFor = "<displayItem"; 2824 int start = text.indexOf(lookFor); 2825 if(start != -1) { 2826 start += lookFor.length(); 2827 start = text.indexOf(">", start); 2828 text = text.substring(start+1).trim(); // trim to ensure no empty lines to deceive us 2829 // especially after a self-closing tag 2830 } 2831 2832 // If we have a positive number of lines remaining, it means it wasn't a self-closing 2833 // tag. Remove the closing tag 2834 String[] lines = text.split("\\r?\\n"); 2835 text = ""; 2836 if(lines.length > 1) { 2837 for (int j = 0; j < lines.length-1; j++) { // skip last line: closing tag 2838 text += lines[j].trim() + "\n"; // Easiest solution: 2839 // trim white space introduced by the one extra level of 2840 // indentation intoduced when enclosing <dispItem> tags removed 2841 } 2842 } 2843 2844 text = text.replaceAll("&", "&");// feels stupid, when we're going to change it back again soon 2845 // but it's the last bit needed to get GLI to preserve html coll descriptions 2846 // while displaying the html as html (without char entities) in the config file editor 2847 2848 return text;//.trim(); // don't want trailing whitespace within displayItem 2849 } 2850 2802 2851 static public String generateStringVersion(Document doc) 2803 2852 { -
main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionMeta.java
r20448 r34241 162 162 */ 163 163 public void setValue(String raw_value) { 164 setValue(raw_value, false); 165 } 166 167 public void setValue(String raw_value, boolean preserveTags) { 164 168 // we need to check if the value has changed 165 169 String current_value = XMLTools.getValue(element); 166 String new_value = Codec.transform(raw_value, Codec.TEXT_TO_DOM); 170 171 String new_value = preserveTags ? 172 Codec.transform(raw_value, Codec.TEXT_TO_DOM_PRESERVE_TAGS) 173 : Codec.transform(raw_value, Codec.TEXT_TO_DOM); 167 174 if (!current_value.equals(new_value)) { 168 // Only raw html text can be given to setValue so we need to encode it175 // Only raw html text can be given to setValue so we need to encode it 169 176 XMLTools.setValue(element, new_value); 170 177 text = null; // Reset text -
main/trunk/gli/src/org/greenstone/gatherer/cdm/GeneralManager.java
r22410 r34241 320 320 if (!ready) return; 321 321 322 boolean preserveTags = true; // for coll description, allow HTML tags to be saved as HTML tags 322 323 public_collectionmeta.setValue((public_checkbox.isSelected() ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR)); 323 324 String creator_email_str = creator_emailfield.getText(); 324 325 creator_collectionmeta.setValue(creator_email_str); 325 collection_extra_collectionmeta.setValue(description_textarea.getText() );326 collection_extra_collectionmeta.setValue(description_textarea.getText(), preserveTags); 326 327 icon_collection_collectionmeta.setValue(icon_textfield.getText()); 327 328 maintainer_collectionmeta.setValue(maintainer_emailfield.getText()); 328 329 icon_collection_small_collectionmeta.setValue(small_icon_textfield.getText()); 329 330 collection_name_collectionmeta.setValue(name_textfield.getText()); 330 331 331 332 332 } 333 333 -
main/trunk/gli/src/org/greenstone/gatherer/util/Codec.java
r28995 r34241 45 45 static final public String GREENSTONE_TO_TEXT = "GREENSTONE_TO_TEXT"; 46 46 static final public String TEXT_TO_DOM = "TEXT_TO_DOM"; 47 static final public String TEXT_TO_DOM_PRESERVE_TAGS = "TEXT_TO_DOM_PRESERVE_TAGS"; 47 48 static final public String TEXT_TO_GREENSTONE = "TEXT_TO_GREENSTONE"; 48 49 static final public String TEXT_TO_REGEXP = "TEXT_TO_REGEXP"; … … 169 170 TRANSFORMS.put(TEXT_TO_DOM, text_to_dom); 170 171 text_to_dom = null; 172 173 // Same as above, but preserve html element tags 174 String[] text_to_dom_preserve_tags = { 175 "&", "&", 176 "\"", """, 177 "\'", "'" 178 }; 179 TRANSFORMS.put(TEXT_TO_DOM_PRESERVE_TAGS, text_to_dom_preserve_tags); 180 text_to_dom_preserve_tags = null; 171 181 172 182 // Unescape html (or xml) text -
main/trunk/gli/src/org/greenstone/gatherer/util/XMLTools.java
r31776 r34241 957 957 // And close. 958 958 os.close(); 959 960 // Useful for debugging unescaped chars that may otherwise break stuff 961 // w = new StringWriter(); 962 // // Generate a new serializer from the above. 963 // s = new XMLSerializer(w, f); 964 // s.asDOMSerializer(); 965 // // Finally serialize the document to file. 966 // s.serialize(document); 967 968 // System.err.println("@@@@ XMLTools: wrote out to doc:\n" + w.toString()); 969 959 970 } 960 971 catch (Exception exception)
Note:
See TracChangeset
for help on using the changeset viewer.