getRootName() public method

get the name of the root tag
public getRootName ( ) : string
return string $rootName
 /**
  * Test extracting the root name
  */
 public function testRootName()
 {
     $u = new XML_Unserializer();
     $xml = '<xml>data</xml>';
     $u->unserialize($xml);
     $this->assertEquals('xml', $u->getRootName());
 }
Ejemplo n.º 2
0
 function __construct($gmlSource)
 {
     parent::__construct();
     include_once "libs/class_xml_check.php";
     $check = new XML_check();
     if ($check->check_string($gmlSource)) {
         print "GML is well-formed\n";
         //print("Elements      : ".$check->get_xml_elements());
         //print("Attributes    : ".$check->get_xml_attributes());
         //print("Size          : ".$check->get_xml_size());
         //print("Text sections : ".$check->get_xml_text_sections());
         //print("Text size     : ".$check->get_xml_text_size());
     } else {
         print "GML is not well-formed. ";
         print $check->get_full_error() . "\n";
         print "Script terminated\n";
         die;
     }
     $this->gmlSource = $gmlSource;
     $this->gmlCon = new gmlConverter();
     require_once "XML/Unserializer.php";
     $unserializer_options = array('parseAttributes' => TRUE);
     $unserializer = new XML_Unserializer($unserializer_options);
     // Serialize the data structure
     $status = $unserializer->unserialize($this->gmlSource);
     $this->gmlArray = $unserializer->getUnserializedData();
     print date('l jS \\of F Y h:i:s A') . " GML serialized\n";
     // Check if XML is a ServiceException
     if ($unserializer->getRootName() == "ServiceExceptionReport") {
         print "The server returned an exception:\n";
         print $this->gmlSource . "\n";
         print "Script terminated\n";
         die;
     }
 }
