# HG changeset patch # Parent ab27872cd0c2318a578d72e76e21929171ee1807 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 @@ - + + Access to parent MIME type and all included paths + + + + + +

+ getIncludedPaths 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. +

+

+ getInheritedType provides generalized or parent MIME type for the content, + which allows to search settings (services) fallbacks. +

+
+ + +
Class2LayerFolder Deprecated and not used 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). + *

+ * 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 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: + *

    + *
  1. text/php/text/html/text/css -- the full path + *
  2. text/html/text/css -- outer content is removed + *
  3. text/css -- the mime type of the identified content itself + *
  4. (empty string) + *
+ *

+ * 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: + *

    + *
  1. text/java/text/x-ant+xml/text/javascript, -- the full MimePath + *
  2. text/x-ant+xml/text/javascript -- a prefix + *
  3. text/xml/text/javascript -- ant+xml is generalized to xml + *
  4. text/javascript + *
  5. (empty string) + *
+ * 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. + *

+ * 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). + *

+ * Note that for MimePaths created from a mime type (not empty!) string, the + * getInheritedPaths().get(1) is a parent mime type. Either empty, + * or the generalized MIME. + *

+ * The caller should not modify the returned List. + * + * @return list of inherited Mime paths + */ + public List getIncludedPaths() { + List paths = getInheritedPaths(null, null); + List mpaths = new ArrayList(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