All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.centit.support.network.HtmlFormUtils Maven / Gradle / Ivy

There is a newer version: 5.3.2302
Show newest version
package com.centit.support.network;

import java.util.Collection;

import org.apache.commons.lang3.StringEscapeUtils;

@SuppressWarnings("unused")
public abstract class HtmlFormUtils {
    private HtmlFormUtils() {
        throw new IllegalAccessError("Utility class");
    }
    /**
     * 请调用直接 org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4
     * 或者 org.springframework.web.util.HtmlUtils.htmlEscape
     * @param value 文本
     * @return  html文本
     */
    public static String htmlValue(String value) {
        return StringEscapeUtils.escapeHtml4(value);
 /*          if (value == null) {
               return null;
           }        
           StringBuffer result = new StringBuffer(value.length());
           for (int i=0; i': 
                   result.append(">");
                   break;
               case '"': 
                   result.append(""");
                   break;
               case '\'': 
                   result.append("'");
                   break;
               case '%': 
                   result.append("%");
                   break;
               case ';': 
                   result.append(";");
                   break;
               case '(': 
                   result.append("(");
                   break;
               case ')': 
                   result.append(")");
                   break;
               case '&': 
                   result.append("&");
                   break;
               case '+':
                   result.append("+");
                   break;
               default:
                   result.append(value.charAt(i));
                   break;
               }
           }
           return result.toString();
      */
    }
    /**
     * 直接 org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4
     * 或者调用 org.springframework.web.util.HtmlUtils.htmlUnescape
     * @param value html文本
     * @return 文本
     */
    public static String htmlString(String value) { 
       return StringEscapeUtils.unescapeHtml4(value);
        /*if (value == null) {
            return null;
        }        
         return value.replaceAll("<", "<").replaceAll(">", ">")
                 .replaceAll(""", "\"").replaceAll("'", "'")
                 .replaceAll("&", "&");*/
   }     
    
    public static String[] htmlValue(String[] strArr) { 
        if(strArr==null || strArr.length==0)
            return null;
        String  resStrArr[] = new String[strArr.length];
         for(int i=0;i0){
                for(int i=0;i0)
                        sb.append(',');
                    sb.append(strArr[i]);
                }
                return sb.toString();
            }else{
              return null;
            }
        }else if(v instanceof Collection){
            @SuppressWarnings("unchecked")
            Collection objArr = (Collection) v;
            StringBuilder sb = new StringBuilder();
            int i=0;
            for(Object obj:objArr){
                if(i>0)
                    sb.append(',');
                sb.append(obj.toString());
                i++;
            }
            return  sb.toString();
        }else if(v instanceof String){
            return (String) v;
        }else{
            return v.toString();
        }
    }

    public static String[] getParameterStringArray(Object v) {
        if(v==null){
            return null;
        }else if(v instanceof String[]){
            String []strArr=(String[]) v;
            if(strArr.length>0){
              return  strArr;
            }else{
              return null;
            }
        }else if(v instanceof Object[]){
            Object[] objArr = (Object[]) v;
            if(objArr.length>0){
                String []strArr= new String [objArr.length];
                for(int i=0;i){
            @SuppressWarnings("unchecked")
            Collection objArr = (Collection) v;
            String []strArr= new String [objArr.size()];
            int i=0;
            for(Object obj:objArr){
                strArr[i++]= obj.toString();
            }
            return  strArr;
        }else if(v instanceof String){
            return new String[]{(String) v};
        }else{
            return new String[]{v.toString()};
        }
    }
}