00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00024 class SInput extends SObject
00025 {
00026 protected $source;
00027 protected $xmlObj;
00028 protected $options;
00029 protected $parent;
00030 protected $name;
00031
00039 public function doc() {
00040 return "An instance of SInput is generated each time you load"
00041 . " content into PageRender2."
00042 . " Each input object has an identifying name"
00043 . " and provides source and options to a translator.";
00044 }
00045
00057 public function __construct ($source, $options, $parent = array(), $name = "")
00058 {
00059 $this->source = $source;
00060 $this->options = $options;
00061 $this->parent = $parent;
00062 $this->name = $name;
00063 }
00064
00065 public function getXmlObj ()
00066 { return $this->xmlObj; }
00067
00068 public function getSource ()
00069 { return $this->source; }
00070
00071 public function setSource ($source)
00072 { $this->source = $source; }
00073
00074 public function getName ()
00075 { return $this->name; }
00076
00084 public function translate () {
00085
00086 if ($this->hasError()) {
00087 $this->setPrettyError('translate', "can't translate an input with previously logged errors.");
00088 return false;
00089 }
00090
00091
00092 $trans_class = $this->getOption('translator_' . $this->getOption('inFormat'));
00093
00094 $translator = $this->parent->getClassInstance($trans_class);
00095
00096
00097 if ($translator === false) {
00098 $this->setPrettyError('translate', "Can't initiate translate: translation class not found.");
00099 return false;
00100 }
00101
00102
00103 if ($translator->getInFormat() != $this->getOption('inFormat')) {
00104 $this->setError("Format mismatch: translator $trans_class input format (" . $translator->getInFormat()
00105 . ") does not match requested input format (" . $this->getOption('inFormat') . ")."
00106 . " Either the translator is incorrectly named, or it has not properly declared"
00107 . " its input/output types.");
00108 return false;
00109 }
00110
00111
00112 if ($translator->getOutFormat() != $this->parent->getPage()->getFormat()) {
00113 $this->setError("Format mismatch: translator $trans_class output format (" . $translator->getOutFormat()
00114 . ") does not match page output format (" . $this->parent->getPage()->getFormat() . ")."
00115 . " Either the translator is incorrectly named, or it has not properly declared"
00116 . " its input/output types.");
00117 return false;
00118 }
00119
00120
00121
00122 $translator->setInputOptions($this->options);
00123
00124
00125 $result = $translator->translate($this);
00126
00127
00128 $this->getWarningFrom($translator);
00129
00130
00131 if ($result === false || $translator->hasError()) {
00132 $this->setPrettyError('translate', "there was an error translating the input using "
00133 . get_class($translator) . ".");
00134 $this->setError($translator->getError());
00135 $translator->resetError();
00136 $translator->resetWarning();
00137 return false;
00138 }
00139
00140 return true;
00141 }
00142
00143
00144
00145
00146 public function sendError ($errArr)
00147 { $this->parent->sendError('SInput', $this->name, $errArr); }
00148
00149 public function getOption ($key)
00150 { if (isset($this->options[$key])) {return $this->options[$key];}
00151 else return $this->parent->getDefault($key);
00152 }
00153
00154 public function getDefault ($key)
00155 { return $this->parent->getDefault($key); }
00156
00164 public function getPageRender() {
00165 return $this->parent;
00166 }
00167 }
00168
00169
00170
00171 ?>