ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilFileXMLWriter Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. 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 (?string $a_rel, ?string $a_abs)
 Set file target directories. More...
 
 setAttachFileContents (int $attachFileContents)
 set attachment content mode More...
 
 start ()
 
 getXML ()
 
 __buildHeader ()
 
 __buildFooter ()
 
- Public Member Functions inherited from ilXmlWriter
 __construct (string $version="1.0", string $outEnc="utf-8", string $inEnc="utf-8")
 
 xmlSetDtdDef (string $dtdDef)
 Sets dtd definition. More...
 
 xmlSetGenCmt (string $genCmt)
 Sets generated comment. More...
 
 xmlFormatData (string $data)
 Indents text for better reading. More...
 
 xmlHeader ()
 Writes xml header. More...
 
 xmlStartTag (string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
 Writes a starttag. More...
 
 xmlEndTag (string $tag)
 Writes an endtag. More...
 
 xmlData (string $data, bool $encode=true, bool $escape=true)
 Writes data. More...
 
 xmlElement (string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
 Writes a basic element (no children, just textual content) More...
 
 xmlDumpFile (string $file, bool $format=true)
 Dumps xml document from memory into a file. More...
 
 xmlDumpMem (bool $format=true)
 Returns xml document from memory. More...
 
 appendXML (string $a_str)
 append xml string to document More...
 
 xmlClear ()
 clears xmlStr More...
 

Data Fields

int $attachFileContents
 
ilObjFile $file
 Exercise Object. More...
 
 $omit_header = false
 

Static Public Attributes

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

Protected Attributes

string $target_dir_relative = null
 
string $target_dir_absolute = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 33 of file class.ilFileXMLWriter.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileXMLWriter::__construct ( )

constructor

Parameters
stringxml version
stringoutput encoding
stringinput encoding

public

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

References $CONTENT_ATTACH_NO, and ILIAS\GlobalScreen\Provider\__construct().

66  {
68  $this->attachFileContents = ilFileXMLWriter::$CONTENT_ATTACH_NO;
69  }
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ __buildFooter()

ilFileXMLWriter::__buildFooter ( )

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

Referenced by start().

231  : void
232  {
233  }
+ Here is the caller graph for this function:

◆ __buildHeader()

ilFileXMLWriter::__buildHeader ( )

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

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

Referenced by start().

219  : bool
220  {
221  if (!$this->getOmitHeader()) {
222  $this->xmlSetDtdDef("<!DOCTYPE File PUBLIC \"-//ILIAS//DTD FileAdministration//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_file_3_8.dtd\">");
223  $this->xmlSetGenCmt("Exercise Object");
224  $this->xmlHeader();
225  }
226 
227  return true;
228  }
xmlSetGenCmt(string $genCmt)
Sets generated comment.
getOmitHeader()
Get omit header.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
xmlHeader()
Writes xml header.
+ 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 94 of file class.ilFileXMLWriter.php.

References $omit_header.

Referenced by __buildHeader().

94  : bool
95  {
96  return $this->omit_header;
97  }
+ Here is the caller graph for this function:

◆ getXML()

ilFileXMLWriter::getXML ( )

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

References ilXmlWriter\xmlDumpMem().

213  : string
214  {
215  return $this->xmlDumpMem(false);
216  }
xmlDumpMem(bool $format=true)
Returns xml document from memory.
+ Here is the call graph for this function:

◆ setAttachFileContents()

ilFileXMLWriter::setAttachFileContents ( int  $attachFileContents)

set attachment content mode

Exceptions
ilExerciseExceptionif mode is not supported

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

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

119  : void
120  {
121  if ($attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && !function_exists("gzencode")) {
122  throw new ilFileException("Inflating with gzip is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
123  }
124  if ($attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && !function_exists("gzcompress")) {
125  throw new ilFileException("Inflating with zlib (compress/uncompress) is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
126  }
127  $this->attachFileContents = $attachFileContents;
128  }
static int $CONTENT_ATTACH_GZIP_ENCODED
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static int $ID_DEFLATE_METHOD_MISMATCH
static int $CONTENT_ATTACH_ZLIB_ENCODED

◆ setFile()

ilFileXMLWriter::setFile ( ilObjFile  $file)

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

References $file.

72  : void
73  {
74  $this->file = &$file;
75  }
ilObjFile $file
Exercise Object.

◆ setFileTargetDirectories()

ilFileXMLWriter::setFileTargetDirectories ( ?string  $a_rel,
?string  $a_abs 
)

Set file target directories.

Parameters
stringrelative file target directory
stringabsolute file target directory

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

106  : void
107  {
108  $this->target_dir_relative = $a_rel;
109  $this->target_dir_absolute = $a_abs;
110  }

◆ setOmitHeader()

ilFileXMLWriter::setOmitHeader (   $a_val)

Set omit header.

Parameters
booleanomit header

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

83  : void
84  {
85  $this->omit_header = $a_val;
86  }

◆ start()

ilFileXMLWriter::start ( )

Definition at line 131 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(), IL_INST_ID, ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

131  : bool
132  {
133  $this->__buildHeader();
134 
135  $attribs = array(
136  "obj_id" => "il_" . IL_INST_ID . "_file_" . $this->file->getId(),
137  "version" => $this->file->getVersion(),
138  "max_version" => $this->file->getMaxVersion(),
139  "size" => $this->file->getFileSize(),
140  "type" => $this->file->getFileType(),
141  "action" => $this->file->getAction(),
142  );
143 
144  $this->xmlStartTag("File", $attribs);
145  $this->xmlElement("Filename", null, $this->file->getFileName());
146 
147  $this->xmlElement("Title", null, $this->file->getTitle());
148  $this->xmlElement("Description", null, $this->file->getDescription());
149  $this->xmlElement("Rating", null, (int) $this->file->hasRating());
150 
151  $versions = $this->file->getVersions();
152 
153  if ($versions !== []) {
154  $this->xmlStartTag("Versions");
155 
156  foreach ($versions as $version) {
157  $attribs = array(
158  "version" => $version["version"],
159  "max_version" => $version["max_version"],
160  "date" => strtotime($version["date"]),
161  "usr_id" => "il_" . IL_INST_ID . "_usr_" . $version["user_id"],
162  "action" => $version["action"],
163  "rollback_version" => $version["rollback_version"],
164  "rollback_user_id" => $version["rollback_user_id"],
165  );
166 
167  $content = "";
168 
169  if ($this->attachFileContents !== 0) {
170  $filename = $this->file->getFile($version["version"]);
171 
172  if (@is_file($filename)) {
173  if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_COPY) {
174  $attribs ["mode"] = "COPY";
175  $content = "/" . $version["version"] . "_" . $this->file->getFileName();
176  copy($filename, $this->target_dir_absolute . $content);
177  $content = $this->target_dir_relative . $content;
178  } // begin-patch fm
179  elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_REST) {
180  $attribs ['mode'] = "REST";
181  $fs = new ilRestFileStorage();
182  $content = $fs->storeFileForRest(base64_encode(@file_get_contents($filename)));
183  ;
184  } // end-patch fm
185  else {
186  $content = @file_get_contents($filename);
187  $attribs ["mode"] = "PLAIN";
188  if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED) {
189  $attribs ["mode"] = "ZLIB";
190  $content = @gzcompress($content, 9);
191  } elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED) {
192  $attribs ["mode"] = "GZIP";
193  $content = @gzencode($content, 9);
194  }
195  $content = base64_encode($content);
196  }
197  }
198  }
199 
200  $this->xmlElement("Version", $attribs, $content);
201  }
202  $this->xmlEndTag("Versions");
203  }
204 
205  $this->xmlEndTag("File");
206 
207  $this->__buildFooter();
208 
209  return true;
210  }
const IL_INST_ID
Definition: constants.php:40
static int $CONTENT_ATTACH_GZIP_ENCODED
xmlEndTag(string $tag)
Writes an endtag.
static int $CONTENT_ATTACH_COPY
$filename
Definition: buildRTE.php:78
File storage handling.
static int $CONTENT_ATTACH_REST
static int $CONTENT_ATTACH_ZLIB_ENCODED
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
+ Here is the call graph for this function:

