001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id:$
023: *
024: */
025: package com.bostechcorp.cbesb.common.util.generators;
026:
027: import java.text.SimpleDateFormat;
028: import java.util.Date;
029: import java.util.HashMap;
030: import java.util.Iterator;
031: import java.util.Map.Entry;
032:
033: import org.jdom.Element;
034: import org.jdom.Namespace;
035:
036: /**
037: * @author LPS
038: * @deprecated
039: */
040: public class HolidayXMLGenerator extends AbstractDOMGenerator {
041:
042: private static final String HOLIDAY_SCHEDULE_T = "holidaySchedule";
043: private static final String HOLIDAY_T = "holiday";
044: private static final String DATE_T = "date";
045: private static final String DESCRIPTION_T = "description";
046:
047: private static final String HOLIDAY_SCHEDULE_NS = "http://cbesb.bostechcorp.com/scheduler/1.0";
048:
049: private String fileName = "";
050:
051: private String dateFormat = "yyyy-MM-dd";
052:
053: /**
054: * @param path
055: */
056: public HolidayXMLGenerator(String path, String fileName) {
057: super (path);
058: this .fileName = fileName;
059: }
060:
061: /* (non-Javadoc)
062: * @see com.bostechcorp.cbesb.common.util.AbstractDOMGenerator#buildDocumentStructure()
063: */
064: @Override
065: protected void buildDocumentStructure() {
066: rootElement = jdomFactory.element(HOLIDAY_SCHEDULE_T);
067: rootElement.setNamespace(Namespace
068: .getNamespace(HOLIDAY_SCHEDULE_NS));
069: }
070:
071: @SuppressWarnings("unchecked")
072: public void setHolidayListDateString(HashMap<Date, String> hList) {
073: SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
074: for (Iterator iter = hList.entrySet().iterator(); iter
075: .hasNext();) {
076: Entry<Date, String> element = (Entry<Date, String>) iter
077: .next();
078:
079: Element dateElement = jdomFactory.element(DATE_T);
080: dateElement.addContent(sdf.format(element.getKey()));
081:
082: Element descriptionElement = jdomFactory.element(
083: DESCRIPTION_T, rootElement.getNamespace());
084: descriptionElement.addContent(element.getValue());
085:
086: Element holidayElement = jdomFactory.element(HOLIDAY_T,
087: rootElement.getNamespace());
088: holidayElement.addContent(dateElement);
089: holidayElement.addContent(descriptionElement);
090: }
091: }
092:
093: @SuppressWarnings("unchecked")
094: public void setHolidayListStringString(HashMap<String, String> hList) {
095: for (Iterator iter = hList.entrySet().iterator(); iter
096: .hasNext();) {
097: Entry<String, String> element = (Entry<String, String>) iter
098: .next();
099:
100: Element dateElement = jdomFactory.element(DATE_T);
101: dateElement.addContent(element.getKey());
102:
103: Element descriptionElement = jdomFactory.element(
104: DESCRIPTION_T, rootElement.getNamespace());
105: descriptionElement.addContent(element.getValue());
106:
107: Element holidayElement = jdomFactory.element(HOLIDAY_T,
108: rootElement.getNamespace());
109: holidayElement.addContent(dateElement);
110: holidayElement.addContent(descriptionElement);
111: }
112: }
113:
114: public void setDateFormat(String df) {
115: dateFormat = df;
116: }
117:
118: /* (non-Javadoc)
119: * @see com.bostechcorp.cbesb.common.util.AbstractDOMGenerator#getFileOut()
120: */
121: @Override
122: protected String getFileOut() {
123: if (filePath.endsWith("/"))
124: return filePath + fileName;
125: return filePath + "/" + fileName;
126: }
127:
128: }
|