1<?php 2 3//this script may only be included - so its better to die if called directly. 4if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) { 5 header("location: index.php"); 6 exit; 7} 8 9 10/*This file is part of J4PHP - Ensembles de propriétés et méthodes permettant le developpment rapide d'application web modulaire 11Copyright (c) 2002-2004 @PICNet 12 13This program is free software; you can redistribute it and/or 14modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE 15as published by the Free Software Foundation. 16 17This program is distributed in the hope that it will be useful, 18but WITHOUT ANY WARRANTY; without even the implied warranty of 19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20GNU LESSER GENERAL PUBLIC LICENSE for more details. 21 22You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE 23along with this program; if not, write to the Free Software 24Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 25*/ 26APIC::import("org.apicnet.io.OOo.absOOo"); 27APIC::import("org.apicnet.io.OOo.objOOo.OOoText"); 28 29/** 30 * OOoWriter, classe de génération et de modification d'un fichier Writer 31 * 32 * @package 33 * @author apicnet 34 * @copyright Copyright (c) 2004 35 * @version $Id: OOoWriter.php,v 1.3 2005-05-18 11:01:39 mose Exp $ 36 * @access public 37 **/ 38class OOoWriter extends absOOo { 39 40 var $style; 41 var $STYLNUM = array( 42 'style_family_text' => 1, 43 'style_family_para' => 1, 44 'style_page_style' => 1 45 ); 46 47 function __construct($dir){ 48 parent::__construct(); 49 $this->DIRXML = $dir; 50 $this->FILENAME = "content.xml"; 51 52 $file = new File($dir."/".$this->FILENAME); 53 if ($file->exists()) { 54 $this->xml = new DOMIT_Document(); 55 $this->xml->loadXML($dir."/".$this->FILENAME, false); 56 } else { 57 $this->xml = new DOMIT_Document(); 58 $this->create(); 59 } 60 61 $this->style = new OOoStyle($this->DIRXML); 62 $this->xml->setDocType("<!DOCTYPE office:document-content PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"office.dtd\">"); 63 } 64 65 66 function create(){ 67 $docWriterNode =& $this->xml->createElement("office:document-content"); 68 $docWriterNode->setAttribute("xmlns:office", "http://openoffice.org/2000/office"); 69 $docWriterNode->setAttribute("xmlns:style", "http://openoffice.org/2000/style"); 70 $docWriterNode->setAttribute("xmlns:text", "http://openoffice.org/2000/text"); 71 $docWriterNode->setAttribute("xmlns:table", "http://openoffice.org/2000/table"); 72 $docWriterNode->setAttribute("xmlns:draw", "http://openoffice.org/2000/drawing"); 73 $docWriterNode->setAttribute("xmlns:fo", "http://www.w3.org/1999/XSL/Format"); 74 $docWriterNode->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink"); 75 $docWriterNode->setAttribute("xmlns:number", "http://openoffice.org/2000/datastyle"); 76 $docWriterNode->setAttribute("xmlns:svg", "http://www.w3.org/2000/svg"); 77 $docWriterNode->setAttribute("xmlns:chart", "http://openoffice.org/2000/chart"); 78 $docWriterNode->setAttribute("xmlns:dr3d", "http://openoffice.org/2000/dr3d"); 79 $docWriterNode->setAttribute("xmlns:math", "http://www.w3.org/1998/Math/MathML"); 80 $docWriterNode->setAttribute("xmlns:form", "http://openoffice.org/2000/form"); 81 $docWriterNode->setAttribute("xmlns:script", "http://openoffice.org/2000/script"); 82 $docWriterNode->setAttribute("office:class", "text"); 83 $docWriterNode->setAttribute("office:version", "1.0"); 84 85 $docWriterNode->appendChild($this->ChildText("office:script", "")); 86 87 $fontDeclsNode =& $this->xml->createElement("office:font-decls"); 88 $fontDeclNode =& $this->xml->createElement("style:font-decl"); 89 $fontDeclNode->setAttribute("style:name", "Tahoma1"); 90 $fontDeclNode->setAttribute("fo:font-family", "Tahoma"); 91 $fontDeclsNode->appendChild($fontDeclNode); 92 $fontDeclNode =& $this->xml->createElement("style:font-decl"); 93 $fontDeclNode->setAttribute("style:name", "Andale Sans UI"); 94 $fontDeclNode->setAttribute("fo:font-family", "&apos;Andale Sans UI&apos;"); 95 $fontDeclNode->setAttribute("style:font-pitch", "variable"); 96 $fontDeclsNode->appendChild($fontDeclNode); 97 $fontDeclNode =& $this->xml->createElement("style:font-decl"); 98 $fontDeclNode->setAttribute("style:name", "Tahoma"); 99 $fontDeclNode->setAttribute("fo:font-family", "Tahoma"); 100 $fontDeclNode->setAttribute("style:font-pitch", "variable"); 101 $fontDeclsNode->appendChild($fontDeclNode); 102 $fontDeclNode =& $this->xml->createElement("style:font-decl"); 103 $fontDeclNode->setAttribute("style:name", "Thorndale"); 104 $fontDeclNode->setAttribute("fo:font-family", "Thorndale"); 105 $fontDeclNode->setAttribute("style:font-family-generic", "roman"); 106 $fontDeclNode->setAttribute("style:font-pitch", "variable"); 107 $fontDeclsNode->appendChild($fontDeclNode); 108 $fontDeclNode =& $this->xml->createElement("style:font-decl"); 109 $fontDeclNode->setAttribute("style:name", "Arial"); 110 $fontDeclNode->setAttribute("fo:font-family", "Arial"); 111 $fontDeclNode->setAttribute("style:font-family-generic", "swiss"); 112 $fontDeclNode->setAttribute("style:font-pitch", "variable"); 113 $fontDeclsNode->appendChild($fontDeclNode); 114 $docWriterNode->appendChild($fontDeclsNode); 115 116 $docWriterNode->appendChild($this->ChildText("office:automatic-styles", "")); 117 118 $bodyNode =& $this->xml->createElement("office:body"); 119 $sequenceDeclsNode =& $this->xml->createElement("office:sequence-decls"); 120 $sequenceDeclNode =& $this->xml->createElement("office:sequence-decl"); 121 $sequenceDeclNode->setAttribute("text:display-outline-level", "0"); 122 $sequenceDeclNode->setAttribute("text:name", "Illustration"); 123 $sequenceDeclsNode->appendChild($sequenceDeclNode); 124 $sequenceDeclNode =& $this->xml->createElement("office:sequence-decl"); 125 $sequenceDeclNode->setAttribute("text:display-outline-level", "0"); 126 $sequenceDeclNode->setAttribute("text:name", "Table"); 127 $sequenceDeclsNode->appendChild($sequenceDeclNode); 128 $sequenceDeclNode =& $this->xml->createElement("office:sequence-decl"); 129 $sequenceDeclNode->setAttribute("text:display-outline-level", "0"); 130 $sequenceDeclNode->setAttribute("text:name", "Text"); 131 $sequenceDeclsNode->appendChild($sequenceDeclNode); 132 $sequenceDeclNode =& $this->xml->createElement("office:sequence-decl"); 133 $sequenceDeclNode->setAttribute("text:display-outline-level", "0"); 134 $sequenceDeclNode->setAttribute("text:name", "Drawing"); 135 $sequenceDeclsNode->appendChild($sequenceDeclNode); 136 137 $pNode =& $this->xml->createElement("text:p"); 138 $pNode->setAttribute("text:style-name", "Standard"); 139 140 $bodyNode->appendChild($sequenceDeclsNode); 141 $bodyNode->appendChild($pNode); 142 143 $docWriterNode->appendChild($bodyNode); 144 145 $this->xml->setDocumentElement($docWriterNode); 146 $this->xml->setXMLDeclaration("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 147 } 148 149 function main(){ 150 echo $this->toString(); 151 } 152 153 function save(){ 154 parent::save(); 155 $this->style->save(); 156 } 157 158 function areHeader(){ 159 $this->style->addHeader(); 160 } 161 162 /** 163 * OOoWriter::addHeader() 164 * 165 * @param $argHeager 166 * @param string $pageName 167 * @return 168 **/ 169 function addHeader($argHeager, $pageName = "pm1"){ 170 $this->style->addStyleHeadFoot($argHeager, "Header", $pageName); 171 } 172 173 /** 174 * OOoWriter::addFooter() 175 * 176 * @param $argFooter 177 * @param string $pageName 178 * @return 179 **/ 180 function addFooter($argFooter, $pageName = "pm1"){ 181 $this->style->addStyleHeadFoot($argFooter, "Footer", $pageName); 182 } 183 184 /** 185 * OOoWriter::addStylePage() 186 * 187 * @param $argPage 188 * @return 189 **/ 190 function addStylePage($argPage){ 191 return $this->style->addStylePage($argPage); 192 } 193 194 /** 195 * OOoWriter::addText() 196 * 197 * @param $objText 198 * @return 199 **/ 200 function addText($objText){ 201 if ($objText->className() == strtolower("OOoText")) { 202 $automaticStylesNode = & $this->getNode("/office:document-content/office:automatic-styles"); 203 $bodyNode = & $this->getNode("/office:document-content/office:body"); 204 $objText->run($bodyNode, $automaticStylesNode, $this->DIRXML); 205 } 206 } 207 208 209 /** 210 * OOoWriter::addTable() 211 * 212 * @param $objTable 213 * @return 214 **/ 215 function addTable($objTable){ 216 if ($objTable->className() == strtolower("OOoTable")) { 217 $automaticStylesNode = & $this->getNode("/office:document-content/office:automatic-styles"); 218 $bodyNode = & $this->getNode("/office:document-content/office:body"); 219 $objTable->run($bodyNode, $automaticStylesNode, $this->DIRXML); 220 } 221 } 222 223 224 /** 225 * OOoWriter::addPage() 226 * 227 * @param $styleNamePage 228 * @return 229 **/ 230 function addPage($styleNamePage){ 231 $argPara = array( 232 "paraName" => $styleNamePage 233 ); 234 235 $para1 = new OOoText(); 236 $styleName = $para1->setStylePara($argPara); 237 238 $argText = array( 239 "NameStyle" => $styleName, 240 "Text" => "" 241 ); 242 $para1->addText($argText); 243 $automaticStylesNode = & $this->getNode("/office:document-content/office:automatic-styles"); 244 $bodyNode = & $this->getNode("/office:document-content/office:body"); 245 $para1->run($bodyNode, $automaticStylesNode, $this->DIRXML); 246 247 } 248 249 250 /** 251 * OOoWriter::addLine(), méthode permettant d'ajouter des lignes au document 252 * 253 * @param integer $num nombre de ligne à ajouter 254 * @return none 255 **/ 256 function addLine($num = 1){ 257 $bodyNode = & $this->getNode("/office:document-content/office:body"); 258 259 while ($num > 0){ 260 $pNode =& $this->xml->createElement("text:p"); 261 $pNode->setAttribute("text:style-name", "Standard"); 262 263 $bodyNode->appendChild($pNode); 264 $num--; 265 } 266 } 267} 268