ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilFileXMLWriter Class Reference

XML writer class. More...

+ Inheritance diagram for ilFileXMLWriter:
+ Collaboration diagram for ilFileXMLWriter:

Public Member Functions

 __construct ()
 constructor More...
 
 setFile (ilObjFile $file)
 
 setOmitHeader ($a_val)
 Set omit header. More...
 
 getOmitHeader ()
 Get omit header. More...
 
 setFileTargetDirectories ($a_rel, $a_abs)
 Set file target directories. More...
 
 setAttachFileContents ($attachFileContents)
 set attachment content mode More...
 
 start ()
 
 getXML ()
 
 __buildHeader ()
 
 __buildFooter ()
 
- Public Member Functions inherited from ilXmlWriter
 __construct ($version="1.0", $outEnc="utf-8", $inEnc="utf-8")
 constructor More...
 
 _ilXmlWriter ()
 destructor public More...
 
 xmlSetDtdDef ($dtdDef)
 Sets dtd definition. More...
 
 xmlSetStSheet ($stSheet)
 Sets stylesheet. More...
 
 xmlSetGenCmt ($genCmt)
 Sets generated comment. More...
 
 xmlEncodeData ($data)
 Encodes text from input encoding into output encoding. More...
 
 xmlFormatData ($data)
 Indents text for better reading. More...
 
 xmlFormatElement ($array)
 Callback function for xmlFormatData; do not invoke directly. More...
 
 xmlHeader ()
 Writes xml header public. More...
 
 xmlStartTag ($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
 Writes a starttag. More...
 
 xmlEndTag ($tag)
 Writes an endtag. More...
 
 xmlComment ($comment)
 Writes a comment. More...
 
 xmlData ($data, $encode=true, $escape=true)
 Writes data. More...
 
 xmlElement ($tag, $attrs=null, $data=null, $encode=true, $escape=true)
 Writes a basic element (no children, just textual content) More...
 
 xmlDumpFile ($file, $format=true)
 Dumps xml document from memory into a file. More...
 
 xmlDumpMem ($format=true)
 Returns xml document from memory. More...
 
 appendXML ($a_str)
 append xml string to document More...
 
 xmlClear ()
 clears xmlStr public More...
 

Data Fields

 $attachFileContents
 
 $file
 
 $omit_header = false
 
- Data Fields inherited from ilXmlWriter
 $xmlStr
 
 $version
 
 $outEnc
 
 $inEnc
 
 $dtdDef = ""
 
 $stSheet = ""
 
 $genCmt = "Generated by ILIAS XmlWriter"
 

Static Public Attributes

static $CONTENT_ATTACH_NO = 0
 
static $CONTENT_ATTACH_ENCODED = 1
 
static $CONTENT_ATTACH_ZLIB_ENCODED = 2
 
static $CONTENT_ATTACH_GZIP_ENCODED = 3
 
static $CONTENT_ATTACH_COPY = 4
 
static $CONTENT_ATTACH_REST = 5
 

Additional Inherited Members

- Static Public Member Functions inherited from ilXmlWriter
static _xmlEscapeData ($data)
 Escapes reserved characters. More...
 

Detailed Description

XML writer class.

Class to simplify manual writing of xml documents. It only supports writing xml sequentially, because the xml document is saved in a string with no additional structure information. The author is responsible for well-formedness and validity of the xml document.

Author
Roland Küstermann Rolan.nosp@m.d@ku.nosp@m.ester.nosp@m.mann.nosp@m..com
Version
Id
class.ilExerciseXMLWriter.php,v 1.3 2005/11/04 12:50:24 smeyer Exp

Definition at line 21 of file class.ilFileXMLWriter.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileXMLWriter::__construct ( )

constructor

Parameters
stringxml version
stringoutput encoding
stringinput encoding

public

Definition at line 55 of file class.ilFileXMLWriter.php.

References $CONTENT_ATTACH_NO.

56  {
57  parent::__construct();
58  $this->attachFileContents = ilFileXMLWriter::$CONTENT_ATTACH_NO;
59  }

Member Function Documentation

◆ __buildFooter()

ilFileXMLWriter::__buildFooter ( )

Definition at line 217 of file class.ilFileXMLWriter.php.

Referenced by start().

218  {
219  }
+ Here is the caller graph for this function:

◆ __buildHeader()

ilFileXMLWriter::__buildHeader ( )

Definition at line 205 of file class.ilFileXMLWriter.php.

References getOmitHeader(), ilXmlWriter\xmlHeader(), ilXmlWriter\xmlSetDtdDef(), and ilXmlWriter\xmlSetGenCmt().

Referenced by start().

206  {
207  if (!$this->getOmitHeader()) {
208  $this->xmlSetDtdDef("<!DOCTYPE File PUBLIC \"-//ILIAS//DTD FileAdministration//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_file_3_8.dtd\">");
209  $this->xmlSetGenCmt("Exercise Object");
210  $this->xmlHeader();
211  }
212 
213  return true;
214  }
xmlSetGenCmt($genCmt)
Sets generated comment.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
getOmitHeader()
Get omit header.
xmlHeader()
Writes xml header public.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOmitHeader()

ilFileXMLWriter::getOmitHeader ( )

Get omit header.

Returns
boolean omit header

Definition at line 84 of file class.ilFileXMLWriter.php.

References $omit_header.

Referenced by __buildHeader().

85  {
86  return $this->omit_header;
87  }
+ Here is the caller graph for this function:

◆ getXML()

ilFileXMLWriter::getXML ( )

Definition at line 199 of file class.ilFileXMLWriter.php.

References ilXmlWriter\xmlDumpMem().

200  {
201  return $this->xmlDumpMem(false);
202  }
xmlDumpMem($format=true)
Returns xml document from memory.
+ Here is the call graph for this function:

◆ setAttachFileContents()

ilFileXMLWriter::setAttachFileContents (   $attachFileContents)

set attachment content mode

Parameters
int$attachFileContents
Exceptions
ilExerciseExceptionif mode is not supported

Definition at line 110 of file class.ilFileXMLWriter.php.

References $attachFileContents, $CONTENT_ATTACH_GZIP_ENCODED, $CONTENT_ATTACH_ZLIB_ENCODED, and ilFileException\$ID_DEFLATE_METHOD_MISMATCH.

111  {
112  if ($attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && !function_exists("gzencode")) {
113  throw new ilFileException("Inflating with gzip is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
114  }
115  if ($attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && !function_exists("gzcompress")) {
116  throw new ilFileException("Inflating with zlib (compress/uncompress) is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
117  }
118  $this->attachFileContents = $attachFileContents;
119  }
Class to report exception.

◆ setFile()

ilFileXMLWriter::setFile ( ilObjFile  $file)

Definition at line 62 of file class.ilFileXMLWriter.php.

References $file, and file.

63  {
64  $this->file = &$file;
65  }
Reload workbook from saved file

◆ setFileTargetDirectories()

ilFileXMLWriter::setFileTargetDirectories (   $a_rel,
  $a_abs 
)

Set file target directories.

Parameters
stringrelative file target directory
stringabsolute file target directory

Definition at line 96 of file class.ilFileXMLWriter.php.

97  {
98  $this->target_dir_relative = $a_rel;
99  $this->target_dir_absolute = $a_abs;
100  }

◆ setOmitHeader()

ilFileXMLWriter::setOmitHeader (   $a_val)

Set omit header.

Parameters
booleanomit header

Definition at line 73 of file class.ilFileXMLWriter.php.

74  {
75  $this->omit_header = $a_val;
76  }

◆ start()

ilFileXMLWriter::start ( )

Definition at line 122 of file class.ilFileXMLWriter.php.

References $CONTENT_ATTACH_COPY, $CONTENT_ATTACH_GZIP_ENCODED, $CONTENT_ATTACH_REST, $CONTENT_ATTACH_ZLIB_ENCODED, $filename, ilXmlWriter\$version, __buildFooter(), __buildHeader(), ilHistory\_getEntriesForObject(), array, ilUtil\date_mysql2time(), file, ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

123  {
124  $this->__buildHeader();
125 
126  $attribs = array(
127  "obj_id" => "il_" . IL_INST_ID . "_file_" . $this->file->getId(),
128  "version" => $this->file->getVersion(),
129  "size" => $this->file->getFileSize(),
130  "type" => $this->file->getFileType(),
131  );
132 
133  $this->xmlStartTag("File", $attribs);
134  $this->xmlElement("Filename", null, $this->file->getFileName());
135 
136  $this->xmlElement("Title", null, $this->file->getTitle());
137  $this->xmlElement("Description", null, $this->file->getDescription());
138  $this->xmlElement("Rating", null, (int) $this->file->hasRating());
139 
140  if ($this->attachFileContents) {
141  $filename = $this->file->getDirectory($this->file->getVersion()) . "/" . $this->file->getFileName();
142  if (@is_file($filename)) {
143  if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_COPY) {
144  $attribs = array("mode" => "COPY");
145  copy($filename, $this->target_dir_absolute . "/" . $this->file->getFileName());
146  $content = $this->target_dir_relative . "/" . $this->file->getFileName();
147  $this->xmlElement("Content", $attribs, $content);
148  } // begin-patch fm
149  elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_REST) {
150  $attribs = array('mode' => "REST");
151  include_once './Services/WebServices/Rest/classes/class.ilRestFileStorage.php';
152  $fs = new ilRestFileStorage();
153  $tmpname = $fs->storeFileForRest(base64_encode(@file_get_contents($filename)));
154  $this->xmlElement("Content", $attribs, $tmpname);
155  } // end-patch fm
156  else {
157  $content = @file_get_contents($filename);
158  $attribs = array("mode" => "PLAIN");
159  if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED) {
160  $attribs ["mode"] = "ZLIB";
161  $content = @gzcompress($content, 9);
162  } elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED) {
163  $attribs ["mode"] = "GZIP";
164  $content = @gzencode($content, 9);
165  }
166  $content = base64_encode($content);
167  $this->xmlElement("Content", $attribs, $content);
168  }
169  }
170  }
171 
172  include_once("./Services/History/classes/class.ilHistory.php");
173 
174  $versions = ilHistory::_getEntriesForObject($this->file->getId(), $this->file->getType());
175 
176  if (count($versions)) {
177  $this->xmlStartTag("Versions");
178  foreach ($versions as $version) {
179  $info_params = $version["info_params"];
180  list($filename, $history_id) = explode(",", $info_params);
181  $attribs = array(
182  "id" => $history_id,
183  "date" => ilUtil::date_mysql2time($version["date"]),
184  "usr_id" => "il_" . IL_INST_ID . "_usr_" . $version["user_id"],
185  );
186  $this->xmlElement("Version", $attribs);
187  }
188  $this->xmlEndTag("Versions");
189  }
190 
191  $this->xmlEndTag("File");
192 
193  $this->__buildFooter();
194 
195  return true;
196  }
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
xmlEndTag($tag)
Writes an endtag.
static date_mysql2time($mysql_date_time)
make time object from mysql_date_time
Reload workbook from saved file
static _getEntriesForObject($a_obj_id, $a_obj_type="")
get all history entries for an object
Create styles array
The data for the language used.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
File storage handling.
+ Here is the call graph for this function:

