[hg] main-silver: #238104: dataloader catches on generalized fil...

  • From: Svata Dedic < >
  • To:
  • Subject: [hg] main-silver: #238104: dataloader catches on generalized fil...
  • Date: Wed, 13 Nov 2013 22:25:12 +0000

changeset 0ce47b53ec27 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/0ce47b53ec27
description:
        #238104: dataloader catches on generalized file's Mime, actions 
loaded/merged from the original and generic mime.

diffstat:

 csl.api/src/org/netbeans/modules/csl/core/GsfDataLoader.java    |  44 
++++++++-
 csl.api/src/org/netbeans/modules/csl/core/GsfDataNode.java      |  46 
++++++---
 csl.api/src/org/netbeans/modules/csl/core/LanguageRegistry.java |  12 ++-
 3 files changed, 82 insertions(+), 20 deletions(-)

diffs (173 lines):

diff --git a/csl.api/src/org/netbeans/modules/csl/core/GsfDataLoader.java 
b/csl.api/src/org/netbeans/modules/csl/core/GsfDataLoader.java
--- a/csl.api/src/org/netbeans/modules/csl/core/GsfDataLoader.java
+++ b/csl.api/src/org/netbeans/modules/csl/core/GsfDataLoader.java
@@ -46,8 +46,11 @@
 import java.io.IOException;
 import java.text.DateFormat;
 import java.util.Date;
+import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import org.netbeans.api.java.classpath.ClassPath;
 import org.openide.ErrorManager;
@@ -68,6 +71,7 @@
  */
 public class GsfDataLoader extends UniFileLoader {
     boolean initialized;
+    Set<String> registeredMimes;
 
     public GsfDataLoader() {
         super("org.netbeans.modules.csl.core.GsfDataObject");
@@ -81,19 +85,53 @@
 
     final void initExtensions() {
         ExtensionList list = new ExtensionList();
-
+        Set mimes = new HashSet<String>();
         for (Language language : LanguageRegistry.getInstance()) {
             
             if(language.useCustomEditorKit()) {
                 //do not try to load files which has their own editor 
support and dataobject
                 continue;
             }
-            
+            mimes.add(language.getMimeType());
             list.addMimeType(language.getMimeType());
         }
         setExtensions(list);
+        registeredMimes = mimes;
+        initialized = true;
+    }
 
-        initialized = true;
+    /**
+     * In addition to mimetype list, checks base mime type if the mime is 
compound.
+     * This is a workaround for loaders implementation do not currently 
support compound MIME types.
+     * See defect #
+     * 
+     * @param fo file object to recognize 
+     * @return primary file / null
+     */
+    @Override
+    protected FileObject findPrimaryFile(FileObject fo) {
+        FileObject pf = super.findPrimaryFile(fo);
+        if (pf != null) {
+            return pf;
+        }
+        String mime = fo.getMIMEType();
+        int slash = -1;
+        int l = mime.length();
+        for (int i = 0; i < l; i++) {
+            char c = mime.charAt(i);
+            if (c == '/') { // NOI18N
+                slash = i;
+            } else if (c == '+') { // NOI18N
+                if (slash == -1) {
+                    return null;
+                }
+                String baseMime = mime.substring(0, slash + 1) + 
mime.substring(i + 1);
+                if (registeredMimes.contains(baseMime)) {
+                    return fo;
+                }
+            }
+        }
+        return null;
     }
 
     @Override
diff --git a/csl.api/src/org/netbeans/modules/csl/core/GsfDataNode.java 
b/csl.api/src/org/netbeans/modules/csl/core/GsfDataNode.java
--- a/csl.api/src/org/netbeans/modules/csl/core/GsfDataNode.java
+++ b/csl.api/src/org/netbeans/modules/csl/core/GsfDataNode.java
@@ -53,6 +53,7 @@
 
 import javax.swing.Action;
 import javax.swing.JSeparator;
+import org.netbeans.api.editor.mimelookup.MimePath;
 
 import org.openide.ErrorManager;
 import org.openide.actions.OpenAction;
@@ -84,6 +85,27 @@
         return SystemAction.get(OpenAction.class);
     }
 
+    private void loadActions(List<Action> actions, DataFolder df) throws 
IOException, ClassNotFoundException {
+        DataObject[] dob = df.getChildren();
+        int i;
+        int k = dob.length;
+
+        for (i = 0; i < k; i++) {
+            InstanceCookie ic = dob[i].getCookie(InstanceCookie.class);
+            if (ic == null) {
+                LOG.log(Level.WARNING, "Not an action instance, or broken 
action: {0}", dob[i].getPrimaryFile());
+                continue;
+            }
+            Class clazz = ic.instanceClass();
+
+            if (JSeparator.class.isAssignableFrom(clazz)) {
+                actions.add(null);
+            } else {
+                actions.add((Action)ic.instanceCreate());
+            }
+        }
+    }
+
     /** Get actions for this data object.
      * (Copied from LanguagesDataNode in languages/engine)
     * @see DataLoader#getActions
@@ -101,23 +123,15 @@
 
                 if (fo != null) {
                     DataFolder df = DataFolder.findFolder(fo);
-                    DataObject[] dob = df.getChildren();
-                    int i;
-                    int k = dob.length;
-
-                    for (i = 0; i < k; i++) {
-                        InstanceCookie ic = 
dob[i].getCookie(InstanceCookie.class);
-                        if (ic == null) {
-                            LOG.log(Level.WARNING, "Not an action instance, 
or broken action: {0}", dob[i].getPrimaryFile());
-                            continue;
+                    loadActions(actions, df);
                         }
-                        Class clazz = ic.instanceClass();
-
-                        if (JSeparator.class.isAssignableFrom(clazz)) {
-                            actions.add(null);
-                        } else {
-                            actions.add((Action)ic.instanceCreate());
-                        }
+                MimePath mp = MimePath.get(mimeType);
+                String s = mp.getInheritedType();
+                if (s != null && !s.isEmpty()) {
+                    fo = FileUtil.getConfigFile("Loaders/" + s + 
"/Actions"); // NOI18N
+                    if (fo != null) {
+                        DataFolder df = DataFolder.findFolder(fo);
+                        loadActions(actions, df);
                     }
                 }
             } catch (ClassNotFoundException ex) {
diff --git a/csl.api/src/org/netbeans/modules/csl/core/LanguageRegistry.java 
b/csl.api/src/org/netbeans/modules/csl/core/LanguageRegistry.java
--- a/csl.api/src/org/netbeans/modules/csl/core/LanguageRegistry.java
+++ b/csl.api/src/org/netbeans/modules/csl/core/LanguageRegistry.java
@@ -92,7 +92,17 @@
      */
     public Language getLanguageByMimeType(@NonNull String mimeType) {
         final Map<String, Language> map = getLanguages();
-        return map.get(mimeType);
+        MimePath mp = MimePath.get(mimeType);
+        Language lng = map.get(mimeType);
+        if (lng != null) {
+            return lng;
+        }
+        String s = mp.getInheritedType();
+        if (s != null && !s.isEmpty()) {
+            return map.get(s);
+        } else {
+            return null;
+        }
     }
 
 // XXX: parsingapi

[hg] main-silver: #238104: dataloader catches on generalized fil...

Svata Dedic 11/13/2013

<Possible follow-up(s)>

[hg] main-silver: #238104: dataloader catches on generalized fil...

Svata Dedic 11/16/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close