[hg] main-silver: Issue #226122 - Enable to discover parent MIME...

  • From: Svata Dedic < >
  • To:
  • Subject: [hg] main-silver: Issue #226122 - Enable to discover parent MIME...
  • Date: Sun, 03 Mar 2013 02:39:48 -0800

changeset eaddbb772461 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/eaddbb772461
description:
        Issue #226122 - Enable to discover parent MIME type (path): fixed
        #226122: added getIncludedPaths and getInheritedType

diffstat:

 editor.mimelookup/apichanges.xml                                       |  20 
++-
 editor.mimelookup/manifest.mf                                          |   2 
+-
 editor.mimelookup/src/org/netbeans/api/editor/mimelookup/MimePath.java |  74 
++++++++++
 3 files changed, 94 insertions(+), 2 deletions(-)

diffs (126 lines):

diff --git a/editor.mimelookup/apichanges.xml 
b/editor.mimelookup/apichanges.xml
--- a/editor.mimelookup/apichanges.xml
+++ b/editor.mimelookup/apichanges.xml
@@ -107,7 +107,25 @@
     <!-- ACTUAL CHANGES BEGIN HERE: -->
 
     <changes>
-
+        <change id="MimePath.inherited">
+            <summary>Access to parent MIME type and all included 
paths</summary>
+            <version major="1" minor="31"/>
+            <date day="27" month="2" year="2013"/>
+            <author login="sdedic"/>
+            <compatibility binary="compatible" source="compatible" 
semantic="compatible" addition="no" deletion="no" modification="no" 
deprecation="yes"/>
+            <description>
+                <p>
+                    <code>getIncludedPaths</code> can be now used to compute 
all MimePaths that should
+                    be considered for the content. In the past, reflection 
was used to access this functionality.
+                </p>
+                <p>
+                    <code>getInheritedType</code> provides generalized or 
parent MIME type for the content, 
+                    which allows to search settings (services) fallbacks.
+                </p>
+            </description>
+            <class package="org.netbeans.api.editor.mimelookup" 
name="MimePath"/>
+            <issue number="226122"/>
+        </change>
         <change id="Class2LayerFolder.deprecated">
             <summary>Class2LayerFolder Deprecated and not used</summary>
             <version major="1" minor="20"/>
diff --git a/editor.mimelookup/manifest.mf b/editor.mimelookup/manifest.mf
--- a/editor.mimelookup/manifest.mf
+++ b/editor.mimelookup/manifest.mf
@@ -1,7 +1,7 @@
 Manifest-Version: 1.0
 OpenIDE-Module: org.netbeans.modules.editor.mimelookup/1
 OpenIDE-Module-Localizing-Bundle: 
org/netbeans/modules/editor/mimelookup/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.30
+OpenIDE-Module-Specification-Version: 1.31
 OpenIDE-Module-Recommends: 
org.netbeans.spi.editor.mimelookup.MimeDataProvider
 AutoUpdate-Essential-Module: true
 
diff --git 
a/editor.mimelookup/src/org/netbeans/api/editor/mimelookup/MimePath.java 
b/editor.mimelookup/src/org/netbeans/api/editor/mimelookup/MimePath.java
--- a/editor.mimelookup/src/org/netbeans/api/editor/mimelookup/MimePath.java
+++ b/editor.mimelookup/src/org/netbeans/api/editor/mimelookup/MimePath.java
@@ -532,6 +532,80 @@
         return true;
     }
     
+    /**
+     * Returns the inherited Mime type.
+     * For {@link #EMPTY}, returns {@code null}. For most other mime types, 
returns
+     * {@code ""}. If the mime type derives from another one, such as 
text/ant+xml derives
+     * from xml, the return value will be the base mime type (text/xml in 
the example case).
+     * <p/>
+     * For MimePaths that identified embedded content (more components on 
the MimePath),
+     * the method returns the parent MIME of the last MIME type on the path
+     * 
+     * @return inherited mime type, or {@code null}, if no parent exists 
(for {@link #EMPTY})
+     */
+    public String getInheritedType() {
+        if ("".equals(mimeType)) {
+            return null;
+        }
+        MimePath lastType = (size() == 1) ? this : MimePath.parse(mimeType);
+        List<String> inheritedPaths = lastType.getInheritedPaths(null, null);
+        if (inheritedPaths.size() > 1) {
+            return inheritedPaths.get(1);
+        } else {
+            return null;
+        }
+    }
+    
+    
+    /**
+     * Returns the included Mime paths.
+     * For MimePath, which nests several MIME types (i.e. 
text/php/text/html/text/css), it enumerates
+     * sub-paths so that a following element represents one level of nesting 
of the content.
+     * For the example example, the return would be:
+     * <ol>
+     * <li>text/php/text/html/text/css -- the full path
+     * <li>text/html/text/css -- outer content is removed
+     * <li>text/css -- the mime type of the identified content itself
+     * <li> (empty string)
+     * </ol>
+     * <p/>
+     * If a MIME type on the path has a generic MIME type (i.e. 
text/x-ant+xml 
+     * has a generic MIME type text/xml), that generic type will be 
inserted. For example,
+     * for text/java/text/x-ant+xml/text/javascript, the result will list:
+     * <ol>
+     * <li>text/java/text/x-ant+xml/text/javascript, -- the full MimePath
+     * <li>text/x-ant+xml/text/javascript -- a prefix
+     * <li>text/xml/text/javascript -- ant+xml is generalized to xml
+     * <li>text/javascript
+     * <li>  (empty string)
+     * </ol>
+     * For all but {@link #EMPTY} MimePaths, the list contains at least one 
entry, and the last
+     * entry is the {@link #EMPTY}. Note also, that the complete MimePath is 
always returned
+     * as the 1st member of the list.
+     * <p/>
+     * The returned sequence of MimePaths is suitable for searching settings 
or services
+     * for the (embedded) content whose type is described by MimePath as it 
is ordered from the
+     * most specific to the least specific paths (including generalization) 
and always contains
+     * the mime type of the identified contents. The last component ({@link 
""}) represents 
+     * default settings (services).
+     * <p/>
+     * Note that for MimePaths created from a mime type (not empty!) string, 
the 
+     * <code>getInheritedPaths().get(1)</code> is a parent mime type. Either 
empty,
+     * or the generalized MIME.
+     * <p/>
+     * The caller should not modify the returned List.
+     * 
+     * @return list of inherited Mime paths
+     */
+    public List<MimePath> getIncludedPaths() {
+        List<String> paths = getInheritedPaths(null, null);
+        List<MimePath> mpaths = new ArrayList<MimePath>(paths.size());
+        for (String p : paths) {
+            mpaths.add(MimePath.parse(p));
+        }
+        return mpaths;
+    }
+    
     // XXX: This is currently called from editor/settings/storage 
(SettingsProvider)
     // and editor/mimelookup/impl via reflection.
     // We will eventually make it friend API. In the meantime just

[hg] main-silver: Issue #226122 - Enable to discover parent MIME...

Svata Dedic 03/03/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