Package net.datacrow.core.web

Source Code of net.datacrow.core.web.WebUtilities

package net.datacrow.core.web;


import net.datacrow.core.DcRepository;
import net.datacrow.core.objects.DcField;
import net.datacrow.core.objects.DcObject;
import net.datacrow.core.objects.Picture;
import net.datacrow.core.web.model.DcWebField;
import net.datacrow.settings.definitions.WebFieldDefinition;
import net.datacrow.util.StringUtils;

/**
* @author rwaals
*/
public abstract class WebUtilities {
   
    public static String getValue(DcObject dco, DcWebField wf, Object value) {
        return getValue(dco, wf.getIndex(), wf.getMaxTextLength(), value);
    }

    public static String getValue(DcObject dco, WebFieldDefinition def, Object value) {
        return getValue(dco, def.getField(), def.getMaxTextLength(), value);
    }

    private static String getValue(DcObject dco, int fieldIdx, int maxTextLength, Object value) {
        DcField field = dco.getField(fieldIdx);
        String s = "";
        s = value != null && field.getValueType() == DcRepository.ValueTypes._PICTURE ?
                    "/mediaimages/" + ((Picture) value).getScaledFilename() :
                    dco.getDisplayString(field.getIndex());

        if (maxTextLength != 0 && field.getValueType() != DcRepository.ValueTypes._PICTURE)
            s = StringUtils.concatUserFriendly(s, maxTextLength);
       
        return s;
    }
}
TOP

Related Classes of net.datacrow.core.web.WebUtilities

TOP
Copyright © 2018 www.massapi.com. 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.