Check if a string needs CData wrapper - Java java.lang

Java examples for java.lang:String XML

Description

Check if a string needs CData wrapper

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String data = "java2s.com";
        System.out.println(needsCData(data));
    }/*from   w  w  w . j a  v  a2 s .c o  m*/

    public static boolean needsCData(String data) {
        boolean result = false;
        for (int x = 0; x < data.length(); x++) {
            char c = data.charAt(x);
            if (c == '>' || c == '<' || c == '&' || (int) c > 127) {
                result = true;
                break;
            }
        }
        return result;
    }

    public static int length(String source) {
        int result = 0;
        if (isNotEmpty(source)) {
            result = source.length();
        }
        return result;
    }

    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    public static boolean isEmpty(String str) {
        return (str == null || str.length() == 0);
    }
}

Related Tutorials