Setting the Mashup Response Character Encoding
There are two aspects involved in setting the character encoding for the mashup response:
Setting the HTTP Content Type Header in the Response
To add the HTTP header for content type to the response, simply declare a variable in the mashup script with the appropriate name and value. For example:
<variables>
<variable name="httpResponse.Content-Type" type="string"
default="text/html; charset=ISO-8859-1"/>
</variables>
See Adding HTTP Headers to the Mashup Result for the full details.
Setting the Character Encoding in the Response XML Declaration
If the response is generally going to be returned in an XML format, the XML declaration <?xml version="1.0"?> in the response also has an optional encoding property. Currently, your cannot set the XML declaration encoding property directly in EMML.
The work around is to define a custom XPath function to set the character encoding. See Defining Custom XPath Functions for instructions on writing custom XPath and registering them in the EMML Reference Runtime Engine.
An example of a custom XPath function to set the character encoding is shown below:
package com.mycompany.mashups;
import org.oma.emml.client.EMMLUserFunction;
public class CustomFunctions extends EMMLUserFunction {
public static String ChangeDocEncoding(Document doc, String encoding) throws Exception {
DOMSource domSrc = new DOMSource(doc.getDocumentElement());
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.setOutputProperty(OutputKeys.ENCODING, encoding);
t.transform(domSrc, result);
return writer.toString();
}
}
Once you have added the custom function to the EMML Engine, you can use it in mashups. For example:
Enterprise Mashup Markup Language (EMML) Documentation is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
