1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package graphical; 29 30 import java.io.File; 31 // import java.io.FileWriter; 32 // import java.io.OutputStream; 33 // import java.io.PrintStream; 34 import java.io.PrintStream; 35 import java.io.RandomAccessFile; 36 // import java.io.StringWriter; 37 // import java.lang.Double; 38 39 40 public class PerformanceContainer /* extends *//* implements */ { 41 private long m_nStartTime; 42 43 /* 44 simple helper functions to start/stop a timer, to know how long a process need in milliseconds 45 */ 46 public long getStartTime() 47 { 48 return System.currentTimeMillis(); 49 } 50 public void setStartTime(long _nStartTime) 51 { 52 m_nStartTime = _nStartTime; 53 } 54 55 /* 56 return the time, which is done until last startTime() 57 */ 58 private long meanTime(long _nCurrentTimer) 59 { 60 if (_nCurrentTimer == 0) 61 { 62 GlobalLogWriter.println("Forgotten to initialise a start timer."); 63 return 0; 64 } 65 long nMeanTime = System.currentTimeMillis(); 66 return nMeanTime - _nCurrentTimer; 67 } 68 69 /* 70 public long stopTimer() 71 { 72 if (m_nStartTime == 0) 73 { 74 System.out.println("Forgotten to initialise start timer."); 75 return 0; 76 } 77 long nStopTime = System.currentTimeMillis(); 78 return nStopTime - m_nStartTime; 79 } 80 */ 81 82 final static int Load = 0; 83 final static int Store = 1; 84 final static int Print = 2; 85 final static int OfficeStart = 3; 86 final static int StoreAsPDF = 4; 87 final static int OfficeStop = 5; 88 final static int AllTime = 6; 89 final static int LAST_VALUE = 7; // THIS MUST BE ALWAYS THE LAST AND THE BIGGEST VALUE! 90 91 private long m_nTime[]; 92 private String m_sMSOfficeVersion; 93 94 public PerformanceContainer() 95 { 96 m_nTime = new long[LAST_VALUE]; 97 // @todo: is this need? 98 for (int i=0;i<LAST_VALUE;i++) 99 { 100 m_nTime[i] = 0; 101 } 102 } 103 104 public void setTime(int _nIndex, long _nValue) 105 { 106 m_nTime[_nIndex] = _nValue; 107 } 108 public long getTime(int _nIndex) 109 { 110 return m_nTime[_nIndex]; 111 } 112 113 public void startTime(int _nIndex) 114 { 115 m_nTime[_nIndex] = getStartTime(); 116 } 117 118 public void stopTime(int _nIndex) 119 { 120 m_nTime[_nIndex] = meanTime(m_nTime[_nIndex]); 121 } 122 123 public String getMSOfficeVersion() 124 { 125 return m_sMSOfficeVersion; 126 } 127 128 public void print(PrintStream out) 129 { 130 // String ls = System.getProperty("line.separator"); 131 // out. 132 out.println("loadtime=" + String.valueOf(m_nTime[ Load ])); 133 out.println("storetime=" + String.valueOf(m_nTime[ Store ])); 134 out.println("printtime=" + String.valueOf(m_nTime[ Print ])); 135 out.println("officestarttime=" + String.valueOf(m_nTime[ OfficeStart ])); 136 out.println("officestoptime=" + String.valueOf(m_nTime[ OfficeStop ])); 137 out.println("storeaspdftime=" + String.valueOf(m_nTime[ StoreAsPDF ])); 138 out.println("alltime=" + String.valueOf(m_nTime[ AllTime ])); 139 } 140 141 public void print(IniFile _aIniFile, String _sSection) 142 { 143 // String ls = System.getProperty("line.separator"); 144 // out. 145 _aIniFile.insertValue(_sSection, "loadtime" , String.valueOf(m_nTime[ Load ])); 146 _aIniFile.insertValue(_sSection, "storetime" , String.valueOf(m_nTime[ Store ])); 147 _aIniFile.insertValue(_sSection, "printtime" , String.valueOf(m_nTime[ Print ])); 148 _aIniFile.insertValue(_sSection, "officestarttime" , String.valueOf(m_nTime[ OfficeStart ])); 149 _aIniFile.insertValue(_sSection, "officestoptime" , String.valueOf(m_nTime[ OfficeStop ])); 150 _aIniFile.insertValue(_sSection, "storeaspdftime" , String.valueOf(m_nTime[ StoreAsPDF ])); 151 _aIniFile.insertValue(_sSection, "alltime" , String.valueOf(m_nTime[ AllTime ])); 152 } 153 154 public static double stringToDouble(String _sStr) 155 { 156 double nValue = 0; 157 try 158 { 159 nValue = Double.parseDouble( _sStr ); 160 } 161 catch (NumberFormatException e) 162 { 163 GlobalLogWriter.println("Can't convert string to double " + _sStr); 164 } 165 return nValue; 166 } 167 168 public static long secondsToMilliSeconds(double _nSeconds) 169 { 170 return (long)(_nSeconds * 1000.0); 171 } 172 173 /* 174 Helper function, which read some values from a given file 175 176 sample of wordinfofile 177 name=c:\doc-pool\wntmsci\samples\msoffice\word\LineSpacing.doc 178 WordVersion=11.0 179 WordStartTime=0.340490102767944 180 WordLoadTime=0.650935888290405 181 WordPrintTime=0.580835103988647 182 */ 183 public void readWordValuesFromFile(String sFilename) 184 { 185 File aFile = new File(sFilename); 186 if (! aFile.exists()) 187 { 188 GlobalLogWriter.println("couldn't find file " + sFilename); 189 return; 190 } 191 192 RandomAccessFile aRandomAccessFile = null; 193 try 194 { 195 aRandomAccessFile = new RandomAccessFile(aFile,"r"); 196 String sLine = ""; 197 while (sLine != null) 198 { 199 sLine = aRandomAccessFile.readLine(); 200 if ( (sLine != null) && 201 (! (sLine.length() < 2) ) && 202 (! sLine.startsWith("#"))) 203 { 204 if (sLine.startsWith("WordStartTime=")) 205 { 206 String sTime = sLine.substring(14); 207 m_nTime[OfficeStart] = secondsToMilliSeconds(stringToDouble(sTime)); 208 } 209 else if (sLine.startsWith("WordLoadTime=")) 210 { 211 String sTime = sLine.substring(13); 212 m_nTime[Load] = secondsToMilliSeconds(stringToDouble(sTime)); 213 } 214 else if (sLine.startsWith("WordPrintTime=")) 215 { 216 String sTime = sLine.substring(14); 217 m_nTime[Print] = secondsToMilliSeconds(stringToDouble(sTime)); 218 } 219 else if (sLine.startsWith("WordVersion=")) 220 { 221 String sMSOfficeVersion = sLine.substring(12); 222 m_sMSOfficeVersion = "Word:" + sMSOfficeVersion; 223 } 224 else if (sLine.startsWith("ExcelVersion=")) 225 { 226 String sMSOfficeVersion = sLine.substring(13); 227 m_sMSOfficeVersion = "Excel:" + sMSOfficeVersion; 228 } 229 else if (sLine.startsWith("PowerPointVersion=")) 230 { 231 String sMSOfficeVersion = sLine.substring(18); 232 m_sMSOfficeVersion = "PowerPoint:" + sMSOfficeVersion; 233 } 234 } 235 } 236 } 237 catch (java.io.FileNotFoundException fne) 238 { 239 GlobalLogWriter.println("couldn't open file " + sFilename); 240 GlobalLogWriter.println("Message: " + fne.getMessage()); 241 } 242 catch (java.io.IOException ie) 243 { 244 GlobalLogWriter.println("Exception while reading file " + sFilename); 245 GlobalLogWriter.println("Message: " + ie.getMessage()); 246 } 247 try 248 { 249 aRandomAccessFile.close(); 250 } 251 catch (java.io.IOException ie) 252 { 253 GlobalLogWriter.println("Couldn't close file " + sFilename); 254 GlobalLogWriter.println("Message: " + ie.getMessage()); 255 } 256 } 257 258 // public static void main(String[] args) 259 // { 260 // BorderRemover a = new BorderRemover(); 261 // try 262 // { 263 // a.createNewImageWithoutBorder(args[0], args[1]); 264 // } 265 // catch(java.io.IOException e) 266 // { 267 // System.out.println("Exception caught."); 268 // } 269 // 270 // } 271 } 272