KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > irplugin > RepositoryFile


1 /*
2  * RepositoryFolder.java
3  *
4  * All rights reserved.
5  * Copyright (C) 2005 JasperSoft Corporation
6  *
7  * JasperSoft Corporation
8  * 303 Second Street, Suite 450 North
9  * San Francisco, CA 94107
10  * http://www.jaspersoft.com
11  *
12  *
13  * Created on April 1, 2006, 3:46 PM
14  *
15  */

16
17 package com.jaspersoft.jasperserver.irplugin;
18
19 import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.ResourceDescriptor;
20 import java.io.File JavaDoc;
21
22
23 /**
24  *
25  * @author gtoffoli
26  */

27 public class RepositoryFile extends RepositoryFolder {
28
29     private String JavaDoc localFileName = null;
30     
31     
32     /** Creates a new instance of RepositoryFolder */
33     public RepositoryFile(JServer server, ResourceDescriptor descriptor) {
34         super( server, descriptor);
35     }
36
37     public String JavaDoc toString()
38     {
39         if (getDescriptor() != null)
40         {
41             return ""+getDescriptor().getLabel();
42         }
43         return "???";
44     }
45     
46     /**
47      * This method return the file rapresented by this resource file.
48      * The file is cached in a temporary directory for subsequent calls to this method.
49      * Please note: the file is never removed... a delete of this file should be done
50      * on plugin startup....
51      * The method returns the cached file name.
52      *
53      */

54     public String JavaDoc getFile() throws Exception JavaDoc
55     {
56         if (localFileName == null)
57         {
58             String JavaDoc localFile = IRPlugin.getMainInstance().createTmpFileName("img",null);
59             try {
60                 //System.out.println("File saved here: " + localFile);
61
getServer().getWSClient().get(getDescriptor(), new File JavaDoc(localFile));
62             } catch (Exception JavaDoc ex)
63             {
64                 ex.printStackTrace();
65             }
66             
67             this.localFileName = localFile;
68         }
69         return localFileName;
70     }
71     
72     /**
73      * If localFileName exists, remove it and set localFileName to NULL.
74      */

75     public void resetFileCache()
76     {
77         if (localFileName != null)
78         {
79             File JavaDoc f = new File JavaDoc(localFileName);
80             if (f.exists())
81             {
82                 f.delete();
83             }
84         }
85         
86         localFileName = null;
87     }
88
89 }
90
Popular Tags