コード例 #1
0
bool XMLParserThread::
xmlParseZoomSettingsRequest( DOMNode* cur, DOMNode* out,
                             DOMDocument* reply, bool indent ) {

   DOMElement* root = XMLUtility::createStandardReply( *reply, *cur, 
                                                       "zoom_settings_reply" );
   out->appendChild( root );
   using XMLTool::getAttrib;

   uint32 pixelSize = CylindricalProjection::NBR_PIXELS;
   getAttrib( pixelSize, "pixel_size", cur, pixelSize );

   if ( ! CylindricalProjection::isValidPixelSize( pixelSize ) ){
      pixelSize = CylindricalProjection::NBR_PIXELS;
   }

   XMLZoomSettings::createReplyBody( *root, pixelSize, getClientSetting() );

   // now we have created a zoom_settings_reply body, we need
   // to check crc against the zoom_settings_request
   //
   // returns crc_ok if they match instead of entire zoom 
   // settings body

   MC2String crcReceived;
   getAttrib( crcReceived, "crc", cur, MC2String() );

   MC2String crcCreated; 
   try {
      getAttrib( crcCreated, "crc", XMLTool::findNode( 
                    root, "zoom_levels" ) );
   } catch ( const XMLTool::Exception& e ) {
      mc2log << fatal 
             << "xmlParseZoomSettingsRequest: No crc in created xml!" << endl;
      MC2_ASSERT( false );
   }
   
   if ( crcCreated == crcReceived ) { 
      // first child must be zoom_levels
      DOMNode* zoom_levels = XMLTool::findNode( 
         root, "zoom_levels" );
      if ( ! XMLString::equals( zoom_levels->getNodeName(), "zoom_levels" ) ) {
         mc2log << fatal << "[ZoomRequest] first child is not zoom levels!" << endl;
         MC2_ASSERT( false );
      }
      // replace zoom_levels with crc_ok
      root->replaceChild( reply->createElement( X( "crc_ok" ) ),
                          zoom_levels );
   }

   if ( indent ) {
      XMLUtility::indentPiece( *root, 1 );
   }
   return true;
}