FROM:http://blog.matrix.org.cn/gh_aiyz/date/20060717
org.eclipse.core.runtime.contentTypes用于扩展系统支持的内容类型。
首先看一个example:
- <extension point="org.eclipse.core.runtime.contentTypes">
- <content-type id="ABC" base-type="org.eclipse.core.runtime.xml" file-extensions="a,b,c">
- <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber">
- <parameter name="element" value="abc"/>
- </describer>
- </content-type>
- </extension>
该extension支持以下attribute:
- id - 该内容类型的唯一标识(即可以是全限定名,也可以是简名,简名会被自动加上当前plugin的namespace而成为全限定名). 不可包含空格。
- base-type - 父类型的全限定名。 父类型的文件关联,content describer和默认字符集将会被继承,除非重定义了。
- name - 人容易读懂的类型名,主要用于界面显示之类的作用。
- file-extensions - 和该内容类型关联的文件扩展名列表,用逗号分割。
- file-names - 和该内容类型关联的文件名列表,用逗号分割。
- priority - 该内容类型的优先级,用于解决冲突(当多个内容类型关联到同一个文件名或者扩展名时)。
-
default-charset - 该内容类型的默认字符集。也可以是个空字符串,如果其父类型有默认字符集而该内容类型不应该有默认字符集。很方便的一个属性。等效于:
xml 代码- <content-type>
- <property name="org.eclipse.core.runtime.charset" default="charset-name"/>
- </content-type>
即等效于通过property元素赋值。
- describer - 实现了org.eclipse.core.runtime.content.IContentDescriber或org.eclipse.core.runtime.content.ITextContentDescriber的全限定类型。或是一个空字符串,如果其父类型有describer而该内容类型不应该有describer。
- alias-for - 一个内容的全限定名。当前类型是该类型的别名。
它支持2个子元素:describer(最多一个)和property(n个)。
describer有两个属性,class代表全限定类名,plugin为提供该类的插件的id,一般为空,表示这个类由该插件自己提供。describer属性的优先级比describer子元素高,所以一旦设了describer属性,describer子元素会被自动忽略。
describer支持parameter子元素,但是这个describer必须实现IExecutableExtension接口才行,参看XMLRootElementContentDescriber的代码,他实现了IExecutableExtension.setInitializationData()方法。
以下是几个相关的接口:
IContentType -- 其实我们并不需要太关心这个接口,尽管它代表着一个content type,但是我们不需要继承或实现它,但是它将在对content type敏感的插件中用到。
IContentDescription -- 同样,我们也不需要实现这个接口,它用来包含被检查的数据的属性信息。它总是包含被检查数据的content type,这个由eclipse platform设置的。它通常还有可能包含一下信息,这些信息是由describer来填充的:
- 字符集
- byte order mark
- 其他第三方插件提供的property。
IContentDescriber/ITextContentDescriber -- 这两个接口是content type的validator和description填充者。后者为文本类型的content types专用。describer负责从content里面读取元数据并设到description中。其describe()方法可以返回三个值,这三个值都在IContentDescriber中定义,分别为
- INDETERMINATE -- 模糊不清
- VALID -- 有效
- INVALID -- 无效