Lines 532-537
Link Here
|
532 |
return true; |
532 |
return true; |
533 |
} |
533 |
} |
534 |
|
534 |
|
|
|
535 |
/** |
536 |
* Returns the inherited Mime type. |
537 |
* For {@link #EMPTY}, returns {@code null}. For most other mime types, returns |
538 |
* {@code ""}. If the mime type derives from another one, such as text/ant+xml derives |
539 |
* from xml, the return value will be the base mime type (text/xml in the example case). |
540 |
* <p/> |
541 |
* For MimePaths that identified embedded content (more components on the MimePath), |
542 |
* the method returns the parent MIME of the last MIME type on the path |
543 |
* |
544 |
* @return inherited mime type, or {@code null}, if no parent exists (for {@link #EMPTY}) |
545 |
*/ |
546 |
public String getInheritedType() { |
547 |
if ("".equals(mimeType)) { |
548 |
return null; |
549 |
} |
550 |
MimePath lastType = (size() == 1) ? this : MimePath.parse(mimeType); |
551 |
List<String> inheritedPaths = lastType.getInheritedPaths(null, null); |
552 |
if (inheritedPaths.size() > 1) { |
553 |
return inheritedPaths.get(1); |
554 |
} else { |
555 |
return null; |
556 |
} |
557 |
} |
558 |
|
559 |
|
560 |
/** |
561 |
* Returns the included Mime paths. |
562 |
* For MimePath, which nests several MIME types (i.e. text/php/text/html/text/css), it enumerates |
563 |
* sub-paths so that a following element represents one level of nesting of the content. |
564 |
* For the example example, the return would be: |
565 |
* <ol> |
566 |
* <li>text/php/text/html/text/css -- the full path |
567 |
* <li>text/html/text/css -- outer content is removed |
568 |
* <li>text/css -- the mime type of the identified content itself |
569 |
* <li> (empty string) |
570 |
* </ol> |
571 |
* <p/> |
572 |
* If a MIME type on the path has a generic MIME type (i.e. text/x-ant+xml |
573 |
* has a generic MIME type text/xml), that generic type will be inserted. For example, |
574 |
* for text/java/text/x-ant+xml/text/javascript, the result will list: |
575 |
* <ol> |
576 |
* <li>text/java/text/x-ant+xml/text/javascript, -- the full MimePath |
577 |
* <li>text/x-ant+xml/text/javascript -- a prefix |
578 |
* <li>text/xml/text/javascript -- ant+xml is generalized to xml |
579 |
* <li>text/javascript |
580 |
* <li> (empty string) |
581 |
* </ol> |
582 |
* For all but {@link #EMPTY} MimePaths, the list contains at least one entry, and the last |
583 |
* entry is the {@link #EMPTY}. Note also, that the complete MimePath is always returned |
584 |
* as the 1st member of the list. |
585 |
* <p/> |
586 |
* The returned sequence of MimePaths is suitable for searching settings or services |
587 |
* for the (embedded) content whose type is described by MimePath as it is ordered from the |
588 |
* most specific to the least specific paths (including generalization) and always contains |
589 |
* the mime type of the identified contents. The last component ({@link ""}) represents |
590 |
* default settings (services). |
591 |
* <p/> |
592 |
* Note that for MimePaths created from a mime type (not empty!) string, the |
593 |
* <code>getInheritedPaths().get(1)</code> is a parent mime type. Either empty, |
594 |
* or the generalized MIME. |
595 |
* <p/> |
596 |
* The caller should not modify the returned List. |
597 |
* |
598 |
* @return list of inherited Mime paths |
599 |
*/ |
600 |
public List<MimePath> getIncludedPaths() { |
601 |
List<String> paths = getInheritedPaths(null, null); |
602 |
List<MimePath> mpaths = new ArrayList<MimePath>(paths.size()); |
603 |
for (String p : paths) { |
604 |
mpaths.add(MimePath.parse(p)); |
605 |
} |
606 |
return mpaths; |
607 |
} |
608 |
|
535 |
// XXX: This is currently called from editor/settings/storage (SettingsProvider) |
609 |
// XXX: This is currently called from editor/settings/storage (SettingsProvider) |
536 |
// and editor/mimelookup/impl via reflection. |
610 |
// and editor/mimelookup/impl via reflection. |
537 |
// We will eventually make it friend API. In the meantime just |
611 |
// We will eventually make it friend API. In the meantime just |