KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > checker > ResultsLogger


1 /*
2  * Copyright (c) 2004-2005, Hewlett-Packard Company and Massachusetts
3  * Institute of Technology. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * - Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * - Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * - Neither the name of the Hewlett-Packard Company nor the name of the
17  * Massachusetts Institute of Technology nor the names of their
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32  * DAMAGE.
33  */

34 package org.dspace.checker;
35
36 import java.text.SimpleDateFormat JavaDoc;
37 import java.util.Date JavaDoc;
38
39 import org.apache.log4j.Logger;
40 import org.dspace.core.I18N;
41
42 /**
43  * <p>
44  * Collects results from a Checksum process and outputs them to a Log4j Logger.
45  * </p>
46  *
47  *
48  * @author Jim Downing
49  * @author Grace Carpenter
50  * @author Nathan Sarr
51  *
52  *
53  */

54 public class ResultsLogger implements ChecksumResultsCollector
55 {
56     /**
57      * Usual Log4J logger.
58      */

59     private static final Logger LOG = Logger.getLogger(ResultsLogger.class);
60
61     /**
62      * Utility date format.
63      */

64     private static final SimpleDateFormat JavaDoc DATE_FORMAT = new SimpleDateFormat JavaDoc(
65             "MM/dd/yyyy hh:mm:ss");
66
67     /**
68      * Date the current checking run started.
69      */

70     Date JavaDoc startDate = null;
71
72     /**
73      * ChecksumResultDAO dependency variable.
74      */

75     private ChecksumResultDAO resultDAO;
76
77     /**
78      * Blanked off, no-op constructor. Do not use.
79      */

80     private ResultsLogger()
81     {
82         ;
83     }
84
85     /**
86      * Main constructor.
87      *
88      * @param startDt
89      * Date the checking run started.
90      */

91     public ResultsLogger(Date JavaDoc startDt)
92     {
93         this.resultDAO = new ChecksumResultDAO();
94
95         LOG.info(msg("run-start-time") + ": " + DATE_FORMAT.format(startDt));
96     }
97
98     /**
99      * Get the i18N string.
100      *
101      * @param key
102      * to get the message.
103      * @return the message found.
104      */

105     private String JavaDoc msg(String JavaDoc key)
106     {
107         return I18N.message(key, ResultsLogger.class);
108     }
109
110     /**
111      * Collect a result for logging.
112      *
113      * @param info
114      * the BitstreamInfo representing the result.
115      * @see org.dspace.checker.ChecksumResultsCollector#collect(org.dspace.checker.BitstreamInfo)
116      */

117     public void collect(BitstreamInfo info)
118     {
119         LOG.info("******************************************************");
120         LOG.info(msg("bitstream-id") + ": " + info.getBitstreamId());
121         LOG.info(msg("bitstream-info-found") + ": " + info.getInfoFound());
122         LOG.info(msg("bitstream-marked-deleted") + ": " + info.getDeleted());
123         LOG.info(msg("bitstream-found") + ": " + info.getBitstreamFound());
124         LOG.info(msg("to-be-processed") + ": " + info.getToBeProcessed());
125         LOG.info(msg("internal-id") + ": " + info.getInternalId());
126         LOG.info(msg("name") + ": " + info.getName());
127         LOG.info(msg("store-number") + ": " + info.getStoreNumber());
128         LOG.info(msg("size") + ": " + info.getSize());
129         LOG.info(msg("bitstream-format") + ": " + info.getBitstreamFormatId());
130         LOG.info(msg("user-format-description") + ": "
131                 + info.getUserFormatDescription());
132         LOG.info(msg("source") + ": " + info.getSource());
133         LOG
134                 .info(msg("checksum-algorithm") + ": "
135                         + info.getChecksumAlgorithm());
136         LOG.info(msg("previous-checksum") + ": " + info.getStoredChecksum());
137         LOG.info(msg("previous-checksum-date")
138                 + ": "
139                 + ((info.getProcessEndDate() != null) ? DATE_FORMAT.format(info
140                         .getProcessEndDate()) : "unknown"));
141         LOG.info(msg("new-checksum") + ": " + info.getCalculatedChecksum());
142         LOG.info(msg("checksum-comparison-result") + ": "
143                 + resultDAO.getChecksumCheckStr(info.getChecksumCheckResult()));
144         LOG.info("\n\n");
145     }
146 }
147
Popular Tags