Changeset 3341
- Timestamp:
- 2002-08-12T09:48:42+12:00 (22 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3/util
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSFile.java
r3284 r3341 105 105 File.separatorChar+filename; 106 106 } 107 107 108 /** returns the absolute path to a stylesheet 109 * stylesheets are looked for in the following order 110 * site-specific, ui specific, default 111 * returns null if the file cannot be found*/ 112 /* static public String stylesheetPath(String gsdl_home, String display_home, 113 String site_home, String filename) { 114 115 // try site one first 116 File stylesheet = new File(site_home+File.separatorChar+"transform"+ 117 File.separatorChar+filename); 118 if (stylesheet.exists()) { 119 return stylesheet.getPath(); 120 } 121 // try custom display 122 stylesheet = new File(display_home+File.separatorChar+"transform"+ 123 File.separatorChar+filename); 124 if (stylesheet.exists()) { 125 return stylesheet.getPath(); 126 } 127 // return the default one - should we check that it exists here? 128 stylesheet = new File(gsdl_home+File.separatorChar+"transform"+ 129 File.separatorChar+filename); 130 if (stylesheet.exists()) { 131 return stylesheet.getPath(); 132 } 133 134 // cant find it 135 return null; 136 } 137 */ 138 static public String stylesheetPath(ConfigVars config, String filename) { 139 // try site one first 140 File stylesheet = new File(config.sites_home_+File.separatorChar+ 141 config.site_name_+File.separatorChar+ 142 "transform"+File.separatorChar+filename); 143 if (stylesheet.exists()) { 144 return stylesheet.getPath(); 145 } 146 // try custom display 147 stylesheet = new File(config.interfaces_home_+File.separatorChar+ 148 config.interface_name_+File.separatorChar+ 149 "transform"+File.separatorChar+filename); 150 if (stylesheet.exists()) { 151 return stylesheet.getPath(); 152 } 153 // return the default one - should we check that it exists here? 154 stylesheet = new File(config.interfaces_home_+File.separatorChar+ 155 "default"+File.separatorChar+ 156 "transform"+File.separatorChar+filename); 157 if (stylesheet.exists()) { 158 return stylesheet.getPath(); 159 } 160 161 // cant find it 162 return null; 163 } 108 164 static public String base64EncodeFromFile(String in_filename) { 109 165 byte [] data=null; -
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSXML.java
r3285 r3341 107 107 /** add text to a document/subsection element */ 108 108 public static boolean addDocText(Document owner, Element doc, String text) { 109 109 110 Element content = owner.createElement("content"); 110 111 Text t = owner.createTextNode(text); … … 133 134 134 135 } 136 137 public static boolean mergeMetadataLists(Node to, Node from) { 138 Node to_meta = GSXML.getChildByTagName(to, "metadataList"); 139 Node from_meta = getChildByTagName(from, "metadataList"); 140 141 if (from_meta == null) { // nothing to copy 142 return true; 143 } 144 Document to_owner = to.getOwnerDocument(); 145 Node new_from = to_owner.importNode(from_meta, true); 146 147 if (to_meta == null) { // just copy the whole list 148 to.appendChild(new_from); 149 return true; 150 } 151 152 // copy individual elements 153 Node child = new_from.getFirstChild(); 154 while ( child != null) { 155 to_meta.appendChild(child); 156 child = child.getNextSibling(); 157 } 158 return true; 159 } 160 161 /** takes two nodes - should have the same node type, tag name, etc 162 * copies the info from 'from' into 'to' 163 -- not finished haven't thought through the algo yet.*/ 164 /* 165 public static boolean mergeElements(Element to, Element from) { 166 167 if (to.getNodeName()!=from.getNodeName()) { 168 System.err.println("cant merge two nodes with different names"); 169 return false; 170 } 171 172 // copy any atts over - ignore for now 173 174 // copy the children 175 if (!from.hasChildNodes()) { 176 return true; 177 } 178 179 // check if they belong to the same document 180 Document to_doc = to.getOwnerDocument(); 181 Document from_doc = from.getOwnerDocument(); 182 Element newfrom; 183 if (to_doc != from_doc) { 184 nfrom = to_doc.importNode(from, true); 185 } else { 186 newfrom = from; 187 } 188 189 if (!to.hasChildNodes()) { 190 // just copy all the children over 191 Node child = newfrom.getFirstChild(); 192 while (child !=null) { 193 to.appendChild(child); 194 child = child.getNextSibling(); 195 } 196 return true; 197 } 198 199 // have to check each one to see if already present or not 200 HashMap children = getChildrenMap(to); 201 202 Node child = newfrom.getFirstChild(); 203 while (child !=null) { 204 String name = child.getNodeName(); 205 Node n = map.get(name); 206 if (n==null) { // there is no elem by that name in to 207 to.appendChild(child); 208 } 209 else { 210 } 211 return true; 212 } 213 */ 214 /** returns the (first) child element with the given name */ 215 public static Node getChildByTagName(Node n, String name) { 216 217 Node child = n.getFirstChild(); 218 while (child!=null) { 219 if (child.getNodeName().equals(name)) { 220 return child; 221 } 222 child = child.getNextSibling(); 223 } 224 return null; //not found 225 } 226 public static HashMap getChildrenMap(Node n) { 227 228 HashMap map= new HashMap(); 229 Node child = n.getFirstChild(); 230 while (child!=null) { 231 String name = child.getNodeName(); 232 map.put(name, child); 233 child = child.getNextSibling(); 234 } 235 return map; 236 } 237 238 public static Element createTextElement(Document owner, String elem_name, 239 String text) { 240 Element e = owner.createElement(elem_name); 241 Text t = owner.createTextNode(text); 242 e.appendChild(t); 243 return e; 244 245 } 246 135 247 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/XMLTransformer.java
r3308 r3341 28 28 import javax.xml.transform.dom.DOMSource; 29 29 import javax.xml.transform.stream.StreamResult; 30 31 import org.w3c.dom.Node; 30 32 31 33 // other java classes … … 90 92 } 91 93 } 94 95 public String transform(String stylesheet, Node xml_in) { 96 97 try { 98 // Use the TransformerFactory to process the stylesheet Source and generate a Transformer. 99 Transformer transformer = t_factory_.newTransformer(new StreamSource(stylesheet)); 100 101 // Use the Transformer to transform an XML Source and send the output to a Result object. 102 StringWriter output = new StringWriter(); 103 104 transformer.transform(new DOMSource(xml_in), new StreamResult(output)); 105 return output.toString(); 106 } catch (TransformerConfigurationException e) { 107 System.err.println("XMLTransformer: couldn't create transformer object: "+e.getMessage()); 108 return ""; 109 } catch (TransformerException e) { 110 System.err.println("XMLTransformer: couldn't transform the source: " + e.getMessage()); 111 return ""; 112 } 113 } 92 114 } 93 115
Note:
See TracChangeset
for help on using the changeset viewer.