19 require_once(BASE.
"wcmf/lib/output/class.OutputStrategy.php");
20 require_once(BASE.
"wcmf/lib/util/class.FileUtil.php");
21 require_once(BASE.
"wcmf/lib/util/class.Log.php");
54 function XMLOutputStrategy($file, $docType, $dtd, $encoding=
'UTF-8', $indent=2, $linebreak=
"\n")
57 $this->_docType = $docType;
59 $this->_encoding = $encoding;
60 $this->_indent = str_repeat(
' ', $indent);
61 $this->_linebreak = $linebreak;
62 $this->_tagsToClose = array();
63 $this->_fileOk =
false;
71 if (file_exists($this->_file))
73 $this->_fp = fopen($this->_file,
"r");
76 Log::warn(
"Can't write to file ".$this->_file.
". Another user holds the lock. Try again later.", __CLASS__);
83 $this->_fp = fopen($this->_file,
"w");
86 if(!flock ($this->_fp, LOCK_EX))
87 Log::warn(
"Can't lock file ".$this->_file.
". Proceeding without.", __CLASS__);
89 $this->_fileOk =
true;
90 $this->
writeToFile(
'<?xml version="1.0" encoding="'.$this->_encoding.
'"?>'.$this->_linebreak.
'<!DOCTYPE '.$this->_docType.
' SYSTEM "'.$this->_dtd.
'">'.$this->_linebreak);
102 for ($i=0;$i<sizeOf($this->_tagsToClose);$i++)
104 $closeTag = $this->_tagsToClose[$i];
105 $this->
writeToFile(str_repeat($this->_indent, $closeTag[
"indent"]).
'</'.$closeTag[
"name"].
'>'.$this->_linebreak);
107 flock ($this->_fp, LOCK_UN);
119 $curIndent = $obj->getDepth();
120 if ($curIndent < $this->_lastIndent)
123 for ($i=$this->_lastIndent-$curIndent;$i>0;$i--)
125 $closeTag = array_shift($this->_tagsToClose);
126 $this->
writeToFile(str_repeat($this->_indent, $closeTag[
"indent"]).
'</'.$closeTag[
"name"].
'>'.$this->_linebreak);
133 if ($obj->getNumChildren() > 0)
135 $closeTag = array(
"name" => $tagName,
"indent" => $curIndent);
136 array_unshift($this->_tagsToClose, $closeTag);
141 $this->
writeToFile(
'</'.$tagName.
'>'.$this->_linebreak);
144 $this->_lastIndent = $curIndent;
155 fputs($this->_fp, $text);
169 $this->
writeToFile(str_repeat($this->_indent, $curIndent).
'<'.$elementName);
177 foreach ($attributeNames as $curAttribute)
182 if ($obj->getNumChildren() > 0)
187 foreach ($elementNames as $curElement)
224 return $obj->getType();
237 return htmlspecialchars(preg_replace(
"/\r\n|\n\r|\n|\r/",
"<br />", $value));
276 return htmlspecialchars(preg_replace(
"/\r\n|\n\r|\n|\r/",
"<br />", $value));
writeObjectContent(&$obj, $curIndent)
warn($message, $category)
OutputStrategy is used to write an object's content to a destination (called 'document') using a spec...
writeElement(&$obj, $name)
XMLOutputStrategy($file, $docType, $dtd, $encoding='UTF-8', $indent=2, $linebreak="\n")
This OutputStrategy outputs an object's content in a xml file using the default format.
writeAttribute(&$obj, $name)
getAttributeName(&$obj, $name)
getAttributeValue(&$obj, $name, $value)
getElementValue(&$obj, $name, $value)