2 * ************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2008 by Sun Microsystems, Inc.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * $RCSfile: Office.java,v $
11 * $Revision: 1.1.2.4 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 * ***********************************************************************
35 import java
.util
.ArrayList
;
41 public class Office
implements IOffice
43 private ParameterHelper m_aParameterHelper
;
44 private String m_sDocumentName
;
45 private String m_sResult
;
46 private IOffice m_aOffice
= null;
48 public Office(ParameterHelper _aParam
, String _sResult
)
50 m_aParameterHelper
= _aParam
;
53 if (_aParam
.getReferenceType().toLowerCase().equals("ooo") ||
54 _aParam
.getReferenceType().toLowerCase().equals("pdf"))
56 m_aOffice
= new OpenOfficePostscriptCreator(_aParam
, m_sResult
);
58 else if (_aParam
.getReferenceType().toLowerCase().equals("msoffice"))
60 m_aOffice
= new MSOfficePostscriptCreator(_aParam
, m_sResult
);
66 * Load a document with an already started Office.
67 * @param _sDocumentName
68 * @throws graphical.OfficeException
70 public void load(String _sDocumentName
) throws OfficeException
72 m_sDocumentName
= _sDocumentName
;
73 // check if given file is a picture, then do nothing
74 String sDocumentSuffix
= FileHelper
.getSuffix(m_sDocumentName
);
75 if (sDocumentSuffix
.toLowerCase().endsWith(".png") ||
76 sDocumentSuffix
.toLowerCase().endsWith(".gif") ||
77 sDocumentSuffix
.toLowerCase().endsWith(".jpg") ||
78 sDocumentSuffix
.toLowerCase().endsWith(".bmp"))
80 throw new OfficeException("The given document is not a document type.");
83 // TODO: we should start the office after we know if we really need an Office.
84 if (m_aOffice
!= null)
86 if (sDocumentSuffix
.toLowerCase().endsWith(".odb"))
88 if (m_aParameterHelper
.getReferenceType().toLowerCase().equals("msoffice"))
90 // we can't handle .odb with msoffice
93 // TODO: run through all documents which exists as reports in odb files
94 OpenOfficeDatabaseReportExtractor aExtractor
= new OpenOfficeDatabaseReportExtractor(m_aParameterHelper
);
95 ArrayList aList
= aExtractor
.load(m_sDocumentName
);
98 // remove the whole section about the 'name'.odb there are no information we need
99 // we will create a new one.
100 String sIniFile
= FileHelper
.appendPath(m_sResult
, "index.ini");
101 IniFile aIniFile2
= new IniFile(sIniFile
);
102 String sSection
= FileHelper
.getBasename(_sDocumentName
); // name of the odb file
103 aIniFile2
.removeSection(sSection
);
106 for (int i
=0; i
<aList
.size();i
++)
108 String sDocumentName
= (String
)aList
.get(i
);
109 m_aOffice
.load(sDocumentName
);
110 m_aOffice
.storeAsPostscript();
113 // foreach Report found in the .odb file, create an entry 'report'<number> in the original <name>.odb Section
114 // so it is possible to run through all reports by the given .odb name
115 IniFile aIniFile
= new IniFile(sIniFile
);
116 // String sSection = FileHelper.getBasename(_sDocumentName); // name of the odb file
117 int nFileCount
= aIniFile
.getIntValue(sSection
, "reportcount", 0);
118 String sValue
= FileHelper
.getBasename(sDocumentName
); // name of the corresponding report
119 aIniFile
.insertValue(sSection
, "report" + nFileCount
, sValue
);
120 aIniFile
.insertValue(sSection
, "reportcount", nFileCount
+ 1);
126 throw new OfficeException("Can't open the document " + m_sDocumentName
);
131 m_aOffice
.load(_sDocumentName
);
136 public void storeAsPostscript() throws OfficeException
138 if (m_aOffice
!= null)
140 if (m_sDocumentName
.endsWith(".odb"))
142 // this has already be done by load() for odb files.
146 m_aOffice
.storeAsPostscript();
149 // FileHelper.addBasenameToIndex(sOutputFilename);
153 public void start() throws OfficeException
155 if (m_aOffice
!= null)
161 public void close() throws OfficeException
163 if (m_aOffice
!= null)