1 16 17 package org.apache.commons.betwixt.strategy; 18 19 import org.apache.commons.betwixt.ElementDescriptor; 20 import org.apache.commons.betwixt.XMLUtils; 21 22 34 public abstract class BaseMixedContentEncodingStrategy 35 extends MixedContentEncodingStrategy { 36 37 43 protected String escapeCharacters(String bodyContent) { 44 return XMLUtils.escapeBodyValue(bodyContent); 45 } 46 47 53 protected String encodeInCDATA(String bodyContent) { 54 StringBuffer buffer = new StringBuffer (bodyContent); 55 buffer.ensureCapacity(12); 56 XMLUtils.escapeCDATAContent(buffer); 57 return buffer.insert(0, "<![CDATA[").append("]]>").toString(); 58 } 59 60 68 public String encode(String bodyContent, ElementDescriptor element) { 69 if (encodeAsCDATA(element)) { 70 return encodeInCDATA(bodyContent); 71 } 72 73 return escapeCharacters(bodyContent); 74 } 75 76 90 protected abstract boolean encodeAsCDATA(ElementDescriptor element); 91 92 } 93 | Popular Tags |