001/** 002 * Copyright (c) 2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: tao $' 006 * '$Date: 2010-06-03 16:45:10 -0700 (Thu, 03 Jun 2010) $' 007 * '$Revision: 24730 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029package org.kepler.workflowscheduler.gui; 030 031import java.util.Vector; 032 033import org.apache.commons.logging.Log; 034import org.apache.commons.logging.LogFactory; 035import org.xml.sax.Attributes; 036import org.xml.sax.SAXException; 037import org.xml.sax.helpers.DefaultHandler; 038 039/** 040 * A parser which parses the result xml from remote scheduler server to 041 * get available time zone ids. 042 * @author tao 043 * 044 */ 045public class ServerTimeZoneIDParser extends DefaultHandler 046{ 047 private static final Log log = LogFactory.getLog(ServerTimeZoneIDParser.class.getName()); 048 private static final String ID = "id"; 049 private static final String AVAILABLETIMEZONEIDS = "availableTimeZoneIDs"; 050 private StringBuffer textBuffer = null; 051 private Vector<String> availableTimeZoneIDs = null; 052 053 /** 054 * Constructor 055 */ 056 public ServerTimeZoneIDParser() 057 { 058 availableTimeZoneIDs = new Vector<String>(); 059 } 060 061 /** SAX Handler that is called at the start of each XML element */ 062 public void startElement(String uri, String localName, String qName, 063 Attributes atts) throws SAXException 064 { 065 066 textBuffer = null; 067 textBuffer = new StringBuffer(); 068 } 069 070 /** SAX Handler that is called for each XML text node */ 071 public void characters(char[] cbuf, int start, int len) throws SAXException 072 { 073 textBuffer.append(new String(cbuf, start, len)); 074 } 075 076 /** SAX Handler that is called at the end of each XML element */ 077 public void endElement(String uri, String localName, String qName) 078 throws SAXException 079 { 080 081 String nodeValue = textBuffer.toString().trim(); 082 //System.out.println("the node value"); 083 //status 084 if(localName != null && localName.equals(ID) ) 085 { 086 if(nodeValue != null && !nodeValue.equals("")) 087 { 088 //System.out.println("add the id "+nodeValue); 089 availableTimeZoneIDs.add(nodeValue); 090 } 091 } 092 textBuffer = null; 093 textBuffer = new StringBuffer(); 094 } 095 096 /** 097 * Get the ids from the server response 098 * @return 099 */ 100 public Vector<String> getValaibleTimeZoneIDs() 101 { 102 return availableTimeZoneIDs; 103 } 104 105}