Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / runner / graphical / Office.java
blob59eeb160f2d9b4e6e7d5d81eb73e985b634e8796
1 /*
2 * ************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 * ***********************************************************************
30 package graphical;
32 import java.util.ArrayList;
34 /**
36 * @author ll93751
38 public class Office implements IOffice
40 private ParameterHelper m_aParameterHelper;
41 private String m_sDocumentName;
42 private String m_sResult;
43 private IOffice m_aOffice = null;
45 public Office(ParameterHelper _aParam, String _sResult)
47 m_aParameterHelper = _aParam;
48 m_sResult = _sResult;
50 if (_aParam.getReferenceType().toLowerCase().equals("ooo") ||
51 _aParam.getReferenceType().toLowerCase().equals("o3") ||
52 _aParam.getReferenceType().toLowerCase().equals("ps") ||
53 _aParam.getReferenceType().toLowerCase().equals("pdf"))
55 m_aOffice = new OpenOfficePostscriptCreator(_aParam, m_sResult);
57 else if (_aParam.getReferenceType().toLowerCase().equals("msoffice"))
59 m_aOffice = new MSOfficePostscriptCreator(_aParam, m_sResult);
64 /**
65 * Load a document with an already started Office.
66 * @param _sDocumentName
67 * @throws graphical.OfficeException
69 public void load(String _sDocumentName) throws OfficeException
71 m_sDocumentName = _sDocumentName;
72 // check if given file is a picture, then do nothing
73 String sDocumentSuffix = FileHelper.getSuffix(m_sDocumentName);
74 if (sDocumentSuffix.toLowerCase().endsWith(".png") ||
75 sDocumentSuffix.toLowerCase().endsWith(".gif") ||
76 sDocumentSuffix.toLowerCase().endsWith(".jpg") ||
77 sDocumentSuffix.toLowerCase().endsWith(".bmp"))
79 throw new OfficeException("The given document is not a document type.");
82 // TODO: we should start the office after we know if we really need an Office.
83 if (m_aOffice != null)
85 if (sDocumentSuffix.toLowerCase().endsWith(".odb"))
87 if (m_aParameterHelper.getReferenceType().toLowerCase().equals("msoffice"))
89 // we can't handle .odb with msoffice
90 return;
92 // TODO: run through all documents which exists as reports in odb files
93 OpenOfficeDatabaseReportExtractor aExtractor = new OpenOfficeDatabaseReportExtractor(m_aParameterHelper);
94 ArrayList aList = aExtractor.load(m_sDocumentName);
95 if (aList != null)
97 // remove the whole section about the 'name'.odb there are no information we need
98 // we will create a new one.
99 String sIniFile = FileHelper.appendPath(m_sResult, "index.ini");
100 IniFile aIniFile2 = new IniFile(sIniFile);
101 String sSection = FileHelper.getBasename(_sDocumentName); // name of the odb file
102 aIniFile2.removeSection(sSection);
103 aIniFile2.close();
105 for (int i=0; i<aList.size();i++)
107 String sDocumentName = (String)aList.get(i);
108 m_aOffice.load(sDocumentName);
109 m_aOffice.storeAsPostscript();
112 // foreach Report found in the .odb file, create an entry 'report'<number> in the original <name>.odb Section
113 // so it is possible to run through all reports by the given .odb name
114 IniFile aIniFile = new IniFile(sIniFile);
115 // String sSection = FileHelper.getBasename(_sDocumentName); // name of the odb file
116 int nFileCount = aIniFile.getIntValue(sSection, "reportcount", 0);
117 String sValue = FileHelper.getBasename(sDocumentName); // name of the corresponding report
118 aIniFile.insertValue(sSection, "report" + nFileCount, sValue);
119 aIniFile.insertValue(sSection, "reportcount", nFileCount + 1);
120 aIniFile.close();
123 else
125 throw new OfficeException("Can't open the document " + m_sDocumentName);
128 else
130 m_aOffice.load(_sDocumentName);
135 public void storeAsPostscript() throws OfficeException
137 if (m_aOffice != null)
139 if (m_sDocumentName.endsWith(".odb"))
141 // this has already be done by load() for odb files.
143 else
145 m_aOffice.storeAsPostscript();
148 // FileHelper.addBasenameToIndex(sOutputFilename);
152 public void start() throws OfficeException
154 if (m_aOffice != null)
156 m_aOffice.start();
160 public void close() throws OfficeException
162 if (m_aOffice != null)
164 m_aOffice.close();