Field Documentation

◆ $attachFileContents

ilFileXMLWriter::$attachFileContents

Definition at line 36 of file class.ilFileXMLWriter.php.

Referenced by setAttachFileContents().

◆ $CONTENT_ATTACH_COPY

ilFileXMLWriter::$CONTENT_ATTACH_COPY = 4
static

Definition at line 27 of file class.ilFileXMLWriter.php.

Referenced by ilFileExporter\getXmlRepresentation(), and start().

◆ $CONTENT_ATTACH_ENCODED

ilFileXMLWriter::$CONTENT_ATTACH_ENCODED = 1
static

Definition at line 24 of file class.ilFileXMLWriter.php.

◆ $CONTENT_ATTACH_GZIP_ENCODED

ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED = 3
static

Definition at line 26 of file class.ilFileXMLWriter.php.

Referenced by setAttachFileContents(), and start().

◆ $CONTENT_ATTACH_NO

ilFileXMLWriter::$CONTENT_ATTACH_NO = 0
static

Definition at line 23 of file class.ilFileXMLWriter.php.

Referenced by __construct().

◆ $CONTENT_ATTACH_REST

ilFileXMLWriter::$CONTENT_ATTACH_REST = 5
static

Definition at line 29 of file class.ilFileXMLWriter.php.

Referenced by start().

◆ $CONTENT_ATTACH_ZLIB_ENCODED

ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED = 2
static

Definition at line 25 of file class.ilFileXMLWriter.php.

Referenced by setAttachFileContents(), and start().

◆ $file

ilFileXMLWriter::$file

Definition at line 42 of file class.ilFileXMLWriter.php.

Referenced by setFile().

◆ $omit_header

ilFileXMLWriter::$omit_header = false

Definition at line 43 of file class.ilFileXMLWriter.php.

Referenced by getOmitHeader().


The documentation for this class was generated from the following file: