Bump for 3.6-28
[LibreOffice.git] / autodoc / source / display / toolkit / htmlfile.cxx
blobf0387f4854921dd1aa1cec647b12500d880aa548
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 ************************************************************************/
29 #include <precomp.h>
30 #include <toolkit/htmlfile.hxx>
32 // NOT FULLY DECLARED SERVICES
33 #include <cosv/file.hxx>
34 #include <udm/html/htmlitem.hxx>
36 namespace
38 bool bUse_OOoFrameDiv = true;
39 const String C_sOOoFrameDiv_IdlId("adc-idlref");
42 using namespace csi;
43 using csi::xml::AnAttribute;
45 DocuFile_Html::DocuFile_Html()
46 : sFilePath(),
47 sTitle(),
48 sLocation(),
49 sStyle(),
50 sCssFile(),
51 sCopyright(),
52 aBodyData(),
53 aBuffer(60000) // Grows dynamically, when necessary.
57 void
58 DocuFile_Html::SetLocation( const csv::ploc::Path & i_rFilePath )
60 StreamLock sPath(1000);
61 i_rFilePath.Get( sPath() );
63 sFilePath = sPath().c_str();
66 void
67 DocuFile_Html::SetTitle( const char * i_sTitle )
69 sTitle = i_sTitle;
72 void
73 DocuFile_Html::SetRelativeCssPath( const char * i_sCssFile_relativePath )
75 sCssFile = i_sCssFile_relativePath;
78 void
79 DocuFile_Html::SetCopyright( const char * i_sCopyright )
81 sCopyright = i_sCopyright;
84 void
85 DocuFile_Html::EmptyBody()
87 aBodyData.SetContent(0);
89 if (bUse_OOoFrameDiv)
91 // Insert <div> tag to allow better formatting for OOo.
92 aBodyData
93 << new xml::XmlCode("<div id=\"")
94 << new xml::XmlCode(C_sOOoFrameDiv_IdlId)
95 << new xml::XmlCode("\">\n\n");
98 aBodyData
99 >> *new html::Label( "_top_" )
100 << " ";
103 bool
104 DocuFile_Html::CreateFile()
106 csv::File aFile(sFilePath, csv::CFM_CREATE);
107 if (NOT aFile.open())
109 Cerr() << "Can't create file " << sFilePath << "." << Endl();
110 return false;
113 WriteHeader(aFile);
114 WriteBody(aFile);
116 // Write end
117 static const char sCompletion[] = "\n</html>\n";
118 aFile.write( sCompletion );
120 aFile.close();
121 Cout() << '.' << Flush();
122 return true;
126 void
127 DocuFile_Html::WriteHeader( csv::File & io_aFile )
129 aBuffer.reset();
131 static const char s1[] =
132 "<html>\n<head>\n<title>";
133 static const char s2[] =
134 "</title>\n"
135 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";
137 aBuffer.write( s1 );
138 aBuffer.write( sTitle );
139 aBuffer.write( s2 );
142 if (NOT sCssFile.empty())
144 static const char s3[] =
145 "<link rel=\"stylesheet\" type=\"text/css\" href=\"";
146 static const char s4[] =
147 "\">\n";
149 aBuffer.write(s3);
150 aBuffer.write(sCssFile);
151 aBuffer.write(s4);
154 if (NOT sStyle.empty())
156 static const char s5[] =
157 "<style>";
158 static const char s6[] =
159 "</style>\n";
161 aBuffer.write(s5);
162 aBuffer.write(sStyle);
163 aBuffer.write(s6);
166 static const char s7[] =
167 "</head>\n";
168 aBuffer.write(s7);
170 io_aFile.write(aBuffer.c_str(), aBuffer.size());
173 void
174 DocuFile_Html::WriteBody( csv::File & io_aFile )
176 aBuffer.reset();
178 aBodyData
179 >> *new html::Link( "#_top_" )
180 << "Top of Page";
182 if ( sCopyright.length() > 0 )
184 aBodyData
185 << new xml::XmlCode("<hr size=\"3\">");
187 aBodyData
188 >> *new html::Paragraph
189 << new html::ClassAttr( "copyright" )
190 << new xml::AnAttribute( "align", "center" )
191 << new xml::XmlCode(sCopyright);
194 if (bUse_OOoFrameDiv)
196 // Insert <div> tag to allow better formatting for OOo.
197 aBodyData
198 << new xml::XmlCode("\n</div> <!-- id=\"")
199 << new xml::XmlCode(C_sOOoFrameDiv_IdlId)
200 << new xml::XmlCode("\" -->\n");
203 aBodyData.WriteOut(aBuffer);
204 io_aFile.write(aBuffer.c_str(), aBuffer.size());
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */