01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * The Original Software is NetBeans. The Initial Developer of the Original
16: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19: package org.netbeans.modules.xslt.tmap;
20:
21: import java.io.IOException;
22: import org.netbeans.api.project.FileOwnerQuery;
23: import org.netbeans.api.project.Project;
24: import org.netbeans.modules.xslt.tmap.util.Util;
25: import org.openide.filesystems.FileObject;
26: import org.openide.loaders.DataObjectExistsException;
27: import org.openide.loaders.MultiDataObject;
28: import org.openide.loaders.UniFileLoader;
29: import org.openide.util.NbBundle;
30:
31: /**
32: *
33: * @author Vitaly Bychkov
34: * @version 1.0
35: */
36: public class TMapDataLoader extends UniFileLoader {
37:
38: public static final String MIME_TYPE = "text/x-tmap+xml";// NOI18N
39: public static final String TRANSFORMMAP_XML = "transformmap.xml";// NOI18N
40: public static final String LOADER_NAME = "LBL_loader_name"; // NOI18N
41: public static final String ACTION_CONTEXT = "Loaders/" + MIME_TYPE
42: + "/Actions"; // NOI18N
43:
44: private static final long serialVersionUID = 1L;
45:
46: public TMapDataLoader() {
47: super ("org.netbeans.modules.xslt.tmap.TMapDataObject");
48: }
49:
50: @Override
51: protected String defaultDisplayName() {
52: return NbBundle.getMessage(TMapDataLoader.class, LOADER_NAME);
53: }
54:
55: @Override
56: protected void initialize() {
57: super .initialize();
58: getExtensions().addMimeType(MIME_TYPE);
59: }
60:
61: @Override
62: protected MultiDataObject createMultiObject(FileObject primaryFile)
63: throws DataObjectExistsException, IOException {
64: return new TMapDataObject(primaryFile, this );
65: }
66:
67: @Override
68: protected FileObject findPrimaryFile(FileObject fo) {
69: FileObject primaryFo = null;
70: String extension = fo.getNameExt();
71: if (extension != null && extension.equals(TRANSFORMMAP_XML)) {
72: // recognize tmap file only in context of XSLT project
73: primaryFo = isXsltProjectContext(fo) ? fo : null;
74: }
75: return primaryFo;
76: }
77:
78: // TODO m
79: private boolean isXsltProjectContext(FileObject fo) {
80: boolean isXsltProject = false;
81:
82: Project project = FileOwnerQuery.getOwner(fo);
83: FileObject source = project == null ? null : Util
84: .getProjectSource(project);
85:
86: isXsltProject = source != null && source.equals(fo.getParent());
87:
88: return isXsltProject;
89: }
90:
91: @Override
92: protected String actionsContext() {
93: return ACTION_CONTEXT;
94: }
95:
96: }
|