| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.debugging.sourcemap; |
| 18 |
|
| 19 |
import org.json.JSONException; |
| 20 |
import org.json.JSONObject; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public class SourceMapConsumerFactory { |
| 27 |
|
| 28 |
|
| 29 |
private SourceMapConsumerFactory() {} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public static SourceMapping parse(String contents) |
| 37 |
throws SourceMapParseException { |
| 38 |
return parse(contents, null); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public static SourceMapping parse(String contents, SourceMapSupplier supplier) |
| 48 |
throws SourceMapParseException { |
| 49 |
|
| 50 |
if (contents.startsWith("/** Begin line maps. **/")) { |
| 51 |
SourceMapConsumerV1 consumer = new SourceMapConsumerV1(); |
| 52 |
consumer.parse(contents); |
| 53 |
return consumer; |
| 54 |
} else if (contents.startsWith("{")){ |
| 55 |
try { |
| 56 |
|
| 57 |
JSONObject sourceMapRoot = new JSONObject(contents); |
| 58 |
|
| 59 |
int version = sourceMapRoot.getInt("version"); |
| 60 |
switch (version) { |
| 61 |
case 2: { |
| 62 |
SourceMapConsumerV2 consumer = new SourceMapConsumerV2(); |
| 63 |
consumer.parse(sourceMapRoot); |
| 64 |
return consumer; |
| 65 |
} |
| 66 |
case 3: { |
| 67 |
SourceMapConsumerV3 consumer = new SourceMapConsumerV3(); |
| 68 |
consumer.parse(sourceMapRoot, supplier); |
| 69 |
return consumer; |
| 70 |
} |
| 71 |
default: |
| 72 |
throw new SourceMapParseException( |
| 73 |
"Unknown source map version:" + version); |
| 74 |
} |
| 75 |
} catch (JSONException ex) { |
| 76 |
throw new SourceMapParseException("JSON parse exception: " + ex); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
throw new SourceMapParseException("unable to detect source map format"); |
| 81 |
} |
| 82 |
} |