URLSpec.java 4.83 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.livecycle.formsservice.client;

import com.adobe.livecycle.formsservice.utils.FormsServiceClientUtils;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Set;
import java.util.StringTokenizer;

public class URLSpec
implements Serializable {
    private static final long serialVersionUID = 5457387861298923100L;
    private String applicationWebRoot = null;
    private String targetURL = null;
    private String contentRootURI = null;
    private String baseURL = null;
    protected static HashMap propertyMap = new HashMap(5);

    public URLSpec() {
    }

    public URLSpec(String optionsString) {
        this.updateOptionsBean(optionsString);
    }

    public URLSpec(String applicationWebRoot, String targetURL, String contentRootURI, String baseURL) {
        this.applicationWebRoot = applicationWebRoot;
        this.targetURL = targetURL;
        this.contentRootURI = contentRootURI;
        this.baseURL = baseURL;
    }

    public String getApplicationWebRoot() {
        return this.applicationWebRoot;
    }

    public void setApplicationWebRoot(String applicationWebRoot) {
        this.applicationWebRoot = applicationWebRoot;
    }

    public String getBaseURL() {
        return this.baseURL;
    }

    public void setBaseURL(String baseURL) {
        this.baseURL = baseURL;
    }

    public String getContentRootURI() {
        return this.contentRootURI;
    }

    public void setContentRootURI(String contentRootURI) {
        this.contentRootURI = contentRootURI;
    }

    public String getTargetURL() {
        return this.targetURL;
    }

    public void setTargetURL(String targetURL) {
        this.targetURL = targetURL;
    }

    public String getOptions() {
        StringBuffer optStr = new StringBuffer();
        for (String key : propertyMap.keySet()) {
            String val = this.getOption(key);
            if (val == null || val.trim().length() <= 0) continue;
            optStr.append(key).append("=").append(val).append("&");
        }
        if (optStr.length() > 1) {
            return optStr.substring(0, optStr.length() - 1);
        }
        return optStr.toString();
    }

    public String getOption(String key) {
        String paramVal = "";
        int propId = this.lookupProperty(key);
        switch (propId) {
            case 1: {
                paramVal = this.getApplicationWebRoot();
                break;
            }
            case 2: {
                paramVal = this.getTargetURL();
                break;
            }
            case 3: {
                paramVal = this.getContentRootURI();
                break;
            }
            case 4: {
                paramVal = this.getBaseURL();
            }
        }
        return this.decodeURL(paramVal);
    }

    public void updateOptionsBean(String key, String value) {
        int propId = this.lookupProperty(key);
        if (value != null && value.trim().length() == 0) {
            value = null;
        }
        switch (propId) {
            case 1: {
                this.setApplicationWebRoot(value);
                break;
            }
            case 2: {
                this.setTargetURL(value);
                break;
            }
            case 3: {
                this.setContentRootURI(value);
                break;
            }
            case 4: {
                this.setBaseURL(value);
            }
        }
    }

    public void updateOptionsBean(String options) {
        if (FormsServiceClientUtils.isEmptyOrNull(options) || options.indexOf("=") == -1) {
            return;
        }
        StringTokenizer inToks = new StringTokenizer(options, "&");
        while (inToks.hasMoreTokens()) {
            String tok = inToks.nextToken();
            int tokEqual = tok.indexOf("=");
            if (tokEqual < 0) continue;
            this.updateOptionsBean(tok.substring(0, tokEqual), tok.substring(tokEqual + 1));
        }
    }

    public String toString() {
        return this.getOptions();
    }

    private int lookupProperty(String key) {
        int propId = 0;
        if (!FormsServiceClientUtils.isEmptyOrNull(key) && propertyMap.containsKey(key = key.toLowerCase())) {
            propId = (Integer)propertyMap.get(key);
        }
        return propId;
    }

    private String decodeURL(String sURLEncoded) {
        if (sURLEncoded != null && sURLEncoded.indexOf(37) != -1) {
            byte[] cDecoded = FormsServiceClientUtils.URLDecode(sURLEncoded);
            sURLEncoded = new String(cDecoded);
        }
        return sURLEncoded;
    }

    static {
        propertyMap.put("applicationWebRoot".toLowerCase(), new Integer(1));
        propertyMap.put("targetURL".toLowerCase(), new Integer(2));
        propertyMap.put("contentRootURI".toLowerCase(), new Integer(3));
        propertyMap.put("baseURL".toLowerCase(), new Integer(4));
    }
}