Update ooo320-m1
[ooovba.git] / autodoc / source / display / toolkit / htmlfile.cxx
blob7a118b69897bdfcc01f1557ca622095768985bb6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: htmlfile.cxx,v $
10 * $Revision: 1.9 $
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 ************************************************************************/
31 #include <precomp.h>
32 #include <toolkit/htmlfile.hxx>
34 // NOT FULLY DECLARED SERVICES
35 #include <cosv/file.hxx>
36 #include <udm/html/htmlitem.hxx>
38 namespace
40 bool bUse_OOoFrameDiv = true;
41 const String C_sOOoFrameDiv_IdlId("adc-idlref");
44 using namespace csi;
45 using csi::xml::AnAttribute;
47 DocuFile_Html::DocuFile_Html()
48 : sFilePath(),
49 sTitle(),
50 sLocation(),
51 sStyle(),
52 sCssFile(),
53 sCopyright(),
54 aBodyData(),
55 aBuffer(60000) // Grows dynamically, when necessary.
59 void
60 DocuFile_Html::SetLocation( const csv::ploc::Path & i_rFilePath )
62 StreamLock sPath(1000);
63 i_rFilePath.Get( sPath() );
65 sFilePath = sPath().c_str();
68 void
69 DocuFile_Html::SetTitle( const char * i_sTitle )
71 sTitle = i_sTitle;
74 void
75 DocuFile_Html::SetRelativeCssPath( const char * i_sCssFile_relativePath )
77 sCssFile = i_sCssFile_relativePath;
80 void
81 DocuFile_Html::SetCopyright( const char * i_sCopyright )
83 sCopyright = i_sCopyright;
86 void
87 DocuFile_Html::EmptyBody()
89 aBodyData.SetContent(0);
91 if (bUse_OOoFrameDiv)
93 // Insert <div> tag to allow better formatting for OOo.
94 aBodyData
95 << new xml::XmlCode("<div id=\"")
96 << new xml::XmlCode(C_sOOoFrameDiv_IdlId)
97 << new xml::XmlCode("\">\n\n");
100 aBodyData
101 >> *new html::Label( "_top_" )
102 << " ";
105 bool
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();
112 return false;
115 WriteHeader(aFile);
116 WriteBody(aFile);
118 // Write end
119 static const char sCompletion[] = "\n</html>\n";
120 aFile.write( sCompletion );
122 aFile.close();
123 Cout() << '.' << Flush();
124 return true;
128 void
129 DocuFile_Html::WriteHeader( csv::File & io_aFile )
131 aBuffer.reset();
133 static const char s1[] =
134 "<html>\n<head>\n<title>";
135 static const char s2[] =
136 "</title>\n"
137 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";
139 aBuffer.write( s1 );
140 aBuffer.write( sTitle );
141 aBuffer.write( s2 );
144 if (NOT sCssFile.empty())
146 static const char s3[] =
147 "<link rel=\"stylesheet\" type=\"text/css\" href=\"";
148 static const char s4[] =
149 "\">\n";
151 aBuffer.write(s3);
152 aBuffer.write(sCssFile);
153 aBuffer.write(s4);
156 if (NOT sStyle.empty())
158 static const char s5[] =
159 "<style>";
160 static const char s6[] =
161 "</style>\n";
163 aBuffer.write(s5);
164 aBuffer.write(sStyle);
165 aBuffer.write(s6);
168 static const char s7[] =
169 "</head>\n";
170 aBuffer.write(s7);
172 io_aFile.write(aBuffer.c_str(), aBuffer.size());
175 void
176 DocuFile_Html::WriteBody( csv::File & io_aFile )
178 aBuffer.reset();
180 aBodyData
181 >> *new html::Link( "#_top_" )
182 << "Top of Page";
184 if ( sCopyright.length() > 0 )
186 aBodyData
187 << new xml::XmlCode("<hr size=\"3\">");
189 aBodyData
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.
199 aBodyData
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());