My favorites | Sign in
Project Home Downloads Source
Repository:
Checkout   Browse   Changes   Clones    
 
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
/*
* Copyright (c) 2012 Google Inc.
*
* All rights reserved. This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.google.eclipse.xtext.filename.resource;

import static com.google.eclipse.xtext.filename.resource.URIs.isMyDslFile;
import static org.eclipse.emf.ecore.resource.ContentHandler.Validity.VALID;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.impl.ContentHandlerImpl;

/**
* Object that provides content description for the input streams associated to URIs that refer to
* "MyDsl" files.
*
* @author alruiz@google.com (Alex Ruiz)
*/
public class MyDslContentHandler extends ContentHandlerImpl {

/** Content type for "MyDsl" files. */
public static final String MY_DSL_FILE_CONTENT_TYPE = "com.google.eclipse.MyDsl";

/**
* Indicates that this content handler can only handle URIs that belong to a "MyDsl" files.
* @param uri the URI to check. It may be {@code null}.
* @return {@code true} if the given URI belongs to a "MyDsl" file; {@code false} otherwise.
*/
@Override public boolean canHandle(URI uri) {
return isMyDslFile(uri);
}

/**
* Returns a map of properties that describe the content of the given URI's corresponding input
* stream. If the given URI refers to a "MyDsl" file, this method will mark the contents as valid
* and it will assign the content type appropiately.
* @param uri the URI for which to determine the content description.
* @param inputStream the {@code InputStream} associated with the given URI.
* @param options direct what kind of description is needed.
* @param context contextual information that content handlers use to store partially computed
* results.
* @return a map of properties that describe the content of the given URI's corresponding input
* stream.
* @throws IOException if there is a problem reading the stream.
*/
@Override public Map<String, Object> contentDescription(URI uri, InputStream inputStream,
Map<?, ?> options, Map<Object, Object> context) throws IOException {
Map<String, Object> description = super.contentDescription(uri, inputStream, options, context);
if (canHandle(uri)) {
description.put(VALIDITY_PROPERTY, VALID);
description.put(CONTENT_TYPE_PROPERTY, MY_DSL_FILE_CONTENT_TYPE);
}
return description;
}
}

Change log

ba3910eee250 by Alex Ruiz <alr...@google.com> on Jan 10, 2012   Diff
Formatting.
Go to: 
Project members, sign in to write a code review

Older revisions

46a03995f280 by Alex Ruiz <alr...@google.com> on Jan 7, 2012   Diff
Initial upload.
All revisions of this file

File info

Size: 2595 bytes, 63 lines
Powered by Google Project Hosting