1 16 package org.apache.cocoon.components.language.markup.xsp; 17 18 import org.apache.cocoon.Constants; 19 import org.apache.cocoon.environment.Response; 20 import org.xml.sax.ContentHandler ; 21 import org.xml.sax.SAXException ; 22 23 import java.text.DateFormat ; 24 import java.text.ParseException ; 25 import java.text.SimpleDateFormat ; 26 import java.util.Date ; 27 import java.util.Locale ; 28 29 35 public class XSPResponseHelper { 36 39 private static final String URI = Constants.XSP_RESPONSE_URI; 40 private static final String PREFIX = Constants.XSP_RESPONSE_PREFIX; 41 42 public static void getLocale(Response response, ContentHandler handler) 43 throws SAXException { 44 Locale locale = response.getLocale(); 45 XSPObjectHelper.start(URI, PREFIX, handler, "locale"); 46 47 XSPObjectHelper.elementData(URI, PREFIX, handler, "language", 48 locale.getLanguage()); 49 XSPObjectHelper.elementData(URI, PREFIX, handler, "country", 50 locale.getCountry()); 51 XSPObjectHelper.elementData(URI, PREFIX, handler, "variant", 52 locale.getVariant()); 53 54 XSPObjectHelper.end(URI, PREFIX, handler, "locale"); 55 } 56 57 public static void addDateHeader(Response response, String name, long date) { 58 response.addDateHeader(name, date); 59 } 60 61 public static void addDateHeader(Response response, String name, Date date) { 62 response.addDateHeader(name, date.getTime()); 63 } 64 65 public static void addDateHeader(Response response, String name, String date) throws ParseException { 66 addDateHeader(response, name, date, DateFormat.getDateInstance()); 67 } 68 69 public static void addDateHeader(Response response, String name, String date, String format) throws ParseException { 70 addDateHeader(response, name, date, new SimpleDateFormat (format)); 71 } 72 73 public static void addDateHeader(Response response, String name, String date, DateFormat format) throws ParseException { 74 response.addDateHeader(name, format.parse(date).getTime()); 75 } 76 77 public static void setDateHeader(Response response, String name, long date) { 78 response.setDateHeader(name, date); 79 } 80 81 public static void setDateHeader(Response response, String name, Date date) { 82 response.setDateHeader(name, date.getTime()); 83 } 84 85 public static void setDateHeader(Response response, String name, String date) throws ParseException { 86 setDateHeader(response, name, date, DateFormat.getDateInstance()); 87 } 88 89 public static void setDateHeader(Response response, String name, String date, String format) throws ParseException { 90 setDateHeader(response, name, date, new SimpleDateFormat (format)); 91 } 92 93 public static void setDateHeader(Response response, String name, String date, DateFormat format) throws ParseException { 94 response.setDateHeader(name, format.parse(date).getTime()); 95 } 96 } 97 | Popular Tags |