1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include <precomp.h> 29 #include <toolkit/htmlfile.hxx> 30 31 // NOT FULLY DECLARED SERVICES 32 #include <cosv/file.hxx> 33 #include <udm/html/htmlitem.hxx> 34 35 namespace 36 { 37 bool bUse_OOoFrameDiv = true; 38 const String C_sOOoFrameDiv_IdlId("adc-idlref"); 39 } 40 41 using namespace csi; 42 using csi::xml::AnAttribute; 43 44 DocuFile_Html::DocuFile_Html() 45 : sFilePath(), 46 sTitle(), 47 sLocation(), 48 sStyle(), 49 sCssFile(), 50 sCopyright(), 51 aBodyData(), 52 aBuffer(60000) // Grows dynamically, when necessary. 53 { 54 } 55 56 void 57 DocuFile_Html::SetLocation( const csv::ploc::Path & i_rFilePath ) 58 { 59 StreamLock sPath(1000); 60 i_rFilePath.Get( sPath() ); 61 62 sFilePath = sPath().c_str(); 63 } 64 65 void 66 DocuFile_Html::SetTitle( const char * i_sTitle ) 67 { 68 sTitle = i_sTitle; 69 } 70 71 void 72 DocuFile_Html::SetRelativeCssPath( const char * i_sCssFile_relativePath ) 73 { 74 sCssFile = i_sCssFile_relativePath; 75 } 76 77 void 78 DocuFile_Html::SetCopyright( const char * i_sCopyright ) 79 { 80 sCopyright = i_sCopyright; 81 } 82 83 void 84 DocuFile_Html::EmptyBody() 85 { 86 aBodyData.SetContent(0); 87 88 if (bUse_OOoFrameDiv) 89 { 90 // Insert <div> tag to allow better formatting for OOo. 91 aBodyData 92 << new xml::XmlCode("<div id=\"") 93 << new xml::XmlCode(C_sOOoFrameDiv_IdlId) 94 << new xml::XmlCode("\">\n\n"); 95 } 96 97 aBodyData 98 >> *new html::Label( "_top_" ) 99 << " "; 100 } 101 102 bool 103 DocuFile_Html::CreateFile() 104 { 105 csv::File aFile(sFilePath, csv::CFM_CREATE); 106 if (NOT aFile.open()) 107 { 108 Cerr() << "Can't create file " << sFilePath << "." << Endl(); 109 return false; 110 } 111 112 WriteHeader(aFile); 113 WriteBody(aFile); 114 115 // Write end 116 static const char sCompletion[] = "\n</html>\n"; 117 aFile.write( sCompletion ); 118 119 aFile.close(); 120 Cout() << '.' << Flush(); 121 return true; 122 } 123 124 125 void 126 DocuFile_Html::WriteHeader( csv::File & io_aFile ) 127 { 128 aBuffer.reset(); 129 130 static const char s1[] = 131 "<html>\n<head>\n<title>"; 132 static const char s2[] = 133 "</title>\n" 134 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n"; 135 136 aBuffer.write( s1 ); 137 aBuffer.write( sTitle ); 138 aBuffer.write( s2 ); 139 140 141 if (NOT sCssFile.empty()) 142 { 143 static const char s3[] = 144 "<link rel=\"stylesheet\" type=\"text/css\" href=\""; 145 static const char s4[] = 146 "\">\n"; 147 148 aBuffer.write(s3); 149 aBuffer.write(sCssFile); 150 aBuffer.write(s4); 151 } 152 153 if (NOT sStyle.empty()) 154 { 155 static const char s5[] = 156 "<style>"; 157 static const char s6[] = 158 "</style>\n"; 159 160 aBuffer.write(s5); 161 aBuffer.write(sStyle); 162 aBuffer.write(s6); 163 } 164 165 static const char s7[] = 166 "</head>\n"; 167 aBuffer.write(s7); 168 169 io_aFile.write(aBuffer.c_str(), aBuffer.size()); 170 } 171 172 void 173 DocuFile_Html::WriteBody( csv::File & io_aFile ) 174 { 175 aBuffer.reset(); 176 177 aBodyData 178 >> *new html::Link( "#_top_" ) 179 << "Top of Page"; 180 181 if ( sCopyright.length() > 0 ) 182 { 183 aBodyData 184 << new xml::XmlCode("<hr size=\"3\">"); 185 186 aBodyData 187 >> *new html::Paragraph 188 << new html::ClassAttr( "copyright" ) 189 << new xml::AnAttribute( "align", "center" ) 190 << new xml::XmlCode(sCopyright); 191 } 192 193 if (bUse_OOoFrameDiv) 194 { 195 // Insert <div> tag to allow better formatting for OOo. 196 aBodyData 197 << new xml::XmlCode("\n</div> <!-- id=\"") 198 << new xml::XmlCode(C_sOOoFrameDiv_IdlId) 199 << new xml::XmlCode("\" -->\n"); 200 } 201 202 aBodyData.WriteOut(aBuffer); 203 io_aFile.write(aBuffer.c_str(), aBuffer.size()); 204 } 205 206 207 208 209 210 211 212