1 16 package org.apache.cocoon.woody.util; 17 18 import org.apache.cocoon.transformation.I18nTransformer; 19 import org.apache.cocoon.woody.Constants; 20 import org.apache.cocoon.xml.AttributesImpl; 21 import org.apache.excalibur.xml.sax.XMLizable; 22 import org.xml.sax.ContentHandler ; 23 import org.xml.sax.SAXException ; 24 25 35 public class I18nMessage implements XMLizable { 36 private String key; 37 private String catalogue; 38 private String [] parameters; 39 private boolean[] keys; 40 41 44 public I18nMessage(String key) { 45 this(key, (String ) null); 46 } 47 48 52 public I18nMessage(String key, String catalogue) { 53 this.key = key; 54 this.catalogue = catalogue; 55 } 56 57 62 public I18nMessage(String key, String [] parameters) { 63 this(key, parameters, (String )null); 64 } 65 66 72 public I18nMessage(String key, String [] parameters, String catalogue) { 73 this.key = key; 74 this.parameters = parameters; 75 this.catalogue = catalogue; 76 } 77 78 85 public I18nMessage(String key, String [] parameters, boolean[] keys) { 86 this(key, parameters, keys, null); 87 } 88 89 97 public I18nMessage(String key, String [] parameters, boolean[] keys, String catalogue) { 98 this.key = key; 99 this.parameters = parameters; 100 this.keys = keys; 101 this.catalogue = catalogue; 102 } 103 104 public void toSAX(ContentHandler contentHandler) throws SAXException { 105 contentHandler.startPrefixMapping("i18n", I18nTransformer.I18N_NAMESPACE_URI); 106 if (parameters != null) { 107 contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TRANSLATE_ELEMENT, "i18n:" + I18nTransformer.I18N_TRANSLATE_ELEMENT, Constants.EMPTY_ATTRS); 108 } 109 110 AttributesImpl i18nAttrs = new AttributesImpl(); 111 if (catalogue != null) { 112 i18nAttrs.addCDATAAttribute(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_CATALOGUE_ATTRIBUTE, "i18n:" + I18nTransformer.I18N_CATALOGUE_ATTRIBUTE, catalogue); 113 } 114 115 contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT, i18nAttrs); 116 contentHandler.characters(key.toCharArray(), 0, key.length()); 117 contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT); 118 119 if (parameters != null) { 121 for (int i = 0; i < parameters.length; i++) { 122 contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_PARAM_ELEMENT, "i18n:" + I18nTransformer.I18N_PARAM_ELEMENT, Constants.EMPTY_ATTRS); 123 if (keys != null && keys[i]) 124 contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT, i18nAttrs); 125 contentHandler.characters(parameters[i].toCharArray(), 0, parameters[i].length()); 126 if (keys != null && keys[i]) 127 contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT); 128 contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_PARAM_ELEMENT, "i18n:" + I18nTransformer.I18N_PARAM_ELEMENT); 129 } 130 contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TRANSLATE_ELEMENT, "i18n:" + I18nTransformer.I18N_TRANSLATE_ELEMENT); 131 } 132 contentHandler.endPrefixMapping("i18n"); 133 } 134 } 135 | Popular Tags |