package org.crosswire.xml; /** * Copyright (c) 2001 CrossWire Bible Society. * Distributable under the terms of the GNU GPL V2. */ import java.sql.Timestamp; /** This object defines a filter criteria for gaining a set of XMLObjects * @version $Id: SimpleMetaData.java,v 1.3.2.8 2001/12/31 01:57:25 troy Exp $ */ public class SimpleMetaData implements java.io.Serializable, java.lang.Cloneable, XMLMetaData { private static String dateFormat = "EEE MMM dd HH:mm:ss z yyyy"; private java.text.SimpleDateFormat dateFormatter = null; private String []strings = new String[5]; private java.sql.Timestamp []timeStamps = new Timestamp[3]; private Status status = new Status(); public Object clone() { SimpleMetaData retVal = null; try { retVal = (SimpleMetaData)super.clone(); retVal.strings = (String[])this.strings.clone(); retVal.timeStamps = (java.sql.Timestamp[])this.timeStamps.clone(); retVal.status = (Status)this.status.clone(); } catch (Exception e) {} return retVal; } /** A constructor which defaults all options to false. */ public SimpleMetaData() { } public SimpleMetaData(XMLMetaData absoluteMetaData) { this(); setKey(XMLMetaData.TYPE, absoluteMetaData.getKey(XMLMetaData.TYPE)); setKey(XMLMetaData.SUBTYPE, absoluteMetaData.getKey(XMLMetaData.SUBTYPE)); setKey(XMLMetaData.KEY1, absoluteMetaData.getKey(XMLMetaData.KEY1)); setKey(XMLMetaData.KEY2, absoluteMetaData.getKey(XMLMetaData.KEY2)); setKey(XMLMetaData.KEY3, absoluteMetaData.getKey(XMLMetaData.KEY3)); setTimeStamp(XMLMetaData.TSCREATE, absoluteMetaData.getTimeStamp(XMLMetaData.TSCREATE)); setTimeStamp(XMLMetaData.TSLASTMOD, absoluteMetaData.getTimeStamp(XMLMetaData.TSLASTMOD)); setTimeStamp(XMLMetaData.TSMISC, absoluteMetaData.getTimeStamp(XMLMetaData.TSMISC)); setStatus(absoluteMetaData.getStatus()); } public SimpleMetaData(String metaDataXML) throws XMLParseException { this(); dateFormatter = new java.text.SimpleDateFormat(dateFormat); XMLBlock inVal = new XMLBlock(metaDataXML); if (inVal.getValue("TYPE") != null) setKey(XMLMetaData.TYPE, inVal.getValue("TYPE")); if (inVal.getValue("SUBTYPE") != null) setKey(XMLMetaData.SUBTYPE, inVal.getValue("SUBTYPE")); if (inVal.getValue("KEY1") != null) setKey(XMLMetaData.KEY1, inVal.getValue("KEY1")); if (inVal.getValue("KEY2") != null) setKey(XMLMetaData.KEY2, inVal.getValue("KEY2")); if (inVal.getValue("KEY3") != null) setKey(XMLMetaData.KEY3, inVal.getValue("KEY3")); if (inVal.getValue("TSCREATE") != null) { java.text.ParsePosition pos = new java.text.ParsePosition(0); java.util.Date tmpDate = dateFormatter.parse(inVal.getValue("TSCREATE"), pos); setTimeStamp(XMLMetaData.TSCREATE, new java.sql.Timestamp(tmpDate.getTime())); } if (inVal.getValue("TSLASTMOD") != null) { java.text.ParsePosition pos = new java.text.ParsePosition(0); java.util.Date tmpDate = dateFormatter.parse(inVal.getValue("TSLASTMOD"), pos); setTimeStamp(XMLMetaData.TSLASTMOD, new java.sql.Timestamp(tmpDate.getTime())); } if (inVal.getValue("TSMISC") != null) { java.text.ParsePosition pos = new java.text.ParsePosition(0); java.util.Date tmpDate = dateFormatter.parse(inVal.getValue("TSMISC"), pos); setTimeStamp(XMLMetaData.TSMISC, new java.sql.Timestamp(tmpDate.getTime())); } if (inVal.getValue("STATUS") != null) setStatus(inVal.getValue("STATUS")); } public String toString() { XMLBlock retVal = null; if (dateFormatter == null) dateFormatter = new java.text.SimpleDateFormat(dateFormat); try { retVal = new XMLBlock(""); } catch (Exception exp) { // will never happen } if (getKey(XMLMetaData.TYPE) != null) retVal.setValue("TYPE", getKey(XMLMetaData.TYPE)); if (getKey(XMLMetaData.SUBTYPE) != null) retVal.setValue("SUBTYPE", getKey(XMLMetaData.SUBTYPE)); if (getKey(XMLMetaData.KEY1) != null) retVal.setValue("KEY1", getKey(XMLMetaData.KEY1)); if (getKey(XMLMetaData.KEY2) != null) retVal.setValue("KEY2", getKey(XMLMetaData.KEY2)); if (getKey(XMLMetaData.KEY3) != null) retVal.setValue("KEY3", getKey(XMLMetaData.KEY3)); if (getTimeStamp(XMLMetaData.TSCREATE) != null) retVal.setValue("TSCREATE", dateFormatter.format(new java.util.Date(getTimeStamp(XMLMetaData.TSCREATE).getTime()))); if (getTimeStamp(XMLMetaData.TSLASTMOD) != null) retVal.setValue("TSLASTMOD", dateFormatter.format(new java.util.Date(getTimeStamp(XMLMetaData.TSLASTMOD).getTime()))); if (getTimeStamp(XMLMetaData.TSMISC) != null) retVal.setValue("TSMISC", dateFormatter.format(new java.util.Date(getTimeStamp(XMLMetaData.TSMISC).getTime()))); if (getStatus() != null) retVal.setValue("STATUS", getStatus()); return retVal.toString(); } public XMLMetaData setObjectState(char value) { status.setState(value); return this; } public char getObjectState() { return status.getState(); } public XMLMetaData setKey(int keyConstant, String value) { keyConstant -= XMLMetaData.TYPE; if (keyConstant < strings.length) strings[keyConstant] = value; return this; } public String getKey(int keyConstant) { keyConstant -= XMLMetaData.TYPE; if (keyConstant < strings.length) return strings[keyConstant]; return null; } public XMLMetaData setTimeStamp(int keyConstant, Timestamp value) { keyConstant -= XMLMetaData.TSCREATE; if (keyConstant < timeStamps.length) timeStamps[keyConstant] = value; return this; } public Timestamp getTimeStamp(int keyConstant) { keyConstant -= XMLMetaData.TSCREATE; if (keyConstant < timeStamps.length) return timeStamps[keyConstant]; return null; } public String getStatusMask() { return status.getStatusMask(); } // for uniqueMetaData (NA are turned to OFF) public String getStatus() { return status.getStatusNoFilters(); } public long getStatusLong() { return status.getLong(); } public XMLMetaData setStatus(String statusString) { status.setStatus(statusString); return this; } public XMLMetaData setStatusMaskBit(int bit, char option) { status.setBit(bit, option); return this; } public XMLMetaData setStatusMask(long mask, char option) { status.setMaskVal(mask, option); return this; } }