1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package org.apache.openoffice.ooxml.parser; 23 24 import java.io.File; 25 import java.io.FileNotFoundException; 26 import java.io.FileOutputStream; 27 import java.io.IOException; 28 import java.io.OutputStream; 29 30 public class Log 31 { 32 public static Log Std = new Log(System.out); 33 public static Log Err = new Log(System.err); 34 public static Log Dbg = Std; 35 36 Log(final OutputStream aOut)37 public Log (final OutputStream aOut) 38 { 39 maOut = aOut; 40 msIndentation = ""; 41 } 42 43 44 45 Log(final String sFilename)46 public Log (final String sFilename) 47 { 48 this(CreateFileOutputStream(sFilename)); 49 } 50 51 52 53 Log(final File aFile)54 public Log (final File aFile) 55 { 56 this(CreateFileOutputStream(aFile)); 57 } 58 59 60 61 CreateFileOutputStream(final File aFile)62 private static OutputStream CreateFileOutputStream (final File aFile) 63 { 64 try 65 { 66 return new FileOutputStream(aFile); 67 } 68 catch (final Exception aException) 69 { 70 aException.printStackTrace(); 71 return null; 72 } 73 } 74 75 76 77 printf(final String sFormat, final Object ... aArgumentList)78 public void printf (final String sFormat, final Object ... aArgumentList) 79 { 80 try 81 { 82 maOut.write(msIndentation.getBytes()); 83 maOut.write(String.format(sFormat, aArgumentList).getBytes()); 84 } 85 catch (IOException e) 86 { 87 e.printStackTrace(); 88 } 89 } 90 91 92 93 IncreaseIndentation()94 public void IncreaseIndentation () 95 { 96 msIndentation += " "; 97 } 98 99 100 101 DecreaseIndentation()102 public void DecreaseIndentation () 103 { 104 msIndentation = msIndentation.substring(4); 105 } 106 107 108 109 CreateFileOutputStream(final String sFilename)110 private static OutputStream CreateFileOutputStream (final String sFilename) 111 { 112 OutputStream aOut; 113 try 114 { 115 aOut = new FileOutputStream(sFilename); 116 return aOut; 117 } 118 catch (FileNotFoundException e) 119 { 120 e.printStackTrace(); 121 return null; 122 } 123 } 124 125 126 127 128 private final OutputStream maOut; 129 private String msIndentation; 130 } 131