01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19: package de.schlund.pfixxml;
20:
21: import java.io.File;
22:
23: import de.schlund.pfixxml.config.GlobalConfigurator;
24: import de.schlund.pfixxml.resources.ResourceUtil;
25: import de.schlund.pfixxml.util.Path;
26:
27: /**
28: * Describe class PathFactory here.
29: *
30: *
31: * Created: Tue Jun 29 18:04:32 2004
32: *
33: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
34: * @version 1.0
35: * @deprecated Use {@link ResourceUtil} instead
36: */
37: @Deprecated
38: public class PathFactory {
39: private static PathFactory instance = new PathFactory();
40: private File docroot;
41:
42: private PathFactory() {
43: }
44:
45: public static PathFactory getInstance() {
46: return instance;
47: }
48:
49: public Path createPath(String relative) {
50: if (relative.startsWith(File.separator)) {
51: throw new IllegalArgumentException(
52: "**** Need a relative path: " + relative);
53: }
54: return Path.create(docroot, relative);
55: }
56:
57: public String makePathStringRelative(String absolute) {
58: if (!absolute.startsWith(docroot.getPath() + File.separator)) {
59: throw new IllegalArgumentException("**** Absolute path "
60: + absolute + " can't be made relative to docroot "
61: + docroot.getPath());
62: }
63: return absolute.substring((docroot.getPath() + File.separator)
64: .length());
65: }
66:
67: public void init(String docrootstr) {
68: docroot = new File(docrootstr);
69: if (!docroot.isDirectory()) {
70: throw new RuntimeException("**** docroot " + docrootstr
71: + " must be a directory! ****");
72: }
73: if (!docroot.isAbsolute()) {
74: throw new RuntimeException("**** docroot " + docrootstr
75: + " must be a absolute! ****");
76: }
77: System.out.println("Docroot is: " + docroot.getPath());
78:
79: // Try to initialize the new resolution system for compatibility reasons
80: // - old code might only know PathFactory.
81: try {
82: GlobalConfigurator.setDocroot(docrootstr);
83: } catch (IllegalStateException e) {
84: // Ignore exception - this is absolutely okay, as this
85: // configuration might already have been performed by other code
86: }
87: }
88:
89: }
|