public String generateTextData(Text text, String data) { if (data == null) return null; if (text == null) return null; TextImpl impl = (TextImpl) text; if (impl.isJSPContent() || impl.isCDATAContent()) { return new SourceValidator(impl).convertSource(data); } String source = data; // convert special characters to character entities StringBuffer buffer = null; int offset = 0; int length = data.length(); for (int i = 0; i < length; i++) { String name = getCharName(data.charAt(i)); if (name == null) continue; if (buffer == null) buffer = new StringBuffer(length + 8); if (i > offset) buffer.append(data.substring(offset, i)); buffer.append('&'); buffer.append(name); buffer.append(';'); offset = i + 1; } if (buffer != null) { if (length > offset) buffer.append(data.substring(offset)); source = buffer.toString(); } if (source == null || source.length() == 0) return null; return source; }
/** * generateText method * * @return java.lang.String * @param text org.w3c.dom.Text */ public String generateText(Text text) { if (text == null) return null; TextImpl impl = (TextImpl) text; String source = impl.getTextSource(); if (source != null) return source; return generateTextData(text, impl.getData()); }