1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include <roap/RoapMessageHandler.h> 17 #include <util/xml/DomExpatAgent.h> 18 #include <util/xml/XMLDocumentImpl.h> 19 #include <util/domcore/NodeListImpl.h> 20 #include <util/domcore/DOMString.h> 21 #include <ofstream.h> 22 using namespace ustl; 23 24 /**see RoapMessageHandler.h */ 25 RoapMessageHandler::RoapMessageHandler() 26 { 27 mDoc = NULL; 28 } 29 30 /**see RoapMessageHandler.h */ 31 XMLDocumentImpl* RoapMessageHandler::createClientMsg(RoapMessageHandler::msgType type) 32 { 33 /* load template from files temporarily, FIX ME later */ 34 string msgTemplate; 35 switch (type) 36 { 37 case RoapMessageHandler::DeviceHello: 38 msgTemplate.append("deviceHello.xml"); 39 break; 40 case RoapMessageHandler::RegistrationRequest: 41 msgTemplate.append("deviceHello.xml"); 42 break; 43 case RoapMessageHandler::RORequest: 44 msgTemplate.append("deviceHello.xml"); 45 break; 46 default: 47 return NULL; 48 } 49 ifstream xmlStream(msgTemplate.c_str()); 50 XMLDocumentImpl* xmlDoc = new XMLDocumentImpl(); 51 DomExpatAgent domExpatAgent1(xmlDoc); 52 if (domExpatAgent1.generateDocumentFromXML(&xmlStream)) 53 { 54 return xmlDoc; 55 } 56 else 57 { 58 delete(xmlDoc); 59 return NULL; 60 } 61 } 62 63