001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.language.markup.xsp;
018:
019: import org.apache.cocoon.Constants;
020: import org.apache.cocoon.environment.Response;
021: import org.xml.sax.ContentHandler;
022: import org.xml.sax.SAXException;
023:
024: import java.text.DateFormat;
025: import java.text.ParseException;
026: import java.text.SimpleDateFormat;
027: import java.util.Date;
028: import java.util.Locale;
029:
030: /**
031: * The XSP <code>Response</code> object helper
032: *
033: * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
034: * @version CVS $Id: XSPResponseHelper.java 433543 2006-08-22 06:22:54Z crossley $
035: */
036: public class XSPResponseHelper {
037: /**
038: * Assign values to the object's namespace uri and prefix
039: */
040: private static final String URI = Constants.XSP_RESPONSE_URI;
041: private static final String PREFIX = Constants.XSP_RESPONSE_PREFIX;
042:
043: public static void getLocale(Response response,
044: ContentHandler handler) throws SAXException {
045: Locale locale = response.getLocale();
046: XSPObjectHelper.start(URI, PREFIX, handler, "locale");
047:
048: XSPObjectHelper.elementData(URI, PREFIX, handler, "language",
049: locale.getLanguage());
050: XSPObjectHelper.elementData(URI, PREFIX, handler, "country",
051: locale.getCountry());
052: XSPObjectHelper.elementData(URI, PREFIX, handler, "variant",
053: locale.getVariant());
054:
055: XSPObjectHelper.end(URI, PREFIX, handler, "locale");
056: }
057:
058: public static void addDateHeader(Response response, String name,
059: long date) {
060: response.addDateHeader(name, date);
061: }
062:
063: public static void addDateHeader(Response response, String name,
064: Date date) {
065: response.addDateHeader(name, date.getTime());
066: }
067:
068: public static void addDateHeader(Response response, String name,
069: String date) throws ParseException {
070: addDateHeader(response, name, date, DateFormat
071: .getDateInstance());
072: }
073:
074: public static void addDateHeader(Response response, String name,
075: String date, String format) throws ParseException {
076: addDateHeader(response, name, date,
077: new SimpleDateFormat(format));
078: }
079:
080: public static void addDateHeader(Response response, String name,
081: String date, DateFormat format) throws ParseException {
082: response.addDateHeader(name, format.parse(date).getTime());
083: }
084:
085: public static void setDateHeader(Response response, String name,
086: long date) {
087: response.setDateHeader(name, date);
088: }
089:
090: public static void setDateHeader(Response response, String name,
091: Date date) {
092: response.setDateHeader(name, date.getTime());
093: }
094:
095: public static void setDateHeader(Response response, String name,
096: String date) throws ParseException {
097: setDateHeader(response, name, date, DateFormat
098: .getDateInstance());
099: }
100:
101: public static void setDateHeader(Response response, String name,
102: String date, String format) throws ParseException {
103: setDateHeader(response, name, date,
104: new SimpleDateFormat(format));
105: }
106:
107: public static void setDateHeader(Response response, String name,
108: String date, DateFormat format) throws ParseException {
109: response.setDateHeader(name, format.parse(date).getTime());
110: }
111: }
|