KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > runtime > content > IContentType


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.runtime.content;
12
13 import java.io.*;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.QualifiedName;
16 import org.eclipse.core.runtime.preferences.IScopeContext;
17
18 /**
19  * Content types represent and provide information on file types, such as
20  * associated file names/extensions, default charset, etc.
21  * <p>
22  * This interface is not intended to be implemented by clients.
23  * </p>
24  *
25  * @since 3.0
26  */

27 public interface IContentType extends IContentTypeSettings {
28     /**
29      * File spec type flag constant, indicating that pre-defined file
30      * specifications should not be taken into account.
31      */

32     public static final int IGNORE_PRE_DEFINED = 0x01;
33     /**
34      * File spec type flag constant, indicating that user-defined file
35      * specifications should not be taken into account.
36      */

37     public static final int IGNORE_USER_DEFINED = 0x02;
38     /**
39      * File spec type constant, indicating a file name specification.
40      */

41     public static final int FILE_NAME_SPEC = 0x04;
42     /**
43      * File spec type constant, indicating a file extension specification.
44      */

45     public static final int FILE_EXTENSION_SPEC = 0x08;
46
47     /**
48      * Returns a reference to this content type's base type. If this content type
49      * does not have a base type (it is a root type), returns <code>null</code>.
50      *
51      * @return this content type's base type, or <code>null</code>
52      */

53     public IContentType getBaseType();
54
55     /**
56      * Returns the default content description for this content type. A default
57      * content description is returned by the content type API whenever
58      * content analysis could not find any particular information to be described
59      * about the contents being processed, so all default attributes for the
60      * content type in question apply.
61      * <p>
62      * Clients doing caching of content descriptions may choose to treat default
63      * descriptions in a special manner, since they are easily recoverable
64      * through this API.
65      * </p>
66      *
67      * @return a content description
68      * @since 3.1
69      */

70     public IContentDescription getDefaultDescription();
71
72     /**
73      * Tries to obtain a description for the given contents.
74      * <p>
75      * Any IOExceptions that may occur while reading the given input stream
76      * will flow to the caller. The input stream will not be closed by this
77      * operation.
78      * </p>
79      *
80      * @param contents the contents to be interpreted
81      * @param options an array of keys for all properties that should be described
82      * @return a content description if one could be obtained, or
83      * <code>null</code>
84      * @throws IOException if an error occurs while reading the contents
85      * @see IContentDescription
86      */

87     public IContentDescription getDescriptionFor(InputStream contents, QualifiedName[] options) throws IOException;
88
89     /**
90      * Tries to obtain a description for the given contents.
91      * <p>
92      * Any IOExceptions that may occur while reading the given reader
93      * will flow to the caller. The reader will not be closed by this
94      * operation.
95      * </p>
96      *
97      * @param contents the contents to be interpreted
98      * @param options an array of keys for all properties that should be described
99      * @return a content description if one could be obtained, or
100      * <code>null</code>
101      * @throws UnsupportedOperationException if this content type
102      * has a describer that does not implement
103      * <code>ITextContentDescriber</code>
104      * @throws IOException if an error occurs while reading the contents
105      * @see IContentDescription
106      */

107     public IContentDescription getDescriptionFor(Reader contents, QualifiedName[] options) throws IOException;
108
109     /**
110      * Returns the default charset for this content type if one has been defined,
111      * <code>null</code> otherwise.
112      * This refinement of the corresponding <code>IContentTypeSettings</code>
113      * method also takes into account the charset defined by the content type
114      * provider (or its base content type).
115      *
116      * @return the default charset, or <code>null</code>
117      */

118     public String JavaDoc getDefaultCharset();
119
120     /**
121      * Returns file specifications from this content type. The type mask
122      * is a bit-wise or of file specification type constants indicating the
123      * file specification types of interest.
124      * This refinement of the corresponding <code>IContentTypeSettings</code>
125      * method supports additional flags because it also takes into account the
126      * file specifications defined by the content type provider (or its base
127      * content type).
128      *
129      * @param type a bit-wise or of file specification type constants. Valid
130      * flags are:
131      *<ul>
132      *<li>one of <code>FILE_EXTENSION_SPEC</code> or
133      *<code>FILE_NAME_SPEC</code></li>
134      *<li>and optionally, one of <code>IGNORE_PRE_DEFINED</code>
135      *or <code>IGNORE_USER_DEFINED</code></li>
136      *</ul>
137      * @return the file specification
138      * @see #FILE_NAME_SPEC
139      * @see #FILE_EXTENSION_SPEC
140      * @see #IGNORE_PRE_DEFINED
141      * @see #IGNORE_USER_DEFINED
142      */

143     public String JavaDoc[] getFileSpecs(int type);
144
145     /**
146      * Returns this content type's unique identifier. Each content type has an
147      * identifier by which they can be retrieved from the content type catalog.
148      *
149      * @return this content type's unique identifier
150      */

151     public String JavaDoc getId();
152
153     /**
154      * Returns a user-friendly name for this content type.
155      *
156      * @return this content type's name
157      */

158     public String JavaDoc getName();
159
160     /**
161      * Returns whether this content type is associated with the
162      * given file name.
163      *
164      * @param fileName the file name
165      * @return <code>true</code> if this content type is associated with
166      * the given file name, <code>false</code> otherwise
167      * @see #isAssociatedWith(String, IScopeContext)
168      */

169     public boolean isAssociatedWith(String JavaDoc fileName);
170
171     /**
172      * Returns whether this content type is associated with the
173      * given file name in the given preference scope.
174      *
175      * @param fileName the file name
176      * @param context a preference scope context
177      * @return <code>true</code> if this content type is associated with
178      * the given file name, <code>false</code> otherwise
179      * @since 3.1
180      */

181     public boolean isAssociatedWith(String JavaDoc fileName, IScopeContext context);
182
183     /**
184      * Returns whether this content type is a kind of the given content
185      * type. A content type A is a kind of a content type B if:
186      * <ol>
187      * <li>A and B are the same content type, or</li>
188      * <li>A's base type is B, or</li>
189      * <li>A's base type is a kind of B.</li>
190      * </ol>
191      *
192      * @param another a content type
193      * @return <code>true</code> if this content type is a kind of the
194      * given content type, <code>false</code> otherwise
195      */

196     public boolean isKindOf(IContentType another);
197
198     /**
199      * Returns the settings for this content type in the given
200      * preference context.
201      *
202      * @param context a preference scope context
203      * @return setting in the given context
204      * @throws CoreException if this method fails. Reasons include:
205      * <ul>
206      * <li> An error occurred obtaining the settings.</li>
207      * </ul>
208      * @since 3.1
209      */

210     public IContentTypeSettings getSettings(IScopeContext context) throws CoreException;
211 }
212
Popular Tags