KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > language > markup > xsp > XSPResponseHelper


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
21 import org.xml.sax.SAXException JavaDoc;
22
23 import java.text.DateFormat JavaDoc;
24 import java.text.ParseException JavaDoc;
25 import java.text.SimpleDateFormat JavaDoc;
26 import java.util.Date JavaDoc;
27 import java.util.Locale JavaDoc;
28
29 /**
30  * The XSP <code>Response</code> object helper
31  *
32  * @author <a HREF="mailto:ricardo@apache.org">Ricardo Rocha</a>
33  * @version CVS $Id: XSPResponseHelper.java 30932 2004-07-29 17:35:38Z vgritsenko $
34  */

35 public class XSPResponseHelper {
36     /**
37      * Assign values to the object's namespace uri and prefix
38      */

39     private static final String JavaDoc URI = Constants.XSP_RESPONSE_URI;
40     private static final String JavaDoc PREFIX = Constants.XSP_RESPONSE_PREFIX;
41
42     public static void getLocale(Response response, ContentHandler JavaDoc handler)
43             throws SAXException JavaDoc {
44         Locale JavaDoc 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 JavaDoc name, long date) {
58         response.addDateHeader(name, date);
59     }
60
61     public static void addDateHeader(Response response, String JavaDoc name, Date JavaDoc date) {
62         response.addDateHeader(name, date.getTime());
63     }
64
65     public static void addDateHeader(Response response, String JavaDoc name, String JavaDoc date) throws ParseException JavaDoc {
66         addDateHeader(response, name, date, DateFormat.getDateInstance());
67     }
68
69     public static void addDateHeader(Response response, String JavaDoc name, String JavaDoc date, String JavaDoc format) throws ParseException JavaDoc {
70         addDateHeader(response, name, date, new SimpleDateFormat JavaDoc(format));
71     }
72
73     public static void addDateHeader(Response response, String JavaDoc name, String JavaDoc date, DateFormat JavaDoc format) throws ParseException JavaDoc {
74         response.addDateHeader(name, format.parse(date).getTime());
75     }
76
77     public static void setDateHeader(Response response, String JavaDoc name, long date) {
78       response.setDateHeader(name, date);
79     }
80
81     public static void setDateHeader(Response response, String JavaDoc name, Date JavaDoc date) {
82       response.setDateHeader(name, date.getTime());
83     }
84
85     public static void setDateHeader(Response response, String JavaDoc name, String JavaDoc date) throws ParseException JavaDoc {
86       setDateHeader(response, name, date, DateFormat.getDateInstance());
87     }
88
89     public static void setDateHeader(Response response, String JavaDoc name, String JavaDoc date, String JavaDoc format) throws ParseException JavaDoc {
90       setDateHeader(response, name, date, new SimpleDateFormat JavaDoc(format));
91     }
92
93     public static void setDateHeader(Response response, String JavaDoc name, String JavaDoc date, DateFormat JavaDoc format) throws ParseException JavaDoc {
94       response.setDateHeader(name, format.parse(date).getTime());
95     }
96 }
97
Popular Tags