2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.util
.ArrayList
;
23 public class Office
implements IOffice
25 private ParameterHelper m_aParameterHelper
;
26 private String m_sDocumentName
;
27 private String m_sResult
;
28 private IOffice m_aOffice
= null;
30 public Office(ParameterHelper _aParam
, String _sResult
)
32 m_aParameterHelper
= _aParam
;
35 if (_aParam
.getReferenceType().toLowerCase().equals("ooo") ||
36 _aParam
.getReferenceType().toLowerCase().equals("o3") ||
37 _aParam
.getReferenceType().toLowerCase().equals("ps") ||
38 _aParam
.getReferenceType().toLowerCase().equals("pdf"))
40 m_aOffice
= new OpenOfficePostscriptCreator(_aParam
, m_sResult
);
42 else if (_aParam
.getReferenceType().toLowerCase().equals("msoffice"))
44 m_aOffice
= new MSOfficePostscriptCreator(_aParam
, m_sResult
);
50 * Load a document with an already started Office.
51 * @param _sDocumentName
52 * @throws graphical.OfficeException
54 public void load(String _sDocumentName
) throws OfficeException
56 m_sDocumentName
= _sDocumentName
;
57 // check if given file is a picture, then do nothing
58 String sDocumentSuffix
= FileHelper
.getSuffix(m_sDocumentName
);
59 if (sDocumentSuffix
.toLowerCase().endsWith(".png") ||
60 sDocumentSuffix
.toLowerCase().endsWith(".gif") ||
61 sDocumentSuffix
.toLowerCase().endsWith(".jpg") ||
62 sDocumentSuffix
.toLowerCase().endsWith(".bmp"))
64 throw new OfficeException("The given document is not a document type.");
67 // TODO: we should start the office after we know if we really need an Office.
68 if (m_aOffice
!= null)
70 if (sDocumentSuffix
.toLowerCase().endsWith(".odb"))
72 if (m_aParameterHelper
.getReferenceType().toLowerCase().equals("msoffice"))
74 // we can't handle .odb with msoffice
77 // TODO: run through all documents which exists as reports in odb files
78 OpenOfficeDatabaseReportExtractor aExtractor
= new OpenOfficeDatabaseReportExtractor(m_aParameterHelper
);
79 ArrayList
<String
> aList
= aExtractor
.load(m_sDocumentName
);
82 // remove the whole section about the 'name'.odb there are no information we need
83 // we will create a new one.
84 String sIniFile
= FileHelper
.appendPath(m_sResult
, "index.ini");
85 IniFile aIniFile2
= new IniFile(sIniFile
);
86 String sSection
= FileHelper
.getBasename(_sDocumentName
); // name of the odb file
87 aIniFile2
.removeSection(sSection
);
90 for (int i
=0; i
<aList
.size();i
++)
92 String sDocumentName
= aList
.get(i
);
93 m_aOffice
.load(sDocumentName
);
94 m_aOffice
.storeAsPostscript();
97 // foreach Report found in the .odb file, create an entry 'report'<number> in the original <name>.odb Section
98 // so it is possible to run through all reports by the given .odb name
99 IniFile aIniFile
= new IniFile(sIniFile
);
100 int nFileCount
= aIniFile
.getIntValue(sSection
, "reportcount", 0);
101 String sValue
= FileHelper
.getBasename(sDocumentName
); // name of the corresponding report
102 aIniFile
.insertValue(sSection
, "report" + nFileCount
, sValue
);
103 aIniFile
.insertValue(sSection
, "reportcount", nFileCount
+ 1);
109 throw new OfficeException("Can't open the document " + m_sDocumentName
);
114 m_aOffice
.load(_sDocumentName
);
119 public void storeAsPostscript() throws OfficeException
121 if (m_aOffice
!= null)
123 if (m_sDocumentName
.endsWith(".odb"))
125 // this has already be done by load() for odb files.
129 m_aOffice
.storeAsPostscript();
134 public void start() throws OfficeException
136 if (m_aOffice
!= null)
142 public void close() throws OfficeException
144 if (m_aOffice
!= null)