Field Documentation

◆ $attachFileContents

int ilFileXMLWriter::$attachFileContents

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

Referenced by setAttachFileContents().

◆ $CONTENT_ATTACH_COPY

int ilFileXMLWriter::$CONTENT_ATTACH_COPY = 4
static

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

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

◆ $CONTENT_ATTACH_ENCODED

int ilFileXMLWriter::$CONTENT_ATTACH_ENCODED = 1
static

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

◆ $CONTENT_ATTACH_GZIP_ENCODED

int ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED = 3
static

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

Referenced by setAttachFileContents(), and start().

◆ $CONTENT_ATTACH_NO

int ilFileXMLWriter::$CONTENT_ATTACH_NO = 0
static

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

Referenced by __construct().

◆ $CONTENT_ATTACH_REST

int ilFileXMLWriter::$CONTENT_ATTACH_REST = 5
static

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

Referenced by start().

◆ $CONTENT_ATTACH_ZLIB_ENCODED

int ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED = 2
static

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

Referenced by setAttachFileContents(), and start().

◆ $file

ilObjFile ilFileXMLWriter::$file

Exercise Object.

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

Referenced by setFile().

◆ $omit_header

ilFileXMLWriter::$omit_header = false

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

Referenced by getOmitHeader().

◆ $target_dir_absolute

string ilFileXMLWriter::$target_dir_absolute = null
protected

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

◆ $target_dir_relative

string ilFileXMLWriter::$target_dir_relative = null
protected

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


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