| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | stubClassLoader::load('net::stubbles::websites::processors::stubAbstractPageProcessor', |
|---|
| 11 | 'net::stubbles::websites::xml::stubXMLResponse', |
|---|
| 12 | 'net::stubbles::ioc::stubBinder', |
|---|
| 13 | 'net::stubbles::ipo::request::stubRequestPrefixDecorator', |
|---|
| 14 | 'net::stubbles::ipo::response::stubBaseResponse', |
|---|
| 15 | 'net::stubbles::util::stubRegistry', |
|---|
| 16 | 'net::stubbles::util::validators::stubRegexValidator', |
|---|
| 17 | 'net::stubbles::xml::stubXMLStreamWriterFactory', |
|---|
| 18 | 'net::stubbles::xml::serializer::stubXMLSerializer' |
|---|
| 19 | ); |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | class stubXMLProcessor extends stubAbstractPageProcessor |
|---|
| 27 | { |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | public function __construct(stubRequest $request, stubSession $session, stubResponse $response, stubPageFactory $pageFactory) |
|---|
| 37 | { |
|---|
| 38 | $response = new stubXMLResponse($response); |
|---|
| 39 | parent::__construct($request, $session, $response, $pageFactory); |
|---|
| 40 | $this->pageDirPrefix = 'conf/'; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | protected function doProcess(stubPage $page, $pageName) |
|---|
| 50 | { |
|---|
| 51 | $xmlSerializer = $this->createXMLSerializer(); |
|---|
| 52 | $xmlStreamWriter = $this->createXMLStreamWriter(); |
|---|
| 53 | $this->response->setPage($page); |
|---|
| 54 | $elements = $page->getElements(); |
|---|
| 55 | $xmlStreamWriter->writeStartElement('document'); |
|---|
| 56 | $xmlStreamWriter->writeAttribute('page', $pageName); |
|---|
| 57 | $this->writeSessionValues($xmlStreamWriter); |
|---|
| 58 | $prefixRequest = new stubRequestPrefixDecorator($this->request, ''); |
|---|
| 59 | $formValues = array(); |
|---|
| 60 | |
|---|
| 61 | if (stubRegistry::has(stubBinder::REGISTRY_KEY)) { |
|---|
| 62 | $injector = stubRegistry::get(stubBinder::REGISTRY_KEY)->getInjector(); |
|---|
| 63 | } else { |
|---|
| 64 | $injector = null; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | foreach ($elements as $name => $element) { |
|---|
| 68 | $prefixRequest->setPrefix($name); |
|---|
| 69 | if (null !== $injector) { |
|---|
| 70 | $injector->handleInjections($element); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | $element->init($prefixRequest, $this->session, $this->response); |
|---|
| 74 | if ($element->isAvailable() == false) { |
|---|
| 75 | continue; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | $data = $element->process(); |
|---|
| 79 | if ($prefixRequest->isCancelled() === true) { |
|---|
| 80 | return; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | $xmlSerializer->serialize($data, $xmlStreamWriter, array(stubXMLSerializer::OPT_ROOT_TAG => $name)); |
|---|
| 84 | if ($element instanceof stubXMLPageElement) { |
|---|
| 85 | $formValues[$name] = $element->getFormValues(); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | $xmlSerializer->serialize($formValues, $xmlStreamWriter, array(stubXMLSerializer::OPT_ROOT_TAG => 'forms')); |
|---|
| 90 | $this->writeRequestValues($xmlStreamWriter, $xmlSerializer); |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | if (null !== $injector) { |
|---|
| 94 | $xmlStreamWriter->writeStartElement('resources'); |
|---|
| 95 | foreach ($page->getResources() as $name => $interface) { |
|---|
| 96 | $resource = $injector->getInstance($interface); |
|---|
| 97 | $xmlSerializer->serialize($resource, $xmlStreamWriter, array(stubXMLSerializer::OPT_ROOT_TAG => $name)); |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | $xmlStreamWriter->writeEndElement(); |
|---|
| 102 | $this->response->setXMLStreamWriter($xmlStreamWriter); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | protected function writeSessionValues(stubXMLStreamWriter $xmlStreamWriter) |
|---|
| 134 | { |
|---|
| 135 | $xmlStreamWriter->writeStartElement('session'); |
|---|
| 136 | if ($this->request->acceptsCookies() === true) { |
|---|
| 137 | $xmlStreamWriter->writeElement('acceptsCookies', array(), 'true'); |
|---|
| 138 | } else { |
|---|
| 139 | $xmlStreamWriter->writeElement('acceptsCookies', array(), 'false'); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | $xmlStreamWriter->writeElement('id', array(), $this->session->getId()); |
|---|
| 143 | $xmlStreamWriter->writeElement('name', array(), stubRegistry::getConfig(stubSession::NAME_REGISTRY_KEY, stubSession::DEFAULT_SESSION_NAME)); |
|---|
| 144 | $xmlStreamWriter->writeElement('isNew', array(), (($this->session->isNew() === true) ? ('true') : ('false'))); |
|---|
| 145 | $xmlStreamWriter->writeStartElement('variant'); |
|---|
| 146 | $xmlStreamWriter->writeElement('name', array(), (string) $this->session->getValue('net.stubbles.websites.variantmanager.variant.name')); |
|---|
| 147 | $xmlStreamWriter->writeElement('alias', array(), (string) $this->session->getValue('net.stubbles.websites.variantmanager.variant.alias')); |
|---|
| 148 | $xmlStreamWriter->writeEndElement(); |
|---|
| 149 | $xmlStreamWriter->writeStartElement('token'); |
|---|
| 150 | $xmlStreamWriter->writeElement('current', array(), $this->session->getCurrentToken()); |
|---|
| 151 | $xmlStreamWriter->writeElement('next', array(), $this->session->getNextToken()); |
|---|
| 152 | $xmlStreamWriter->writeEndElement(); |
|---|
| 153 | $xmlStreamWriter->writeEndElement(); |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | protected function writeRequestValues(stubXMLStreamWriter $xmlStreamWriter, $xmlSerializer) |
|---|
| 180 | { |
|---|
| 181 | $xmlStreamWriter->writeStartElement('request'); |
|---|
| 182 | $errors = $this->request->getValueErrors(); |
|---|
| 183 | foreach ($errors as $requestValueName => $requestErrorValues) { |
|---|
| 184 | $xmlStreamWriter->writeStartElement('value'); |
|---|
| 185 | $xmlStreamWriter->writeAttribute('name', $requestValueName); |
|---|
| 186 | $xmlSerializer->serialize(array_values($requestErrorValues), $xmlStreamWriter, array(stubXMLSerializer::OPT_ROOT_TAG => 'errors')); |
|---|
| 187 | $xmlStreamWriter->writeEndElement(); |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | $xmlStreamWriter->writeEndElement(); |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | protected function createXMLStreamWriter() |
|---|
| 199 | { |
|---|
| 200 | return stubXMLStreamWriterFactory::createAsAvailable(); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | protected function createXMLSerializer() |
|---|
| 209 | { |
|---|
| 210 | $xmlSerializer = new stubXMLSerializer(); |
|---|
| 211 | return $xmlSerializer; |
|---|
| 212 | } |
|---|
| 213 | } |
|---|
| 214 | ?> |
|---|