001/** 002 * Copyright 2010-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.common.util.inform; 017 018import java.io.PrintStream; 019 020import org.kuali.common.util.Assert; 021import org.kuali.common.util.log.LogMsg; 022 023public final class Inform { 024 025 public static final PrintStream DEFAULT_PRINT_STREAM = System.out; 026 public static final String DEFAULT_START_TOKEN = "[INFO] Progress: "; 027 public static final String DEFAULT_PROGRESS_TOKEN = "."; 028 public static final String DEFAULT_COMPLETE_TOKEN = "\n"; 029 public static final LogMsg DEFAULT_START_MESSAGE = LogMsg.NOOP; 030 public static final LogMsg DEFAULT_STOP_MESSAGE = LogMsg.NOOP; 031 032 public static final Inform DEFAULT_INFORM = new Inform(); 033 034 public Inform() { 035 this(DEFAULT_PRINT_STREAM, DEFAULT_START_TOKEN, DEFAULT_PROGRESS_TOKEN, DEFAULT_COMPLETE_TOKEN, DEFAULT_START_MESSAGE, DEFAULT_STOP_MESSAGE); 036 } 037 038 public Inform(LogMsg startMessage) { 039 this(DEFAULT_PRINT_STREAM, DEFAULT_START_TOKEN, DEFAULT_PROGRESS_TOKEN, DEFAULT_COMPLETE_TOKEN, startMessage, DEFAULT_STOP_MESSAGE); 040 } 041 042 public Inform(LogMsg startMessage, LogMsg stopMessage) { 043 this(DEFAULT_PRINT_STREAM, DEFAULT_START_TOKEN, DEFAULT_PROGRESS_TOKEN, DEFAULT_COMPLETE_TOKEN, startMessage, stopMessage); 044 } 045 046 public Inform(PrintStream printStream, String startToken, String progressToken, String completeToken, LogMsg startMessage, LogMsg stopMessage) { 047 Assert.noNulls(printStream, startMessage, stopMessage, completeToken); 048 // Printing a whitespace character to indicate progress completion is ok 049 // Assert.noBlanks(startToken, progressToken,completeToken); 050 Assert.noBlanks(startToken, progressToken); 051 this.printStream = printStream; 052 this.startToken = startToken; 053 this.progressToken = progressToken; 054 this.completeToken = completeToken; 055 this.startMessage = startMessage; 056 this.stopMessage = stopMessage; 057 } 058 059 private final PrintStream printStream; 060 private final String startToken; 061 private final String progressToken; 062 private final String completeToken; 063 private final LogMsg startMessage; 064 private final LogMsg stopMessage; 065 066 public PrintStream getPrintStream() { 067 return printStream; 068 } 069 070 public String getStartToken() { 071 return startToken; 072 } 073 074 public String getCompleteToken() { 075 return completeToken; 076 } 077 078 public LogMsg getStartMessage() { 079 return startMessage; 080 } 081 082 public LogMsg getStopMessage() { 083 return stopMessage; 084 } 085 086 public String getProgressToken() { 087 return progressToken; 088 } 089 090}