add namespace to transactions
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Thu, 29 Jul 2010 20:39:33 +0000 (20:39 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Thu, 29 Jul 2010 20:39:33 +0000 (20:39 +0000)
git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@578 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

phpbase/exception.php
phpbase/transaction.php
woc/php/phpstrans.cpp
woc/php/phptrans.cpp
woc/proc/processor.cpp
woc/proc/processor.h

index f41c026..e4dfbc3 100644 (file)
@@ -30,7 +30,7 @@ class WobTransactionError extends Exception
        public function printXml()
        {
                header("X-WobResponse-Status: Error");
-               print("<WobError type=\"".xq($this->etype)."\">".xq($this->estr)."</WobError>\n");
+               print("<WobError xmlns=\"http://silmor.de/PACK/Error\" type=\"".xq($this->etype)."\">".xq($this->estr)."</WobError>\n");
        }
        
        /**returns the error type*/
index c3feaef..96cb2df 100644 (file)
@@ -30,12 +30,12 @@ class WobTransactionBase {
                global $_SERVER;
                if($_SERVER["REQUEST_METHOD"] != "POST"){
                        header("X-WobResponse-Status: Error");
-                       print("<WobError type=\"non-post\">".tr("Request is not a POST Request, Aborting.")."</WobError>\n");
+                       print("<WobError xmlns=\"http://silmor.de/PACK/Error\" type=\"non-post\">".tr("Request is not a POST Request, Aborting.")."</WobError>\n");
                        exit();
                }
                if(!isset($_SERVER["HTTP_X_WOBREQUEST"])){
                        header("X-WobResponse-Status: Error");
-                       print("<WobError type=\"non-wob\">".tr("Request is not a Wob Request, Aborting.")."</WobError>\n");
+                       print("<WobError xmlns=\"http://silmor.de/PACK/Error\" type=\"non-wob\">".tr("Request is not a Wob Request, Aborting.")."</WobError>\n");
                        exit();
                }
                self::$running=$_SERVER["HTTP_X_WOBREQUEST"];
@@ -104,6 +104,20 @@ class WobTransactionBase {
        protected function isAuthorized($transactioName){return false;}
        /**stub: returns the name of the user (default returns empty string)*/
        protected function userName(){return "";}
+       
+       /**internal: returns an initialized XML array ("doc"=>DomDocument, "root"=>transaction rool DomElement)*/
+       protected function xmlCreate($elem){
+               $r=array();
+               $r["doc"]=new DOMDocument;
+               $r["root"]=$r["doc"]->createElementNS($this->xmlNamespace(),$elem);
+               return $r;
+       }
+       
+       /**internal: converts XML array to string representation*/
+       protected function xmlToString($xml){
+               $xml["doc"]->appendChild($xml["root"]);
+               return $xml["doc"]->saveXml();
+       }
 };
 
 ?>
\ No newline at end of file
index 0043a96..721ad75 100644 (file)
@@ -131,8 +131,8 @@ QString WocPHPServerTransaction::trnOutput(const WocTransaction&trn)
 {
        QStringList sl=trn.outputNames();
        QString code="\t/*start of output encoding*/\n";
-       code+="\ttry{\n\t\t$xml=new DOMDocument;\n";
-       code+="\t\t$root=$xml->createElement(\"WobResponse-"+trn.name()+"\");\n";
+       code+="\ttry{\n\t\t$xml=$this->xmlCreate(\"WobResponse-"+trn.name()+"\");\n";
+       code+="\t\t$root=$xml['root'];\n";
        for(int i=0;i<sl.size();i++){
                QString t=trn.outputType(sl[i]);
                if(trn.isAttributeType(t)){
@@ -163,9 +163,8 @@ QString WocPHPServerTransaction::trnOutput(const WocTransaction&trn)
                        }
                }
        }
-       code+="\t\t$xml->appendChild($root);\n";
        code+="\t\theader(\"X-WobResponse-Status: Ok\");\n";
-       code+="\t\tprint($xml->saveXml());\n";
+       code+="\t\tprint($this->xmlToString($xml));\n";
        code+="\t}catch(Exception $e){$this->handleException($e);}\n";
        code+="\t/*end of output*/\n";
        return code;
index 1639edb..0413c4c 100644 (file)
@@ -49,6 +49,7 @@ void WocPHPTransaction::transInfo()
        m_transact.write(QString("  static public function svnVersion(){return \""+woc->svnRevision()+"\";}\n\n").toAscii());
        m_transact.write(QString("  static public function svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n\n").toAscii());
        m_transact.write(QString("  static public function svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii());
+       m_transact.write(QString("  static public function xmlNamespace(){return \""+woc->xmlNamespace()+"\";}\n\n").toAscii());
 }
 
 void WocPHPTransaction::transInfo2()
index 11cea42..40b0e33 100644 (file)
@@ -129,6 +129,7 @@ bool WocProcessor::processFile(QString fn)
                                m_wobDir=el.attribute("wobDir");
                        if(el.hasAttribute("name"))
                                m_projname=el.attribute("name");
+                       m_xmlNS=el.attribute("xml-namespace");
                }else
                if(tn=="Include"){
                        if(!processFile(m_baseDir+"/"+m_wobDir+"/"+el.attribute("file")))
index 11ff06b..3f2ddb6 100644 (file)
@@ -100,6 +100,8 @@ class WocProcessor:public QObject
                QString dbSchema()const{return m_dbSchema;}
                /**returns the database schema version*/
                QString dbVersion()const{return m_dbVer;}
+               /**returns the XML namespace of the project*/
+               QString xmlNamespace()const{return m_xmlNS;}
                
                /**returns whether a table exists*/
                bool hasTable(QString)const;
@@ -134,7 +136,7 @@ class WocProcessor:public QObject
        private:
                QString m_baseDir,m_wobDir,m_verComm,m_verNeedComm,m_verHR,m_projname;
                QString m_svnTarget,m_svnRev,m_svnExe,m_svnRoot,m_svnUrl;
-               QString m_dbInst,m_dbSchema,m_dbVer;
+               QString m_dbInst,m_dbSchema,m_dbVer,m_xmlNS;
                QStringList m_docstrings;
                bool m_error,m_dbUpd;