Revision 40984 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/actions/CopyPasteDocsUtils.java

View differences:

CopyPasteDocsUtils.java
38 38
import org.slf4j.Logger;
39 39
import org.slf4j.LoggerFactory;
40 40

  
41
import org.gvsig.andami.PluginsLocator;
41 42
import org.gvsig.app.project.documents.Document;
42 43
import org.gvsig.tools.ToolsLocator;
43 44
import org.gvsig.tools.persistence.PersistenceManager;
......
62 63
        .getLogger(CopyPasteDocsUtils.class);
63 64

  
64 65
    /**
65
     * The file which is used to save the layers
66
     * The folder where docs are temporarily persisted
66 67
     */
67
    private static String CLIPBOARD_FOLDER =
68
        System.getProperty("user.home")
69
        + File.separator + "gvSIG"
70
        + File.separator + "clipboard-documents";
68
    private static File clipboardFolder = null;
71 69
    private static String CLIPBOARD_FILE_NAME_PREFIX = "gvSIG_docs_clipboard_";
72 70
    private static String CLIPBOARD_FILE_NAME_EXTENSION = "tmp";
73 71
    private static int MAX_FILE_COUNT = 1000;
74 72

  
75
    private static/* XML */PersistenceManager persManager = ToolsLocator
76
        .getPersistenceManager();
73
    private CopyPasteDocsUtils() {
74
    }
77 75
    
78
    static {
79
        File file = new File(CLIPBOARD_FOLDER);
80
        file.mkdirs();
76
    private static PersistenceManager getPersMan() {
77
        return ToolsLocator.getPersistenceManager();
81 78
    }
82

  
83
    private CopyPasteDocsUtils() {
79
    
80
    private static File getClipboardFolder() {
81
        if (clipboardFolder == null) {
82
            File appf = PluginsLocator.getManager().getApplicationHomeFolder();
83
            clipboardFolder = new File(appf, "clipboard-documents");
84
            clipboardFolder.mkdirs();
85
        }
86
        return clipboardFolder;
84 87
    }
85 88
    
86 89
    /**
......
96 99
            filebase = filebase + typeName;
97 100
        }
98 101
        
99
        File folder = new File(CLIPBOARD_FOLDER);
102
        File folder = getClipboardFolder();
100 103
        
101 104
        if (!folder.exists() || !folder.isDirectory()) {
102 105
            return resp;
......
111 114
        return resp;
112 115
    }
113 116
    
114
    /**
115
     * Returns null if not file exists
116
     * 
117
     * @param docTypeName
118
     * @return
119
     * @throws IOException
120
     */
121
    /*
122
    private static File getFirstClipboardFile(String docTypeName)
123
    throws IOException {
124
        
125
        if (docTypeName == null || docTypeName.length() == 0) {
126
            throw new IOException("Doc type name cannot be empty");
127
        }
128
        
129
        String filebase = System.getProperty("user.home")
130
            + File.separator + "gvSIG" + File.separator
131
            + CLIPBOARD_FILE_NAME_PREFIX + docTypeName + "_0."
132
            + CLIPBOARD_FILE_NAME_EXTENSION;
133
        File resp = new File(filebase);
134
        if (resp.exists()) {
135
            return resp;
136
        } else {
137
            return null;
138
        }
139
    }
140
    */
141 117
    
142 118
    private static File getFirstUnusedClipboardFile(String docTypeName)
143 119
    throws IOException {
......
146 122
            throw new IOException("Doc type name cannot be empty");
147 123
        }
148 124
        
149
        String filebase = null;
125
        String filename = null;
150 126
        for (int i=0; i<MAX_FILE_COUNT; i++) {
151
            filebase = CLIPBOARD_FOLDER + File.separator
152
                + CLIPBOARD_FILE_NAME_PREFIX + docTypeName + "_" +
127
            filename = CLIPBOARD_FILE_NAME_PREFIX + docTypeName + "_" +
153 128
                Integer.toString(i)
154 129
                + "." + CLIPBOARD_FILE_NAME_EXTENSION;
155
            File resp = new File(filebase);
130
            File resp = new File(getClipboardFolder(), filename);
156 131
            if (!resp.exists()) {
157 132
                /*
158 133
                 * Removed when JVM terminates
......
178 153
            filebase = filebase + docTypeName;
179 154
        }
180 155
        
181
        File folder = new File(CLIPBOARD_FOLDER);
156
        File folder = getClipboardFolder();
182 157
        
183 158
        if (!folder.exists() || !folder.isDirectory()) {
184 159
            /*
......
232 207
        for (int i=0; i<ff.size(); i++) {
233 208
            infile = ff.get(i);
234 209
            is = new FileInputStream(infile);
235
            obj = persManager.getObject(is);
210
            obj = getPersMan().getObject(is);
236 211
            is.close();
237 212
            if (obj instanceof Document) {
238 213
                doc = (Document) obj;
......
299 274
        PersistentState state = null;
300 275
            
301 276
        for (int i=0; i<docs.size(); i++) {
302
            state = persManager.getState(docs.get(i), true);
277
            state = getPersMan().getState(docs.get(i), true);
303 278
            if (state.getContext().getErrors() != null) {
304 279
                throw state.getContext().getErrors();
305 280
            }
306 281
            f = getFirstUnusedClipboardFile(typeName);
307 282
            os = new FileOutputStream(f);
308
            persManager.saveState(state, os);
283
            getPersMan().saveState(state, os);
309 284
            os.close();
310 285
        }
311 286
    }

Also available in: Unified diff