source: trunk/java-client/org/nzdl/gsdl/service/NzdlDocSaveWrapper.java@ 2254

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

fixed Makefiles to stop deleting html files. Added the notion of a Wrapper. Converted NzdlCachingServiceClient to NzdlCacheWrapper. Added NzdlDocSaveWrapper. Added NzdlLogWrapper. Added functionality to NzdlIORs to use these.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1/*
2 * NzdlDocSaveWrapper.java
3 * Copyright (C) 2001 New Zealand Digital Library Project
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.service;
22
23import java.io.File;
24import java.io.FileWriter;
25
26/* gsdl corba stuff */
27import org.nzdl.gsdl.corba.gsdlInterface.corbaFilterRequest;
28import org.nzdl.gsdl.util.NzdlCorbaFactory;
29
30/**
31 * A Wrapper around an NzdlService object that adds functionality.
32 *
33 * Typically one or more of the methods will be overridden to
34 * add that functionality
35 *
36 * @author Brett Sheeran ([email protected]) (comments)
37 * @author Stuart Yeates ([email protected])
38 * @version $Revision: 2157 $
39 */
40public class NzdlDocSaveWrapper
41 extends NzdlWrapper {
42
43 static String dirPath = "/tmp/docs/";
44
45 /**
46 * The bean constructor ...
47 */
48 public NzdlDocSaveWrapper() {
49 }
50
51 /**
52 * The normal constructor ...
53 */
54 public NzdlDocSaveWrapper(NzdlService service) {
55 super(service);
56 try {
57 File directory = new File(dirPath);
58 if (!directory.exists())
59 directory.mkdirs();
60 } catch (Exception exception) {
61 System.err.println("unable to create directory: " + exception);
62 }
63 }
64
65 /**
66 * Wraps a getDocument and saves to disk any documents we see ...
67 * @see NzdlService#getDocument
68 */
69 public String getDocument( String _name, String _docID ) {
70
71 String doc = super.getDocument(_name,_docID);
72
73 try {
74 File dir = new File(dirPath, _name);
75 if (!dir.exists())
76 dir.mkdirs();
77 File file = new File(dir, _docID);
78 if (!file.exists()) {
79 FileWriter writer = new FileWriter(file);
80 writer.write("<gsdlsection>");
81 writer.write(doc);
82 writer.write("</gsdlsection>");
83 writer.flush();
84 writer.close();
85 }
86 } catch (Exception exception) {
87 System.err.println("Exception: " + exception);
88 }
89
90 return doc;
91 }
92
93}
Note: See TracBrowser for help on using the repository browser.