1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.netbeans.modules.office.loader;
25 
26 import java.io.IOException;
27 import java.io.File;
28 
29 import org.openide.actions.*;
30 import org.openide.filesystems.*;
31 import org.openide.loaders.*;
32 import org.openide.util.NbBundle;
33 import org.openide.util.actions.SystemAction;
34 
35 import org.openoffice.netbeans.modules.office.actions.MountDocumentAction;
36 
37 /** Recognizes single files in the Repository as being of a certain type.
38  *
39  * @author tomaso
40  */
41 public class OfficeDocumentDataLoader extends UniFileLoader {
42 
OfficeDocumentDataLoader()43     public OfficeDocumentDataLoader() {
44         this("org.openoffice.netbeans.modules.office.loader.OfficeDocumentDataObject");
45     }
46 
47     // Can be useful for subclasses:
OfficeDocumentDataLoader(String recognizedObjectClass)48     protected OfficeDocumentDataLoader(String recognizedObjectClass) {
49         super(recognizedObjectClass);
50     }
51 
defaultDisplayName()52     protected String defaultDisplayName() {
53         return "Office Document";
54     }
55 
initialize()56     protected void initialize() {
57         super.initialize();
58 
59         ExtensionList extensions = new ExtensionList();
60         extensions.addExtension("sxw");
61         extensions.addExtension("sxc");
62         extensions.addExtension("sxd");
63         extensions.addExtension("sxi");
64         setExtensions(extensions);
65     }
66 
findPrimaryFile(FileObject fo)67     protected FileObject findPrimaryFile(FileObject fo) {
68         ExtensionList extensions = getExtensions();
69         if (extensions.isRegistered(fo) == false)
70             return null;
71 
72         File document = FileUtil.toFile(fo);
73         JarFileSystem jarFs = new JarFileSystem();
74 
75         try {
76             jarFs.setJarFile(document);
77         }
78         catch (IOException e) {
79             // TopManager.getDefault().notify(new NotifyDescriptor.Exception(e, "asdf"));
80             return null;
81         }
82         catch (Exception e) {
83             return null;
84         }
85         return fo;
86     }
87 
defaultActions()88     protected SystemAction[] defaultActions() {
89         return new SystemAction[] {
90             SystemAction.get(OpenAction.class),
91             // SystemAction.get(MountDocumentAction.class),
92             null,
93             SystemAction.get(CutAction.class),
94             SystemAction.get(CopyAction.class),
95             SystemAction.get(PasteAction.class),
96             null,
97             SystemAction.get(DeleteAction.class),
98             SystemAction.get(RenameAction.class),
99             null,
100             // SystemAction.get(ToolsAction.class),
101             SystemAction.get(PropertiesAction.class),
102         };
103     }
104 
createMultiObject(FileObject primaryFile)105     protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException {
106         return new OfficeDocumentDataObject(primaryFile, this);
107     }
108 }
109