Package org.auraframework.util.json

Examples of org.auraframework.util.json.JsonStreamReader$JsonEndOfStreamException


@SuppressWarnings("rawtypes")
public class StringToHashMapConverter implements Converter<String, HashMap> {

    @Override
    public HashMap<String, Object> convert(String value) {
        JsonStreamReader reader = new JsonStreamReader(value);
        try {
            reader.next();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return (HashMap<String, Object>) reader.getObject();
    }
View Full Code Here


    private List<ValidationError> validateJavascript(Source<?> source, DefType defType) throws IOException {
        String sourceUrl = source.getUrl().toString();
        String sourceCode = source.getContents() + ';';

        // check if needs to add "var actions=" line before '{' to prevent jslint parser errors
        JsonStreamReader jreader = new JsonStreamReader(sourceCode);
        jreader.setRecursiveReadEnabled(false);
        // skip comment and whitespace
        JsonConstant token = jreader.next();
        int lineOffset = 0;
        JavascriptProcessingError customError = null;
        if (token == JsonConstant.OBJECT_START) {
            // fix, but report a ValidationError also
            int charNum = jreader.getCharNum();
            sourceCode = "var actions=\n" + sourceCode.substring(charNum - 1);
            //
            // We do some fancy footwork here to get the line number right.
            // (1) we take off 1 to remove the (first line = 1) from the reader.
            // (2) we take off 1 for the '\n' just above in the fixup.
            // (3) we add back two when creating the error to make the line correct
            //     here while having the line offset adjusted correctly.
            // A little confusing, but it does do the right thing.
            //
            lineOffset = jreader.getLineNum() - 2;
            customError = new JavascriptProcessingError("Starting '(' missing", lineOffset + 2, 1,
                    sourceUrl,
                    null, Level.Error);
        }
View Full Code Here

        builder.setOwnHash(source.getHash());
        builder.setLocation(getLocation());
    }

    public T getDefinition() {
        JsonStreamReader in = null;
        Map<String, Object> map = null;
        String contents = source.getContents();

        try {
            in = new JsonStreamReader(new StringReader(contents), getHandlerProvider());
            try {
                JsonConstant token = in.next();
                if (token == JsonConstant.FUNCTION_ARGS_START) {
                    in.next();
                }
                map = in.getObject();
            } finally {
                try {
                    in.close();
                } catch (IOException e) {
                    // We are in a very confusing state here, don't throw an exception.
                    // Either we've already had an exception, in which case we have
                    // more information there, or we successfully finished, in which
                    // case it is rather unclear how this could happen.
View Full Code Here

    }

    // json-ify the js so we can have basic validation and ensure well-formed output
    @Override
    public IncludeDef getDefinition() {
        JsonStreamReader in = null;
        String contents = "function(){" + source.getContents() + "\n}";
        String code = null;
        in = new JsonStreamReader(new StringReader(contents), getHandlerProvider());
        try {
            in.next();
            JsFunction function = (JsFunction) in.getValue();
            code = function.getBody();
        } catch (JsonParseException pe) {
            // EVIL: JsonStreamReader doesn't handle js regex during parse, so we can end up here unexpectedly
            // TODO: will have to find better impl to sanitize and validate library content
            // until then, at least strip out multi-line comments
            code = source.getContents();
            code = code.trim().replaceAll("(?s)/\\*.*?\\*/", "");
        } catch (IOException ioe) {
            return createDefinition(new AuraRuntimeException(ioe, getLocation()));
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                // We are in a very confusing state here, don't throw an exception. Either we've already had an
                // exception, in which case we have more information there, or we successfully finished, in which case
                // it is rather unclear how this could happen.
            }
View Full Code Here

        return body;
    }

    @SuppressWarnings("unchecked")
    private Object serializeAndReadAttributeFromDef(T def, String property) throws Exception {
        JsonStreamReader jsonStreamReader = new JsonStreamReader(Json.serialize(def));
        jsonStreamReader.next();
        Object temp = jsonStreamReader.getValue();
        assertTrue(temp instanceof Map);
        Map<Object, Object> cmpConfig = (HashMap<Object, Object>) temp;
        return cmpConfig.containsKey(property) ? cmpConfig.get(property) : null;
    }
View Full Code Here

        Reader reader = null;
        try {
            try {

                reader = new InputStreamReader(resourceLoader.getResourceAsStream("jsdoc/symbolSet.json"));
                JsonStreamReader jsonReader = new JsonStreamReader(reader);
                jsonReader.disableLengthLimitsBecauseIAmStreamingAndMyMemoryUseIsNotProportionalToTheStreamLength();
                jsonReader.next();
                List<Object> readSymbols = jsonReader.getList();
                symbols = Maps.newTreeMap();
                List<Map<String, Object>> classes = new ArrayList<Map<String, Object>>();
                for (Object symbol : readSymbols) {
                    Map<String, Object> map = (Map<String, Object>) symbol;
                    if (!map.containsKey("access")) {
View Full Code Here

TOP

Related Classes of org.auraframework.util.json.JsonStreamReader$JsonEndOfStreamException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.