Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 90   Methods: 4
NCLOC: 48   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CreationDate.java 50% 72.2% 75% 69.2%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    */
 17   
 18    package org.apache.xindice.webadmin.webdav.components.props;
 19   
 20    import org.apache.xindice.core.Collection;
 21    import org.apache.xindice.core.DBException;
 22    import org.apache.xindice.core.data.Entry;
 23    import org.apache.xindice.core.meta.MetaData;
 24    import org.apache.xindice.webadmin.PartialResponse;
 25    import org.apache.commons.logging.Log;
 26    import org.apache.commons.logging.LogFactory;
 27   
 28    import java.util.Date;
 29    import java.util.Locale;
 30    import java.util.TimeZone;
 31    import java.text.SimpleDateFormat;
 32   
 33    /**
 34    * CreationDate creates a response node that contains the time when resource
 35    * was created in the format "yyyy-MM-dd'T'HH:mm:ss'Z'" if creation time is
 36    * available.<br/><br/>
 37    * See {@link java.text.SimpleDateFormat} for date format information.<br>
 38    * <br>
 39    * Example:
 40    * <pre>
 41    * &lt;creationdate&gt;
 42    * 2007-05-09T09:22:00Z
 43    * &lt;/creationdate&gt;
 44    * </pre>
 45    *
 46    * @version $Revision: 541515 $, $Date: 2007-05-24 19:45:06 -0700 (Thu, 24 May 2007) $
 47    */
 48    public class CreationDate implements DAVProperty {
 49    private static final String CREATION_TIME = "creationdate";
 50    private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
 51    private static final Log log = LogFactory.getLog(CreationDate.class);
 52   
 53  2 public String getName() {
 54  2 return CREATION_TIME;
 55    }
 56   
 57  0 public PartialResponse.Content getRootProperty() {
 58  0 return null;
 59    }
 60   
 61  8 public PartialResponse.Content getProperty(Collection col) {
 62  8 try {
 63  8 MetaData meta = col.getCollectionMeta();
 64  8 long date = meta.getCreatedTime();
 65  8 if (date != 0) {
 66  8 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
 67  8 sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
 68  8 return new PartialResponse.Content(CREATION_TIME, sdf.format(new Date(date)));
 69    }
 70    } catch (DBException e) {
 71  0 log.error("Getting creation time for collection " + col.getCanonicalName() + " failed", e);
 72  0 return null;
 73    }
 74   
 75  0 return null;
 76    }
 77   
 78  5 public PartialResponse.Content getProperty(Entry entry) {
 79  5 long date = entry.getCreationTime();
 80  5 if (date != 0) {
 81  5 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
 82  5 sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
 83  5 return new PartialResponse.Content(CREATION_TIME, sdf.format(new Date(date)));
 84    } else {
 85    // creation time is not available
 86  0 return null;
 87    }
 88    }
 89   
 90    }