Changeset 3284
- Timestamp:
- 2002-07-30T09:54:24+12:00 (22 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3/util
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSFile.java
r3235 r3284 20 20 21 21 import java.io.File; 22 import org.apache.soap.encoding.soapenc.Base64; 23 import java.io.BufferedInputStream; 24 import java.io.BufferedOutputStream; 25 import java.io.FileInputStream; 26 import java.io.FileOutputStream; 27 import java.io.InputStream; 28 import java.io.IOException; 22 29 23 30 /** … … 39 46 40 47 /** creates a File for the collection directory */ 41 static public File collect ionDirFile(String site_home) {48 static public File collectDirFile(String site_home) { 42 49 return new File(site_home+File.separatorChar+"collect"); 43 50 } 51 44 52 45 53 /** creates a File for the collection config file */ … … 66 74 return gsdl_home+File.separatorChar+"transform"; 67 75 } 76 77 /** returns the base directory name for a collection */ 78 static public String collectionBaseDir(String site_home, 79 String collection_name) { 80 return site_home+File.separatorChar+"collect"+ 81 File.separatorChar+collection_name; 82 } 83 84 /** returns the text path (for doc retrieval) relative to collectionBaseDir */ 85 static public String collectionTextPath(String collection_name) { 86 return "index"+File.separatorChar+"text"+File.separatorChar+ 87 collection_name; 88 } 89 90 /** returns the index path (for querying) relative to collectionBaseDir */ 91 static public String collectionIndexPath(String collection_name, 92 String index_name) { 93 return "index"+File.separatorChar+index_name+File.separatorChar+ 94 collection_name; 95 } 96 97 /** returns an absolute path for an associated file */ 98 static public String assocFileAbsolutePath(String site_home, 99 String collection_name, 100 String assoc_file_path, 101 String filename) { 102 return collectionBaseDir(site_home, collection_name)+ 103 File.separatorChar+"index"+File.separatorChar+ 104 "assoc"+File.separatorChar+assoc_file_path+ 105 File.separatorChar+filename; 106 } 107 108 static public String base64EncodeFromFile(String in_filename) { 109 byte [] data=null; 110 try { 111 data = readFile(in_filename); 112 } catch (Exception e) { 113 System.out.println("couldn't read the file"); 114 } 115 String encodedString = Base64.encode(data); 116 return encodedString; 117 118 } 119 static public boolean base64DecodeToFile(String data, String out_filename) { 120 try { 121 byte[] buffer=Base64.decode(data); 122 writeFile(buffer, out_filename); 68 123 124 } catch (Exception e) { 125 System.err.println("file opening/closing errors"+e.getMessage()); 126 return false; 127 } 128 return true; 129 130 } 131 132 public static byte[] readFile(String filename) throws IOException { 133 File file = new File(filename); 134 BufferedInputStream bis = new BufferedInputStream(new 135 FileInputStream(file)); 136 int bytes = (int) file.length(); 137 byte[] buffer = new byte[bytes]; 138 int readBytes = bis.read(buffer); 139 bis.close(); 140 return buffer; 141 } 142 public static void writeFile(byte [] buffer, String filename) throws IOException { 143 File file = new File(filename); 144 BufferedOutputStream bos = new BufferedOutputStream(new 145 FileOutputStream(file)); 146 bos.write(buffer); 147 bos.close(); 148 } 69 149 70 150 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/OID.java
r3257 r3284 8 8 9 9 /** returns everything up to the first dot 10 if no dot, returns OID*/11 public static String getTop(String OID) {12 int pos = OID.indexOf('.');10 if no dot, returns oid */ 11 public static String getTop(String oid) { 12 int pos = oid.indexOf('.'); 13 13 if (pos == -1) { 14 return OID;14 return oid; 15 15 } 16 return OID.substring(0, pos); 16 return oid.substring(0, pos); 17 17 18 } 18 /** returns true is OID is top level (ie has no dots) */ 19 public static boolean isTop(String OID) { 20 return (OID.indexOf('.')==-1); 19 /** returns true is oid is top level (ie has no dots) 20 returns false for an empty oid */ 21 public static boolean isTop(String oid) { 22 if (oid.equals("")) { 23 return false; 24 } 25 return (oid.indexOf('.')==-1); 21 26 } 22 27 23 /** returns the parent of OID(everything up to last dot)24 returns "" if OIDhas no parent */25 public static String getParent(String OID) {26 int pos = OID.lastIndexOf('.');28 /** returns the parent of oid (everything up to last dot) 29 returns "" if oid has no parent */ 30 public static String getParent(String oid) { 31 int pos = oid.lastIndexOf('.'); 27 32 if (pos == -1) { 28 33 return ""; 29 34 } 30 return OID.substring(0, pos);35 return oid.substring(0, pos); 31 36 } 32 37 33 38 /** returns the full name - replaces " with parent */ 34 public static String translateParent(String OID, String parent) {39 public static String translateParent(String oid, String parent) { 35 40 // this is the behaviour of the original - should only replace first 36 41 //perhaps? 37 return OID.replaceAll("\"", parent);42 return oid.replaceAll("\"", parent); 38 43 } 39 44 /** does the opposite to translate_parent */ 40 public static String shrinkParent(String OID) {41 int pos = OID.lastIndexOf('.');42 if (pos==-1) return OID;43 return "\""+ OID.substring(pos);45 public static String shrinkParent(String oid) { 46 int pos = oid.lastIndexOf('.'); 47 if (pos==-1) return oid; 48 return "\""+oid.substring(pos); 44 49 } 45 /** returns true if OIDuses .fc, .lc, .pr, .ns, .ps */46 public static boolean needsTranslating(String OID) {47 String tail = OID.substring(OID.length()-3);50 /** returns true if oid uses .fc, .lc, .pr, .ns, .ps */ 51 public static boolean needsTranslating(String oid) { 52 String tail = oid.substring(oid.length()-3); 48 53 return (tail.equals(".fc") || tail.equals(".lc") || tail.equals(".pr") 49 54 || tail.equals(".ns") || tail.equals(".ps")); 50 55 } 51 56 /** strips suffix from end */ 52 public static String stripSuffix(String OID) {53 String tail = OID.substring(OID.length()-3);57 public static String stripSuffix(String oid) { 58 String tail = oid.substring(oid.length()-3); 54 59 while (tail.equals(".fc") || tail.equals(".lc") || tail.equals(".pr") 55 60 || tail.equals(".ns") || tail.equals(".ps")) { 56 OID = OID.substring(0, OID.length()-3);57 tail = OID.substring(OID.length()-3);61 oid = oid.substring(0, oid.length()-3); 62 tail = oid.substring(oid.length()-3); 58 63 } 59 return OID;64 return oid; 60 65 } 61 /** returns true if child is a child of parent */ 66 /** returns true if child is a child of parent 67 an oid is not a child of itself */ 62 68 public static boolean isChildOf(String parent, String child) { 69 if (parent.equals(child)) { 70 return false; 71 } 63 72 return child.startsWith(parent); 64 73 }
Note:
See TracChangeset
for help on using the changeset viewer.