Ejemplo n.º 3
0
 /**
  * The ProcessXmlData function creates a DOM object representation of the
  * XML document received from Google Checkout. It then evaluates the root 
  * tag of the document to determine which function should handle the document.
  *
  * This function routes the XML responses that Google Checkout sends in 
  * response to API requests. These replies are sent to one of the other 
  * functions in this library.
  *
  * This function also routes Merchant Calculations API requests and
  * Notification API requests. Those requests are processed by functions
  * in the MerchantCalculationsAPIFunctions.php and 
  * NotificationAPIFunctions.php libraries, respectively.
  *
  * @param    $xml_data    The XML document sent by the Google Checkout server.
  */
 function ProcessXmlData($xml_response)
 {
     $unserializer = new XML_Unserializer();
     $rslt = $unserializer->unserialize($xml_response);
     $dom_data_root = $unserializer->getUnserializedData();
     $message_recognizer = $unserializer->getRootName();
     $sn = '';
     if (preg_match('/serial-number="([\\d\\-]+)">/i', $xml_response, $matches)) {
         $sn = $matches[1];
     }
     //$this->LogMessage ("Google Checkout: ProcessXmlData: " . "<br />" . nl2br(htmlspecialchars($xml_response)), $debug_only_msg = true);
     $this->LogMessage("Google Checkout: ProcessXmlData: " . "\n" . $xml_response, $debug_only_msg = true);
     /*
      * Select the appropriate function to handle the XML document
      * by evaluating the root tag of the document. Functions to
      * handle the following types of responses are contained in
      * this document:
      *     <request-received>
      *     <error>
      *     <diagnosis>
      *     <checkout-redirect>
      *
      * This function routes the following types of responses
      * to the MerchantCalculationsAPIFunctions.php file:
      *     <merchant-calculation-callback>
      *
      * This function routes the following types of responses
      * to the NotificationAPIFunctions.php file:
      *     <new-order-notification>
      *     <order-state-change-notification>
      *     <charge-amount-notification>
      *     <chargeback-amount-notification>
      *     <refund-amount-notification>
      *     <risk-information-notification>
      * 
      */
     switch ($message_recognizer) {
         // <request-received> received
         case "request-received":
             $this->ProcessRequestReceivedResponse($dom_data_root, $sn);
             break;
             // <error> received
         // <error> received
         case "error":
             $this->ProcessErrorResponse($dom_data_root, $sn);
             break;
             // <diagnosis> received
         // <diagnosis> received
         case "diagnosis":
             $this->ProcessDiagnosisResponse($dom_data_root, $sn);
             break;
             // <checkout-redirect> received
         // <checkout-redirect> received
         case "checkout-redirect":
             $this->ProcessCheckoutRedirect($dom_data_root, $sn);
             break;
             /*
              * +++ CHANGE ME +++
              * The following case is only for partners who are implementing 
              * the Merchant Calculations API. If you are not implementing 
              * the Merchant Calculations API, you may ignore this case.
              */
             // <merchant-calculation-callback> received
         /*
          * +++ CHANGE ME +++
          * The following case is only for partners who are implementing 
          * the Merchant Calculations API. If you are not implementing 
          * the Merchant Calculations API, you may ignore this case.
          */
         // <merchant-calculation-callback> received
         case "merchant-calculation-callback":
             $this->ProcessMerchantCalculationCallback($dom_data_root, $sn);
             break;
             /*
              * +++ CHANGE ME +++
              * The following cases are only for partners who are
              * implementing the Notification API. If you are not
              * implementing the Notification API, you may ignore
              * the remaining cases in this function.
              */
             // <new-order-notification> received
         /*
          * +++ CHANGE ME +++
          * The following cases are only for partners who are
          * implementing the Notification API. If you are not
          * implementing the Notification API, you may ignore
          * the remaining cases in this function.
          */
         // <new-order-notification> received
         case "new-order-notification":
             $this->ProcessNewOrderNotification($dom_data_root, $sn);
             break;
             // <order-state-change-notification> received
         // <order-state-change-notification> received
         case "order-state-change-notification":
             $this->ProcessOrderStateChangeNotification($dom_data_root, $sn);
             break;
             // <charge-amount-notification> received
         // <charge-amount-notification> received
         case "charge-amount-notification":
             $this->ProcessChargeAmountNotification($dom_data_root, $sn);
             break;
             // <chargeback-amount-notification> received
         // <chargeback-amount-notification> received
         case "chargeback-amount-notification":
             $this->ProcessChargebackAmountNotification($dom_data_root, $sn);
             break;
             // <refund-amount-notification> received
         // <refund-amount-notification> received
         case "refund-amount-notification":
             $this->ProcessRefundAmountNotification($dom_data_root, $sn);
             break;
             // <risk-information-notification> received
         // <risk-information-notification> received
         case "risk-information-notification":
             $this->ProcessRiskInformationNotification($dom_data_root, $sn);
             break;
             // <subscription-request-received> received
         // <subscription-request-received> received
         case "subscription-request-received":
             $this->ProcessRebillingNotification($dom_data_root, $sn);
             break;
             // <cancelled-subscription-notification> received
         // <cancelled-subscription-notification> received
         case "cancelled-subscription-notification":
             $this->ProcessCancellationNotification($dom_data_root, $sn);
             break;
             /*
              * None of the above: The message is not recognized. 
              * You should not remove this case.
              */
         /*
          * None of the above: The message is not recognized. 
          * You should not remove this case.
          */
         default:
             $this->SendNotificationAcknowledgment($sn);
             return array('error-message' => "Google Checkout ProcessXmlData: The message is not recognized.");
             break;
     }
     return $dom_data_root;
 }
