1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: htmlfile.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <toolkit/htmlfile.hxx>
34 // NOT FULLY DECLARED SERVICES
35 #include <cosv/file.hxx>
36 #include <udm/html/htmlitem.hxx>
40 bool bUse_OOoFrameDiv
= true;
41 const String
C_sOOoFrameDiv_IdlId("adc-idlref");
45 using csi::xml::AnAttribute
;
47 DocuFile_Html::DocuFile_Html()
55 aBuffer(60000) // Grows dynamically, when necessary.
60 DocuFile_Html::SetLocation( const csv::ploc::Path
& i_rFilePath
)
62 StreamLock
sPath(1000);
63 i_rFilePath
.Get( sPath() );
65 sFilePath
= sPath().c_str();
69 DocuFile_Html::SetTitle( const char * i_sTitle
)
75 DocuFile_Html::SetRelativeCssPath( const char * i_sCssFile_relativePath
)
77 sCssFile
= i_sCssFile_relativePath
;
81 DocuFile_Html::SetCopyright( const char * i_sCopyright
)
83 sCopyright
= i_sCopyright
;
87 DocuFile_Html::EmptyBody()
89 aBodyData
.SetContent(0);
93 // Insert <div> tag to allow better formatting for OOo.
95 << new xml::XmlCode("<div id=\"")
96 << new xml::XmlCode(C_sOOoFrameDiv_IdlId
)
97 << new xml::XmlCode("\">\n\n");
101 >> *new html::Label( "_top_" )
106 DocuFile_Html::CreateFile()
108 csv::File
aFile(sFilePath
, csv::CFM_CREATE
);
109 if (NOT aFile
.open())
111 Cerr() << "Can't create file " << sFilePath
<< "." << Endl();
119 static const char sCompletion
[] = "\n</html>\n";
120 aFile
.write( sCompletion
);
123 Cout() << '.' << Flush();
129 DocuFile_Html::WriteHeader( csv::File
& io_aFile
)
133 static const char s1
[] =
134 "<html>\n<head>\n<title>";
135 static const char s2
[] =
137 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";
140 aBuffer
.write( sTitle
);
144 if (NOT sCssFile
.empty())
146 static const char s3
[] =
147 "<link rel=\"stylesheet\" type=\"text/css\" href=\"";
148 static const char s4
[] =
152 aBuffer
.write(sCssFile
);
156 if (NOT sStyle
.empty())
158 static const char s5
[] =
160 static const char s6
[] =
164 aBuffer
.write(sStyle
);
168 static const char s7
[] =
172 io_aFile
.write(aBuffer
.c_str(), aBuffer
.size());
176 DocuFile_Html::WriteBody( csv::File
& io_aFile
)
181 >> *new html::Link( "#_top_" )
184 if ( sCopyright
.length() > 0 )
187 << new xml::XmlCode("<hr size=\"3\">");
190 >> *new html::Paragraph
191 << new html::ClassAttr( "copyright" )
192 << new xml::AnAttribute( "align", "center" )
193 << new xml::XmlCode(sCopyright
);
196 if (bUse_OOoFrameDiv
)
198 // Insert <div> tag to allow better formatting for OOo.
200 << new xml::XmlCode("\n</div> <!-- id=\"")
201 << new xml::XmlCode(C_sOOoFrameDiv_IdlId
)
202 << new xml::XmlCode("\" -->\n");
205 aBodyData
.WriteOut(aBuffer
);
206 io_aFile
.write(aBuffer
.c_str(), aBuffer
.size());