FieldDescription.java 3.62 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceUtil
 *  org.apache.sling.api.resource.ValueMap
 */
package com.day.cq.wcm.foundation.forms;

import com.day.cq.wcm.foundation.forms.impl.FormsUtil;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;

public class FieldDescription {
    private String name;
    private boolean required = false;
    private String requiredMsg;
    private String constraintType;
    private String constraintMsg;
    private boolean readOnly = false;
    private boolean privateField = false;
    private boolean multiValue = false;
    private final Resource fieldResource;

    public FieldDescription(Resource rsrc) {
        this.fieldResource = rsrc;
    }

    public FieldDescription(Resource rsrc, String name) {
        this.fieldResource = rsrc;
        this.name = name;
    }

    public void update(Resource rsrc) {
        ValueMap props = ResourceUtil.getValueMap((Resource)rsrc);
        this.required = (Boolean)props.get("required", (Object)Boolean.FALSE);
        this.readOnly = (Boolean)props.get("readOnly", (Object)Boolean.FALSE);
        String name = (String)props.get("name", (Object)"");
        if (name.length() == 0) {
            name = ResourceUtil.getName((Resource)rsrc);
            name = FormsUtil.filterElementName(name);
        }
        this.name = name;
        String msg = (String)props.get("requiredMessage", (Object)"");
        if (msg.length() == 0) {
            msg = "This field is required";
        }
        this.requiredMsg = msg;
        String constraint = (String)props.get("constraintType", (Object)"");
        if (constraint.length() > 0) {
            if (constraint.indexOf(47) == -1) {
                constraint = "foundation/components/form/constraints/" + constraint;
            }
        } else {
            constraint = null;
        }
        this.constraintType = constraint;
        msg = (String)props.get("constraintMessage", (Object)"");
        if (msg.length() == 0) {
            msg = null;
        }
        this.constraintMsg = msg;
    }

    public Resource getFieldResource() {
        return this.fieldResource;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isRequired() {
        return this.required;
    }

    public void setRequired(boolean required) {
        this.required = required;
    }

    public String getRequiredMessage() {
        return this.requiredMsg;
    }

    public void setRequiredMessage(String requiredMsg) {
        this.requiredMsg = requiredMsg;
    }

    public String getConstraintType() {
        return this.constraintType;
    }

    public void setConstraintType(String constraintType) {
        this.constraintType = constraintType;
    }

    public String getConstraintMessage() {
        return this.constraintMsg;
    }

    public void setConstraintMessage(String constraintMsg) {
        this.constraintMsg = constraintMsg;
    }

    public boolean isReadOnly() {
        return this.readOnly;
    }

    public void setReadOnly(boolean readOnly) {
        this.readOnly = readOnly;
    }

    public boolean isPrivate() {
        return this.privateField;
    }

    public void setPrivateField(boolean flag) {
        this.privateField = flag;
    }

    public boolean isMultiValue() {
        return this.multiValue;
    }

    public void setMultiValue(boolean flag) {
        this.multiValue = flag;
    }
}