protected String validateEntities(String s) {
    	// validate entities throughout the string
        Pattern pattern = Pattern.compile("&([^&;]*)(?=(;|&|$))");
        Matcher matcher = pattern.matcher(s);
        if (matcher.find()) {
            String one = matcher.group(1); // ([^&;]*)
            String two = matcher.group(2); // (?=(;|&|$))
            s = checkEntity(one, two);
        }

        // validate quotes outside of tags
        pattern = Pattern.compile("(>|^)([^<]+?)(<|$)", Pattern.DOTALL);
        matcher = pattern.matcher(s);
        StringBuffer buf = new StringBuffer();
        if (matcher.find()) {
            String one = matcher.group(1); // (>|^)
            String two = matcher.group(2); // ([^<]+?)
            String three = matcher.group(3); // (<|$)
            matcher.appendReplacement(buf, one + two.replaceAll("\"", "&quot;")
                    + three);
        }
        matcher.appendTail(buf);
        return s;
    }