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.schema.misc; 23 24 import java.io.File; 25 import java.io.FileNotFoundException; 26 import java.io.FileOutputStream; 27 import java.io.PrintStream; 28 29 /** Make output with indentation easier. 30 */ 31 public class Log 32 { Log(final File aFile)33 public Log (final File aFile) 34 { 35 PrintStream aOut = null; 36 try 37 { 38 aOut = new PrintStream(new FileOutputStream(aFile)); 39 } 40 catch (FileNotFoundException e) 41 { 42 e.printStackTrace(); 43 } 44 maOut = aOut; 45 mbIsActive = maOut!=null; 46 msIndentation = ""; 47 } 48 49 50 51 AddComment( final String sFormat, final Object ... aArgumentList)52 public void AddComment ( 53 final String sFormat, 54 final Object ... aArgumentList) 55 { 56 if (mbIsActive) 57 { 58 maOut.print(msIndentation); 59 maOut.print("// "); 60 maOut.printf(sFormat, aArgumentList); 61 maOut.print("\n"); 62 } 63 } 64 65 66 67 StartBlock()68 public void StartBlock () 69 { 70 if (mbIsActive) 71 msIndentation += " "; 72 } 73 74 75 76 EndBlock()77 public void EndBlock () 78 { 79 if (mbIsActive) 80 msIndentation = msIndentation.substring(4); 81 } 82 83 84 85 printf( final String sFormat, final Object ... aArgumentList)86 public void printf ( 87 final String sFormat, final Object ... aArgumentList) 88 { 89 if (mbIsActive) 90 { 91 final String sMessage = String.format(sFormat, aArgumentList); 92 maOut.print(msIndentation); 93 maOut.print(sMessage); 94 } 95 } 96 97 98 99 println( final String sMessage)100 public void println ( 101 final String sMessage) 102 { 103 if (mbIsActive) 104 { 105 maOut.print(msIndentation); 106 maOut.print(sMessage); 107 maOut.print("\n"); 108 } 109 } 110 111 112 113 Close()114 public void Close() 115 { 116 if (mbIsActive) 117 maOut.close(); 118 } 119 120 121 122 123 private final PrintStream maOut; 124 private final boolean mbIsActive; 125 private String msIndentation; 126 } 127