Ejemplo n.º 4
0
$level = 0;
$depth = 0;
$tables = array();
$fields = array();
$wheres = array();
$limits = array();
$unserializer_options = array('parseAttributes' => TRUE, 'typeHints' => FALSE);
$unserializer = new XML_Unserializer($unserializer_options);
// Post method is used
if ($HTTP_RAW_POST_DATA) {
    Log::write($HTTP_RAW_POST_DATA);
    $HTTP_RAW_POST_DATA = dropNameSpace($HTTP_RAW_POST_DATA);
    //makeExceptionReport($HTTP_RAW_POST_DATA);
    $status = $unserializer->unserialize($HTTP_RAW_POST_DATA);
    $arr = $unserializer->getUnserializedData();
    $request = $unserializer->getRootName();
    switch ($request) {
        case "GetFeature":
            $transaction = false;
            if (!is_array($arr['Query'][0])) {
                $arr['Query'] = array(0 => $arr['Query']);
            }
            for ($i = 0; $i < sizeof($arr['Query']); $i++) {
                if (!is_array($arr['Query'][$i]['PropertyName'])) {
                    $arr['Query'][$i]['PropertyName'] = array(0 => $arr['Query'][$i]['PropertyName']);
                }
            }
            $HTTP_FORM_VARS["REQUEST"] = "GetFeature";
            foreach ($arr['Query'] as $queries) {
                $queries['typeName'] = dropAllNameSpaces($queries['typeName']);
                $HTTP_FORM_VARS["TYPENAME"] .= $queries['typeName'] . ",";
Ejemplo n.º 5
0
 function wfs_server()
 {
     // Manually tested this piece of code in order to check the requests.
     // Code based on a similar idea but build in Java
     header('Content-Type:text/xml; charset=UTF-8', TRUE);
     header('Connection:close', TRUE);
     //$userFromUri = "mhoegh"; // for testing
     logfile::write($userFromUri . "\n\n");
     // We connect to the users db
     $postgisdb = $userFromUri;
     $srs = $srsFromUri;
     $postgisschema = $schemaFromUri;
     $postgisObject = new postgis();
     //$user = new users($userFromUri);
     //$version = new version($user);
     $geometryColumnsObj = new GeometryColumns();
     function microtime_float()
     {
         list($utime, $time) = explode(" ", microtime());
         return (double) $utime + (double) $time;
     }
     $startTime = microtime_float();
     //ini_set("display_errors", "On");
     $thePath = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REDIRECT_URL'];
     //$thePath= "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
     $server = "http://" . $_SERVER['SERVER_NAME'];
     $BBox = null;
     //end added
     $currentTable = null;
     $currentTag = null;
     $gen = array();
     $gen[0] = "";
     $level = 0;
     $depth = 0;
     $tables = array();
     $fields = array();
     $wheres = array();
     $limits = array();
     logfile::write("\nRequest\n\n");
     logfile::write($HTTP_RAW_POST_DATA . "\n\n");
     $unserializer_options = array('parseAttributes' => TRUE, 'typeHints' => FALSE);
     $unserializer = new XML_Unserializer($unserializer_options);
     /*$HTTP_RAW_POST_DATA = '<?xml version="1.0" encoding="utf-8"?><wfs:Transaction service="WFS" version="1.0.0" xmlns="http://www.opengis.net/wfs" xmlns:mrhg="http://twitter/mrhg" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><wfs:Insert idgen="GenerateNew"><mrhg:hej><the_geom><gml:MultiPolygon srsName="urn:x-ogc:def:crs:EPSG:6.9:4326"><gml:polygonMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:coordinates>5.0657329559,-41.1107215881 8.4824724197,-39.3435783386 4.3241734505,-34.6001853943 5.0657329559,-41.1107215881 </gml:coordinates></gml:LinearRing></gml:exterior></gml:Polygon></gml:polygonMember></gml:MultiPolygon></the_geom></mrhg:hej></wfs:Insert></wfs:Transaction>';*/
     /*$HTTP_RAW_POST_DATA = '<?xml version="1.0"?><DescribeFeatureType  version="1.1.0"  service="WFS"  xmlns="http://www.opengis.net/wfs"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">    <TypeName>california_coastline</TypeName></DescribeFeatureType>';
      */
     // Post method is used
     if ($HTTP_RAW_POST_DATA) {
         //$forUseInSpatialFilter = $HTTP_RAW_POST_DATA; // We store a unaltered version of the raw request
         $HTTP_RAW_POST_DATA = dropNameSpace($HTTP_RAW_POST_DATA);
         logfile::write($HTTP_RAW_POST_DATA . "\n\n");
         $status = $unserializer->unserialize($HTTP_RAW_POST_DATA);
         $arr = $unserializer->getUnserializedData();
         $request = $unserializer->getRootName();
         //print_r($arr);
         switch ($request) {
             case "GetFeature":
                 if (!is_array($arr['Query'][0])) {
                     $arr['Query'] = array(0 => $arr['Query']);
                 }
                 for ($i = 0; $i < sizeof($arr['Query']); $i++) {
                     if (!is_array($arr['Query'][$i]['PropertyName'])) {
                         $arr['Query'][$i]['PropertyName'] = array(0 => $arr['Query'][$i]['PropertyName']);
                     }
                 }
                 $HTTP_FORM_VARS["REQUEST"] = "GetFeature";
                 foreach ($arr['Query'] as $queries) {
                     $HTTP_FORM_VARS["TYPENAME"] .= $queries['typeName'] . ",";
                     if ($queries['PropertyName'][0]) {
                         foreach ($queries['PropertyName'] as $PropertyNames) {
                             // We check if typeName is prefix and add it if its not
                             if (strpos($PropertyNames, ".")) {
                                 $HTTP_FORM_VARS["PROPERTYNAME"] .= $PropertyNames . ",";
                             } else {
                                 $HTTP_FORM_VARS["PROPERTYNAME"] .= $queries['typeName'] . "." . $PropertyNames . ",";
                             }
                         }
                     }
                     if (is_array($queries['Filter']) && $arr['version'] == "1.0.0") {
                         @($checkXml = simplexml_load_string($queries['Filter']));
                         if ($checkXml === FALSE) {
                             makeExceptionReport("Filter is not valid");
                         }
                         $wheres[$queries['typeName']] = parseFilter($queries['Filter'], $queries['typeName']);
                     }
                 }
                 $HTTP_FORM_VARS["TYPENAME"] = dropLastChrs($HTTP_FORM_VARS["TYPENAME"], 1);
                 $HTTP_FORM_VARS["PROPERTYNAME"] = dropLastChrs($HTTP_FORM_VARS["PROPERTYNAME"], 1);
                 break;
             case "DescribeFeatureType":
                 $HTTP_FORM_VARS["REQUEST"] = "DescribeFeatureType";
                 $HTTP_FORM_VARS["TYPENAME"] = $arr['TypeName'];
                 //if (!$HTTP_FORM_VARS["TYPENAME"]) $HTTP_FORM_VARS["TYPENAME"] = $arr['typeName'];
                 break;
             case "GetCapabilities":
                 $HTTP_FORM_VARS["REQUEST"] = "GetCapabilities";
                 break;
             case "Transaction":
                 $HTTP_FORM_VARS["REQUEST"] = "Transaction";
                 if (isset($arr["Insert"])) {
                     $transactionType = "Insert";
                 }
                 if ($arr["Update"]) {
                     $transactionType = "update";
                 }
                 if ($arr["Delete"]) {
                     $transactionType = "Delete";
                 }
                 break;
         }
     } else {
         if (sizeof($_GET) > 0) {
             logfile::write($_SERVER['QUERY_STRING'] . "\n\n");
             $HTTP_FORM_VARS = $_GET;
             $HTTP_FORM_VARS = array_change_key_case($HTTP_FORM_VARS, CASE_UPPER);
             // Make keys case insensative
             $HTTP_FORM_VARS["TYPENAME"] = dropNameSpace($HTTP_FORM_VARS["TYPENAME"]);
             // We remove name space, so $where will get key without it.
             if ($HTTP_FORM_VARS['FILTER']) {
                 @($checkXml = simplexml_load_string($HTTP_FORM_VARS['FILTER']));
                 if ($checkXml === FALSE) {
                     makeExceptionReport("Filter is not valid");
                 }
                 //$forUseInSpatialFilter = $HTTP_FORM_VARS['FILTER'];
                 $status = $unserializer->unserialize(dropNameSpace($HTTP_FORM_VARS['FILTER']));
                 $arr = $unserializer->getUnserializedData();
                 $wheres[$HTTP_FORM_VARS['TYPENAME']] = parseFilter($arr, $HTTP_FORM_VARS['TYPENAME']);
             }
         } else {
             $HTTP_FORM_VARS = array("");
         }
     }
     //HTTP_FORM_VARS is set in script if POST is used
     $HTTP_FORM_VARS = array_change_key_case($HTTP_FORM_VARS, CASE_UPPER);
     // Make keys case
     $HTTP_FORM_VARS["TYPENAME"] = dropNameSpace($HTTP_FORM_VARS["TYPENAME"]);
     $tables = explode(",", $HTTP_FORM_VARS["TYPENAME"]);
     $properties = explode(",", dropNameSpace($HTTP_FORM_VARS["PROPERTYNAME"]));
     $featureids = explode(",", $HTTP_FORM_VARS["FEATUREID"]);
     $bbox = explode(",", $HTTP_FORM_VARS["BBOX"]);
     // Start HTTP basic authentication
     //if(!$_SESSION["oauth_token"]) {
     $auth = $postgisObject->getGeometryColumns($postgisschema . "." . $HTTP_FORM_VARS["TYPENAME"], "authentication");
     //}
     // End HTTP basic authentication
     print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     ob_start();
     if (!empty($properties[0])) {
         foreach ($properties as $property) {
             $__u = explode(".", $property);
             // Is it "/" for get method?
             // We first check if typeName is namespace
             if ($__u[1]) {
                 foreach ($tables as $table) {
                     if ($table == $__u[0]) {
                         $fields[$table] .= $__u[1] . ",";
                     }
                 }
             } else {
                 foreach ($tables as $table) {
                     $fields[$table] .= $property . ",";
                 }
             }
         }
     }
     if (!empty($featureids[0])) {
         foreach ($featureids as $featureid) {
             $__u = explode(".", $featureid);
             foreach ($tables as $table) {
                 $primeryKey = $postgisObject->getPrimeryKey($postgisschema . "." . $table);
                 if ($table == $__u[0]) {
                     $wheresArr[$table][] = "{$primeryKey['attname']}={$__u[1]}";
                 }
                 $wheres[$table] = implode(" OR ", $wheresArr[$table]);
             }
         }
     }
     //get the request
     switch (strtoupper($HTTP_FORM_VARS["REQUEST"])) {
         case "GETCAPABILITIES":
             getCapabilities($postgisObject);
             break;
         case "GETFEATURE":
             if (!$gmlFeatureCollection) {
                 $gmlFeatureCollection = "wfs:FeatureCollection";
             }
             print "<" . $gmlFeatureCollection . "\n";
             print "xmlns=\"http://www.opengis.net/wfs\"\n";
             print "xmlns:wfs=\"http://www.opengis.net/wfs\"\n";
             print "xmlns:gml=\"http://www.opengis.net/gml\"\n";
             print "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
             print "xmlns:{$gmlNameSpace}=\"{$gmlNameSpaceUri}\"\n";
             if ($gmlSchemaLocation) {
                 print "xsi:schemaLocation=\"{$gmlSchemaLocation}\"";
             } else {
                 //print "xsi:schemaLocation=\"{$gmlNameSpaceUri} {$thePath}?REQUEST=DescribeFeatureType&amp;TYPENAME=".$HTTP_FORM_VARS["TYPENAME"]." http://www.opengis.net/wfs ".str_replace("server.php","",$thePath)."schemas/wfs/1.0.0/WFS-basic.xsd\"";
                 print "xsi:schemaLocation=\"{$gmlNameSpaceUri} {$thePath}?REQUEST=DescribeFeatureType&amp;TYPENAME=" . $HTTP_FORM_VARS["TYPENAME"] . " http://www.opengis.net/wfs http://wfs.plansystem.dk:80/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd\"";
             }
             print ">\n";
             doQuery("Select");
             print "</" . $gmlFeatureCollection . ">";
             break;
         case "DESCRIBEFEATURETYPE":
             getXSD($postgisObject);
             break;
         case "TRANSACTION":
             doParse($arr);
             break;
         default:
             makeExceptionReport("Don't know that request");
             break;
     }
 }