source: trunk/java-client/org/nzdl/gsdl/ptp/Locator.java@ 2136

Last change on this file since 2136 was 2136, checked in by say1, 23 years ago

helps if i add all the files ...

  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/*
2 * TODO.java
3 * Copyright (C) 2000 Stuart Yeates
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20// the package we're in
21package org.nzdl.gsdl.ptp;
22
23// java standard library classes used
24import java.io.IOException;
25import java.io.Reader;
26import java.io.InputStreamReader;
27import java.io.Writer;
28import java.io.OutputStreamWriter;
29import java.io.BufferedInputStream;
30import java.io.BufferedOutputStream;
31import java.io.Serializable;
32//import java.io.;
33import java.util.*;
34import java.net.*;
35
36/**
37 * Class Locator is an abstract contact details for a digital library
38 *
39 * Currently implemented Locators include HTTP, IOR and PTP
40 *
41 * @author stuart yeates ([email protected])
42 * @version $Revision: 2136 $
43 * @see org.nzdl.gsdl.ptp.PTP
44 * @see org.nzdl.gsdl.ptp.HTTP
45 * @see org.nzdl.gsdl.ptp.IOR
46 *
47 */
48
49public abstract class Locator {
50
51 /**
52 * Convert a Locator from a string into a Locator.
53 * @param the String to be parsed
54 * @return null if unable to parse the string, otherwise an instance of a Locator subclass
55 */
56 static Locator parse(String str) {
57 String ptp = new String("PTP");
58 String http = new String("HTTP");
59 String ior = new String("IOR");
60
61 String first = str.substring(0,ptp.length());
62 if (first.compareToIgnoreCase(ptp) == 0) {
63
64 StringBuffer leading = new StringBuffer();
65 StringBuffer host = new StringBuffer();
66 StringBuffer port = new StringBuffer();
67 StringBuffer trailing = new StringBuffer();
68
69 int i = 0;
70 while(i < str.length() && str.charAt(i) != ':') {
71 leading.append(str.charAt(i));
72 i++;
73 }
74 i++;
75 while(i < str.length() && str.charAt(i) != ':') {
76 host.append(str.charAt(i));
77 i++;
78 }
79 i++;
80 while(i < str.length() && Character.isDigit(str.charAt(i)) ) {
81 port.append(str.charAt(i));
82 i++;
83 }
84 while(i < str.length() ) {
85 trailing.append(str.charAt(i));
86 i++;
87 }
88 System.err.println("PTP parsed \"" + str + "\" into host = \"" +
89 host + "\" and port = \"" + port + "\"");
90 if (port.equals(""))
91 throw new Error ("unable to parse: " +str);
92
93 return new PTP(host.toString(),Integer.parseInt(port.toString()));
94
95 }
96 first = str.substring(0,http.length());
97 if (first.compareToIgnoreCase(http) == 0) {
98 URL url = null;
99 try {
100 url = new URL(str);
101 } catch (MalformedURLException exception) {
102 System.err.println("HTTP: " + str + " threw a MalformedURLException");
103 return null;
104 }
105 if (!(url.getProtocol().compareToIgnoreCase("http") == 0))
106 {
107 System.err.println("HTTP: " + str + " not an http url");
108 }
109 return new HTTP(url.getHost(),url.getPort(), url.getFile());
110 }
111 first = str.substring(0,ptp.length());
112 if (first.compareToIgnoreCase(ior) == 0) {
113 return null;
114 }
115 return null;
116 }
117
118}
119
120
121
122
123
124
125
Note: See TracBrowser for help on using the repository browser.