Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e8c63f69c182df37c51796179e8d9d86398baa34 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*******************************************************************************
 * Copyright (c) 2000, 2008 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.team.core;

import org.eclipse.core.resources.IStorage;

/**
 * This is the API to define mappings between file names, file extensions and
 * content types, typically used by repository providers in order to determine
 * whether a given file can be treated as text or must be considered binary.
 *
 * Mappings for names and extensions can either be contributed via an extension
 * point or via this interface.
 *
 * For methods that determine the content type for a given file, the following
 * rules apply:
 * <ul>
 * <li>Mappings for the entire file name take precedence over mappings for the
 * file extension only.</li>
 * <li>User-defined mappings take precedence over plugin-contributed mappings
 * </li>
 * </ul>
 *
 * If a mapping is added for a name or an extension that already has a mapping
 * which has been contributed by a plugin, it overrides the one contributed by
 * the plugin. If the user-defined mapping is deleted, the plugin-contributed
 * mapping is valid again. This interface is not intended to be implemented by
 * clients.
 *
 * @see org.eclipse.team.core.Team#getFileContentManager()
 *
 * @since 3.1
 * @noimplement This interface is not intended to be implemented by clients.
 */
public interface IFileContentManager {

    /**
     * Get the content type for a given instance of <code>IStorage</code>. User-defined mappings
     * take precedence over plugin-contributed mappings; further, mappings for the entire file name
     * take precedence over mappings for the file extension only.
     *
     * @param storage the instance of <code>IStorage</code>.
     * @return one of <code>Team.UNKNOWN</code>, <code>Team.TEXT</code> or <code>Team.BINARY</code>.
     *
     * @since 3.1
     */
    int getType(IStorage storage);

    /**
     * Check whether the given file name is assigned to a specific type in the content type registry.
     * @param filename the file name to check for
     * @return True if the file name is registered in the system and assigned to a content type, false
     * if the file name is unknown.
     *
     * @since 3.1
     */
    boolean isKnownFilename(String filename);

    /**
     * Check whether the given file extension is assigned to a specific type in the content type registry.
     * @param extension the extension to check for
     * @return True if the extension is registered in the system and assigned to a content type, false
     * if the extension is unknown.
     *
     * @since 3.1
     */
    boolean isKnownExtension(String extension);

    /**
     * Get the content type for a given file name.
     * @param filename The file name
     * @return one of <code>Team.UNKNOWN</code>, <code>Team.TEXT</code> or <code>Team.BINARY</code>.
     *
     * @since 3.1
     */
    int getTypeForName(String filename);

    /**
     * Get the content type for a given file extension.
     * @param extension The extension
     * @return one of <code>Team.UNKNOWN</code>, <code>Team.TEXT</code> or <code>Team.BINARY</code>.
     *
     * @since 3.1
     */
    int getTypeForExtension(String extension);

    /**
     * Map a set of file names to a set of content types and save the mappings in
     * the preferences. Already existing mappings for these file names are updated
     * with the new ones, other mappings will be preserved.
     *
     * @param names The file names
     * @param types The corresponding types, each one being one of
     *            <code>Team.UNKNOWN</code>,<code>Team.TEXT</code> or
     *            <code>Team.BINARY</code>.
     *
     * @since 3.1
     */
    void addNameMappings(String[] names, int[] types);

    /**
     * Map a set of file extensions to a set of content types and save the mapping in
     * the preferences. Already existing mappings for these extensions are updated
     * with the new ones, other mappings will be preserved.
     *
     * @param extensions The extensions
     * @param types The corresponding types, each one being one of
     *            <code>Team.UNKNOWN</code>,<code>Team.TEXT</code> or
     *            <code>Team.BINARY</code>.
     *
     * @since 3.1
     */
    void addExtensionMappings(String[] extensions, int[] types);

    /**
     * Map a set of file names to a set of content types and save the mappings in
     * the preferences. All existing user-defined mappings for <b>any
     * </b> file names are deleted and replaced by the new ones.
     *
     * @param names The file names
     * @param types The corresponding types, each one being one of
     *            <code>Team.UNKNOWN</code>,<code>Team.TEXT</code> or
     *            <code>Team.BINARY</code>.
     *
     * @since 3.1
     */
    void setNameMappings(String[] names, int[] types);

    /**
     * Map a set of file extensions to a set of content types and save the
     * mapping in the preferences. All existing user-defined mappings for <b>any
     * </b> file extensions are deleted and replaced by the new ones.
     *
     * @param extensions The extensions
     * @param types The corresponding types, each one being one of
     *            <code>Team.UNKNOWN</code>,<code>Team.TEXT</code> or
     *            <code>Team.BINARY</code>.
     *
     * @since 3.1
     */
    void setExtensionMappings(String[] extensions, int[] types);

    /**
     * Get all the currently defined mappings from file names to content types.
     *
     * @return the mappings
     *
     * @since 3.1
     */
    IStringMapping [] getNameMappings();

    /**
     * Get all the currently defined mappings from file names to content types.
     *
     * @return the mappings
     *
     * @since 3.1
     */
    IStringMapping [] getExtensionMappings();

    /**
     * Get all the plugin-contributed mappings from file names to content types.
     *
     * @return the mappings
     *
     * @since 3.1
     */
    IStringMapping [] getDefaultNameMappings();

    /**
     * Get all the plugin-contributed mappings from file extensions to content types.
     *
     * @return the mappings

     * @since 3.1
     */
    IStringMapping [] getDefaultExtensionMappings();
}

Back to the top