1*0841af79SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*0841af79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*0841af79SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*0841af79SAndrew Rist * distributed with this work for additional information
6*0841af79SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*0841af79SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*0841af79SAndrew Rist * "License"); you may not use this file except in compliance
9*0841af79SAndrew Rist * with the License. You may obtain a copy of the License at
10*0841af79SAndrew Rist *
11*0841af79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*0841af79SAndrew Rist *
13*0841af79SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*0841af79SAndrew Rist * software distributed under the License is distributed on an
15*0841af79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*0841af79SAndrew Rist * KIND, either express or implied. See the License for the
17*0841af79SAndrew Rist * specific language governing permissions and limitations
18*0841af79SAndrew Rist * under the License.
19*0841af79SAndrew Rist *
20*0841af79SAndrew Rist *************************************************************/
21cdf0e10cSrcweir
22cdf0e10cSrcweir #include <precomp.h>
23cdf0e10cSrcweir #include <toolkit/htmlfile.hxx>
24cdf0e10cSrcweir
25cdf0e10cSrcweir // NOT FULLY DECLARED SERVICES
26cdf0e10cSrcweir #include <cosv/file.hxx>
27cdf0e10cSrcweir #include <udm/html/htmlitem.hxx>
28cdf0e10cSrcweir
29cdf0e10cSrcweir namespace
30cdf0e10cSrcweir {
31cdf0e10cSrcweir bool bUse_OOoFrameDiv = true;
32cdf0e10cSrcweir const String C_sOOoFrameDiv_IdlId("adc-idlref");
33cdf0e10cSrcweir }
34cdf0e10cSrcweir
35cdf0e10cSrcweir using namespace csi;
36cdf0e10cSrcweir using csi::xml::AnAttribute;
37cdf0e10cSrcweir
DocuFile_Html()38cdf0e10cSrcweir DocuFile_Html::DocuFile_Html()
39cdf0e10cSrcweir : sFilePath(),
40cdf0e10cSrcweir sTitle(),
41cdf0e10cSrcweir sLocation(),
42cdf0e10cSrcweir sStyle(),
43cdf0e10cSrcweir sCssFile(),
44cdf0e10cSrcweir sCopyright(),
45cdf0e10cSrcweir aBodyData(),
46cdf0e10cSrcweir aBuffer(60000) // Grows dynamically, when necessary.
47cdf0e10cSrcweir {
48cdf0e10cSrcweir }
49cdf0e10cSrcweir
50cdf0e10cSrcweir void
SetLocation(const csv::ploc::Path & i_rFilePath)51cdf0e10cSrcweir DocuFile_Html::SetLocation( const csv::ploc::Path & i_rFilePath )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir StreamLock sPath(1000);
54cdf0e10cSrcweir i_rFilePath.Get( sPath() );
55cdf0e10cSrcweir
56cdf0e10cSrcweir sFilePath = sPath().c_str();
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
59cdf0e10cSrcweir void
SetTitle(const char * i_sTitle)60cdf0e10cSrcweir DocuFile_Html::SetTitle( const char * i_sTitle )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir sTitle = i_sTitle;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir
65cdf0e10cSrcweir void
SetRelativeCssPath(const char * i_sCssFile_relativePath)66cdf0e10cSrcweir DocuFile_Html::SetRelativeCssPath( const char * i_sCssFile_relativePath )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir sCssFile = i_sCssFile_relativePath;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
71cdf0e10cSrcweir void
SetCopyright(const char * i_sCopyright)72cdf0e10cSrcweir DocuFile_Html::SetCopyright( const char * i_sCopyright )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir sCopyright = i_sCopyright;
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
77cdf0e10cSrcweir void
EmptyBody()78cdf0e10cSrcweir DocuFile_Html::EmptyBody()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir aBodyData.SetContent(0);
81cdf0e10cSrcweir
82cdf0e10cSrcweir if (bUse_OOoFrameDiv)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir // Insert <div> tag to allow better formatting for OOo.
85cdf0e10cSrcweir aBodyData
86cdf0e10cSrcweir << new xml::XmlCode("<div id=\"")
87cdf0e10cSrcweir << new xml::XmlCode(C_sOOoFrameDiv_IdlId)
88cdf0e10cSrcweir << new xml::XmlCode("\">\n\n");
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
91cdf0e10cSrcweir aBodyData
92cdf0e10cSrcweir >> *new html::Label( "_top_" )
93cdf0e10cSrcweir << " ";
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
96cdf0e10cSrcweir bool
CreateFile()97cdf0e10cSrcweir DocuFile_Html::CreateFile()
98cdf0e10cSrcweir {
99cdf0e10cSrcweir csv::File aFile(sFilePath, csv::CFM_CREATE);
100cdf0e10cSrcweir if (NOT aFile.open())
101cdf0e10cSrcweir {
102cdf0e10cSrcweir Cerr() << "Can't create file " << sFilePath << "." << Endl();
103cdf0e10cSrcweir return false;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
106cdf0e10cSrcweir WriteHeader(aFile);
107cdf0e10cSrcweir WriteBody(aFile);
108cdf0e10cSrcweir
109cdf0e10cSrcweir // Write end
110cdf0e10cSrcweir static const char sCompletion[] = "\n</html>\n";
111cdf0e10cSrcweir aFile.write( sCompletion );
112cdf0e10cSrcweir
113cdf0e10cSrcweir aFile.close();
114cdf0e10cSrcweir Cout() << '.' << Flush();
115cdf0e10cSrcweir return true;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
118cdf0e10cSrcweir
119cdf0e10cSrcweir void
WriteHeader(csv::File & io_aFile)120cdf0e10cSrcweir DocuFile_Html::WriteHeader( csv::File & io_aFile )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir aBuffer.reset();
123cdf0e10cSrcweir
124cdf0e10cSrcweir static const char s1[] =
125cdf0e10cSrcweir "<html>\n<head>\n<title>";
126cdf0e10cSrcweir static const char s2[] =
127cdf0e10cSrcweir "</title>\n"
128cdf0e10cSrcweir "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";
129cdf0e10cSrcweir
130cdf0e10cSrcweir aBuffer.write( s1 );
131cdf0e10cSrcweir aBuffer.write( sTitle );
132cdf0e10cSrcweir aBuffer.write( s2 );
133cdf0e10cSrcweir
134cdf0e10cSrcweir
135cdf0e10cSrcweir if (NOT sCssFile.empty())
136cdf0e10cSrcweir {
137cdf0e10cSrcweir static const char s3[] =
138cdf0e10cSrcweir "<link rel=\"stylesheet\" type=\"text/css\" href=\"";
139cdf0e10cSrcweir static const char s4[] =
140cdf0e10cSrcweir "\">\n";
141cdf0e10cSrcweir
142cdf0e10cSrcweir aBuffer.write(s3);
143cdf0e10cSrcweir aBuffer.write(sCssFile);
144cdf0e10cSrcweir aBuffer.write(s4);
145cdf0e10cSrcweir }
146cdf0e10cSrcweir
147cdf0e10cSrcweir if (NOT sStyle.empty())
148cdf0e10cSrcweir {
149cdf0e10cSrcweir static const char s5[] =
150cdf0e10cSrcweir "<style>";
151cdf0e10cSrcweir static const char s6[] =
152cdf0e10cSrcweir "</style>\n";
153cdf0e10cSrcweir
154cdf0e10cSrcweir aBuffer.write(s5);
155cdf0e10cSrcweir aBuffer.write(sStyle);
156cdf0e10cSrcweir aBuffer.write(s6);
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
159cdf0e10cSrcweir static const char s7[] =
160cdf0e10cSrcweir "</head>\n";
161cdf0e10cSrcweir aBuffer.write(s7);
162cdf0e10cSrcweir
163cdf0e10cSrcweir io_aFile.write(aBuffer.c_str(), aBuffer.size());
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
166cdf0e10cSrcweir void
WriteBody(csv::File & io_aFile)167cdf0e10cSrcweir DocuFile_Html::WriteBody( csv::File & io_aFile )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir aBuffer.reset();
170cdf0e10cSrcweir
171cdf0e10cSrcweir aBodyData
172cdf0e10cSrcweir >> *new html::Link( "#_top_" )
173cdf0e10cSrcweir << "Top of Page";
174cdf0e10cSrcweir
175cdf0e10cSrcweir if ( sCopyright.length() > 0 )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir aBodyData
178cdf0e10cSrcweir << new xml::XmlCode("<hr size=\"3\">");
179cdf0e10cSrcweir
180cdf0e10cSrcweir aBodyData
181cdf0e10cSrcweir >> *new html::Paragraph
182cdf0e10cSrcweir << new html::ClassAttr( "copyright" )
183cdf0e10cSrcweir << new xml::AnAttribute( "align", "center" )
184cdf0e10cSrcweir << new xml::XmlCode(sCopyright);
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
187cdf0e10cSrcweir if (bUse_OOoFrameDiv)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir // Insert <div> tag to allow better formatting for OOo.
190cdf0e10cSrcweir aBodyData
191cdf0e10cSrcweir << new xml::XmlCode("\n</div> <!-- id=\"")
192cdf0e10cSrcweir << new xml::XmlCode(C_sOOoFrameDiv_IdlId)
193cdf0e10cSrcweir << new xml::XmlCode("\" -->\n");
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
196cdf0e10cSrcweir aBodyData.WriteOut(aBuffer);
197cdf0e10cSrcweir io_aFile.write(aBuffer.c_str(), aBuffer.size());
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
200cdf0e10cSrcweir
201cdf0e10cSrcweir
202cdf0e10cSrcweir
203cdf0e10cSrcweir
204cdf0e10cSrcweir
205cdf0e10cSrcweir
206