Android Open Source - Android-Data-Binding Parser






From Project

Back to project page Android-Data-Binding.

License

The source code is released under:

MIT License

If you think the Android project Android-Data-Binding listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.furkanbayraktar.databinding.common.parser;
//w  w  w  .  ja  va  2s.c  o m
import com.furkanbayraktar.databinding.exception.UnsupportedSyntaxError;
import com.furkanbayraktar.databinding.logging.Logger;

import java.util.HashMap;

/**
 * Created by Furkan Bayraktar.
 * Created at 8/15/14.
 *
 */
public class Parser {

    private static Parser instance;

    private Parser(){
        Logger.info("Parser object created.");
    }

    public static Parser getInstance(){
        if(instance == null){
            instance = new Parser();
        }
        return instance;
    }

    public HashMap<String, String> parse(String tag){

        try {
            Logger.info("Parsing tag...");

            HashMap<String, String> result = new HashMap<String, String>();

            Logger.info("Looking for assignable values...");

            int start = tag.indexOf("#ASSIGN");

            if (start != -1) {
                int start2 = tag.indexOf("{", start) + 1;
                int end = tag.indexOf("}", start2);

                if (end == -1) {
                    UnsupportedSyntaxError ex = new UnsupportedSyntaxError();
                    Logger.error("Unsupported syntax.", ex);
                }

                result.put("assign", tag.substring(start2, end));

                Logger.info("Assignable values found: " + result.get("assign"));
            }

            Logger.info("Looking for visibility values...");

            start = tag.indexOf("#VISIBLE");

            if (start != -1) {
                int start2 = tag.indexOf("{", start) + 1;
                int end = tag.indexOf("}", start2);

                if (end == -1) {
                    UnsupportedSyntaxError ex = new UnsupportedSyntaxError();
                    Logger.error("Unsupported syntax.", ex);
                }

                result.put("visible", tag.substring(start2, end));

                Logger.info("Visibility values found: " + result.get("visible"));
            }

            Logger.info("Looking for function arguments...");

            start = tag.indexOf("#FUNC");

            if (start != -1) {
                int start2 = tag.indexOf("{", start) + 1;
                int end = tag.indexOf("}", start2);

                if (end == -1) {
                    UnsupportedSyntaxError ex = new UnsupportedSyntaxError();
                    Logger.error("Unsupported syntax.", ex);
                }

                result.put("func", tag.substring(start2, end));

                Logger.info("Function arguments found: " + result.get("func"));
            }

            Logger.info("Parsing completed.");

            return result;
        }catch (Exception ex){
            Logger.error("Unexpected error.", ex);
        }
        return null;
    }

}




Java Source Code List

com.furkanbayraktar.databinding.ViewBinder.java
com.furkanbayraktar.databinding.annotations.BindedFunction.java
com.furkanbayraktar.databinding.common.adapter.BoundListAdapter.java
com.furkanbayraktar.databinding.common.external.Expression.java
com.furkanbayraktar.databinding.common.parser.ExpressionEvaluator.java
com.furkanbayraktar.databinding.common.parser.Parser.java
com.furkanbayraktar.databinding.common.resolver.AssignmentResolver.java
com.furkanbayraktar.databinding.common.resolver.FunctionResolver.java
com.furkanbayraktar.databinding.common.resolver.PathResolver.java
com.furkanbayraktar.databinding.common.resolver.ViewResolver.java
com.furkanbayraktar.databinding.common.resolver.VisibilityResolver.java
com.furkanbayraktar.databinding.exception.FunctionException.java
com.furkanbayraktar.databinding.exception.POJOParseException.java
com.furkanbayraktar.databinding.exception.ResolverException.java
com.furkanbayraktar.databinding.exception.UnsupportedObjectException.java
com.furkanbayraktar.databinding.exception.UnsupportedSyntaxError.java
com.furkanbayraktar.databinding.exception.UnsupportedViewException.java
com.furkanbayraktar.databinding.logging.Logger.java
com.furkanbayraktar.databinding.model.BasePOJO.java
com.furkanbayraktar.databindingprivate.app.ListActivity.java
com.furkanbayraktar.databindingprivate.app.MainActivity.java
com.furkanbayraktar.databindingprivate.app.model.news.Content.java
com.furkanbayraktar.databindingprivate.app.model.news.Entry.java
com.furkanbayraktar.databindingprivate.app.model.news.Feed.java
com.furkanbayraktar.databindingprivate.app.model.news.MediaGroup.java
com.furkanbayraktar.databindingprivate.app.model.news.ResponseData.java
com.furkanbayraktar.databindingprivate.app.model.news.ResponseObject.java
com.furkanbayraktar.databindingprivate.app.model.sample.SampleObject.java
com.furkanbayraktar.databindingprivate.app.network.GsonRequest.java