예제 #1
1
파일: Twitter.cpp 프로젝트: as2120/ZPoco
Poco::AutoPtr<Poco::XML::Document> Twitter::invoke(const std::string& httpMethod, const std::string& twitterMethod, Poco::Net::HTMLForm& form)
{
    // Create the request URI.
    // We use the XML version of the Twitter API.
    Poco::URI uri(_uri + twitterMethod + ".xml");
    std::string path(uri.getPath());

    Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
    Poco::Net::HTTPRequest req(httpMethod, path, Poco::Net::HTTPMessage::HTTP_1_1);

    // Add username and password (HTTP basic authentication) to the request.
    Poco::Net::HTTPBasicCredentials cred(_username, _password);
    cred.authenticate(req);

    // Send the request.
    form.prepareSubmit(req);
    std::ostream& ostr = session.sendRequest(req);
    form.write(ostr);

    // Receive the response.
    Poco::Net::HTTPResponse res;
    std::istream& rs = session.receiveResponse(res);

    // Create a DOM document from the response.
    Poco::XML::DOMParser parser;
    parser.setFeature(Poco::XML::DOMParser::FEATURE_FILTER_WHITESPACE, true);
    parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACES, false);
    Poco::XML::InputSource source(rs);
    Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parse(&source);

    // If everything went fine, return the XML document.
    // Otherwise look for an error message in the XML document.
    if (res.getStatus() == Poco::Net::HTTPResponse::HTTP_OK)
    {
        return pDoc;
    }
    else
    {
        std::string error(res.getReason());
        Poco::AutoPtr<Poco::XML::NodeList> pList = pDoc->getElementsByTagName("error");
        if (pList->length() > 0)
        {
            error += ": ";
            error += pList->item(0)->innerText();
        }
        throw Poco::ApplicationException("Twitter Error", error);
    }
}
예제 #2
0
/* Validate all of the pipelines in the given config file.
* This method does some basic parsing of the config file to learn
* about the various pipelines that exist in the file.
*/
bool ValidatePipeline::isValid(const char *a_configPath) const
{
    bool failed = false;

    std::ifstream in(a_configPath);
    if (!in) {
        fprintf(stdout, "Error opening pipeline config file: %s\n", a_configPath);
    } else {
        try {
            Poco::XML::InputSource src(in);
            Poco::XML::DOMParser parser;
            // basic parsing
            Poco::AutoPtr<Poco::XML::Document> xmlDoc = parser.parse(&src);

            // must have at least one pipeline element
            Poco::AutoPtr<Poco::XML::NodeList> pipelines =
                xmlDoc->getElementsByTagName(TskPipelineManager::PIPELINE_ELEMENT);

            if (pipelines->length() == 0) {
                fprintf(stdout, "No pipelines found in config file.\n");
            } else {
                // parse all pipelines in the config file
                for (unsigned long i = 0; i < pipelines->length(); i++)
                {
                    Poco::XML::Node * pNode = pipelines->item(i);
                    Poco::XML::Element* pElem = dynamic_cast<Poco::XML::Element*>(pNode);
                    Poco::XML::DOMWriter writer;
                    std::ostringstream pipelineXml;
                    writer.writeNode(pipelineXml, pNode);

                    std::string pipelineType = pElem->getAttribute(TskPipelineManager::PIPELINE_TYPE_ATTRIBUTE);

                    TskPipeline * pipeline = 0;
                    if (pipelineType == TskPipelineManager::FILE_ANALYSIS_PIPELINE_STR)
                        pipeline = new TskFileAnalysisPipeline();
                    else if (pipelineType == TskPipelineManager::REPORTING_PIPELINE_STR)
                        pipeline = new TskReportPipeline();
                    else {
                        fprintf(stdout, "Unsupported pipeline type: %s\n", pipelineType.c_str());
                        failed = true;
                        continue;
                    }

                    try {
                        pipeline->validate(pipelineXml.str());
                    } catch (...) {
                        fprintf(stdout, "Error parsing pipeline: %s\n", pElem->getAttribute(TskPipelineManager::PIPELINE_TYPE_ATTRIBUTE).c_str());
                        failed = true;
                    }
                    delete pipeline;
                }
            }
        } catch (Poco::XML::SAXParseException& ex) {
            fprintf(stderr, "Error parsing pipeline config file: %s (%s)\n", a_configPath, ex.what());
        }
    }

    // If any of the pipelines failed validation we return false
    return failed ? false : true;
}
예제 #3
0
XmlHandler::XmlHandler(std::string filename) {

  std::ifstream in(filename);
  Poco::XML::InputSource src(in);
  Poco::XML::DOMParser parser;
  pDoc = parser.parse(&src);
}
예제 #4
0
파일: Mapper.cpp 프로젝트: Belsepubi/naali
    void Mapper::LoadInputMappings(const std::string &file)
    {
        if (boost::filesystem::exists(file) == false)
        {
            InputModuleOIS::LogInfo("Input mappings file not found, using default mappings.");

            Export(file);
        } else
        {
            InputModuleOIS::LogInfo("Loading input mappings from file " + file + "...");
            try
            {
                Poco::XML::InputSource source(file);
                Poco::XML::DOMParser parser;
                Poco::XML::AutoPtr<Poco::XML::Document> document = parser.parse(&source);
                
                if (!document.isNull())
                {
                    Poco::XML::Node* node = document->firstChild();
                    if (node)
                    {
                        LoadInputMappings(node);
                    }
                }
                else
                {
                    throw Exception("Failed to parse xml document.");
                }
            } catch (std::exception &e)
            {
                InputModuleOIS::LogInfo(e.what());
                InputModuleOIS::LogInfo("Failed to parse input mappings file, using default mappings.");
            }
        }
    }
예제 #5
0
/**
 * Parse the runinfo file to find the names of the neutron event files.
 *
 * @param runinfo Runinfo file with full path.
 * @param dataDir Directory where the runinfo file lives.
 * @param eventFilenames vector of all possible event files. This is filled by
 *the algorithm.
 */
void LoadPreNexus::parseRuninfo(const string &runinfo, string &dataDir,
                                vector<string> &eventFilenames) {
  eventFilenames.clear();

  // Create a Poco Path object for runinfo filename
  Poco::Path runinfoPath(runinfo, Poco::Path::PATH_GUESS);
  // Now lets get the directory
  Poco::Path dirPath(runinfoPath.parent());
  dataDir = dirPath.absolute().toString();
  g_log.debug() << "Data directory \"" << dataDir << "\"\n";

  std::ifstream in(runinfo.c_str());
  Poco::XML::InputSource src(in);

  Poco::XML::DOMParser parser;
  Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parse(&src);

  Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
  Poco::XML::Node *pNode = it.nextNode(); // root node
  while (pNode) {
    if (pNode->nodeName() == "RunInfo") // standard name for this type
    {
      pNode = pNode->firstChild();
      while (pNode) {
        if (pNode->nodeName() == "FileList") {
          pNode = pNode->firstChild();
          while (pNode) {
            if (pNode->nodeName() == "DataList") {
              pNode = pNode->firstChild();
              while (pNode) {
                if (pNode->nodeName() == "scattering") {
                  Poco::XML::Element *element =
                      static_cast<Poco::XML::Element *>(pNode);
                  eventFilenames.push_back(element->getAttribute("name"));
                }
                pNode = pNode->nextSibling();
              }
            } else // search for DataList
              pNode = pNode->nextSibling();
          }
        } else // search for FileList
          pNode = pNode->nextSibling();
      }
    } else // search for RunInfo
      pNode = pNode->nextSibling();
  }

  // report the results to the log
  if (eventFilenames.size() == 1) {
    g_log.debug() << "Found 1 event file: \"" << eventFilenames[0] << "\"\n";
  } else {
    g_log.debug() << "Found " << eventFilenames.size() << " event files:";
    for (auto &eventFilename : eventFilenames) {
      g_log.debug() << "\"" << eventFilename << "\" ";
    }
    g_log.debug() << "\n";
  }
}
void XMLConfiguration::load(Poco::XML::InputSource* pInputSource)
{
	poco_check_ptr (pInputSource);
	
	Poco::XML::DOMParser parser;
	parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACES, false);
	parser.setFeature(Poco::XML::DOMParser::FEATURE_FILTER_WHITESPACE, true);
	Poco::XML::AutoPtr<Poco::XML::Document> pDoc = parser.parse(pInputSource);
	load(pDoc);
}
예제 #7
0
void Configure::loadChannelList(void)
{
    std::ifstream in(SystemInfo::instance().getExecutePath() + "\\config\\channelList.xml");
    Poco::XML::InputSource src(in);
    Poco::XML::DOMParser parser;

    try
    {
        Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parse(&src);
        Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ALL);
        Poco::XML::Node* pNode = it.nextNode();

        static int index = 0;
		std::string channelInfo[3];
        while (pNode)  
        {
            if(pNode->nodeName() == "Row")
            {
                pNode = it.nextNode();
                if(pNode->nodeName() != "#text")
                {
                    continue; //No text node present
                }
                index = 0;
                if(m_encodeChannel == channelInfo[1])
                {
                    // 找到频道对照表
                    m_encodeChannelID = channelInfo[0];
                    m_encodeChannelPrefix = channelInfo[2];
                    LOG(INFO) << "get channel info : ID [" << m_encodeChannelID << "] Prefix[" << m_encodeChannelPrefix << "].";
                    return;
                }
            }
            if(pNode->nodeName() == "Cell")
            {
                pNode = it.nextNode();
                if(pNode->nodeName() != "#text")
                {
                    pNode = it.nextNode();
                    continue; //No text node present
                }
                channelInfo[index++] = pNode->nodeValue();
            }

            pNode = it.nextNode();//指向下一个node
        }
    }
    catch(std::exception& e)
    {
        LOG(ERROR) << "parse channelList xml file error." << e.what() ;
    }
}
void ExtensionPointService::handleExtensions(Bundle::ConstPtr pBundle, std::istream& istr, GenericHandler handler, Direction dir)
{
	Poco::XML::DOMParser parser;
	parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACES, false);
	parser.setFeature(Poco::XML::DOMParser::FEATURE_FILTER_WHITESPACE, true);
	Poco::XML::InputSource source(istr);
	AutoPtr<Document> pDoc(parser.parse(&source));
	Node* pRoot = pDoc->firstChild();
	while (pRoot && pRoot->nodeName() != EXTENSIONS_ELEM)
	{
		pRoot = pRoot->nextSibling();
	}
	if (pRoot)
	{
		Node* pNode = (dir == DIR_FORWARD ? pRoot->firstChild() : pRoot->lastChild());
		while (pNode)
		{
			if (pNode->nodeType() == Node::ELEMENT_NODE)
			{
				if (pNode->nodeName() == EXTENSION_ELEM)
				{
					Element* pElem = static_cast<Element*>(pNode);
					const std::string& id = pElem->getAttribute(POINT_ATTR);
					if (!id.empty())
					{
						(this->*handler)(pBundle, id, pElem);
					}
					else
					{
						_logger.error(std::string("No point attribute found in extension element of bundle ")
							+ pBundle->symbolicName());
					}
				}
				else
				{
					_logger.warning(std::string("Unsupported element '")
						+ pNode->nodeName()
						+ "' found in "
						+ EXTENSIONS_XML
						+ " of bundle "
						+ pBundle->symbolicName());
				}
			}

			pNode = (dir == DIR_FORWARD ? pNode->nextSibling() : pNode->previousSibling());
		}
	}
	else throw Poco::NotFoundException("No extensions element found");
}
예제 #9
0
  /**
   * Reads detctor ids for groups from an XML grouping file, such as one created by the SpatialGrouping algorithm.
   * @param filename :: path and name of input file
   * @throw FileError is there is a problem with the XML file
   */
  void ReadGroupsFromFile::readXMLGroupingFile(const std::string& filename)
  {
    Poco::XML::DOMParser xmlParser;
    Poco::XML::Document* file;
    try
    {
      file = xmlParser.parse(filename);
    }
    catch ( ... )
    {
      throw Kernel::Exception::FileError("Unable to parse file: ", filename);
    }

    Poco::XML::Element* root = file->documentElement();
  
    if ( ! root->hasChildNodes() )
    {
      throw Kernel::Exception::FileError("No root element in XML grouping file: ", filename);
    }

    Poco::XML::NodeList* groups = root->getElementsByTagName("group");

    if ( groups->length() == 0 )
    {
      throw Kernel::Exception::FileError("XML group file contains no group elements:", filename);
    }

    unsigned int nGroups = static_cast<unsigned int>(groups->length());
    for ( unsigned int i = 0; i < nGroups; i++ )
    {
      // Get the "detids" element from the grouping file
      Poco::XML::Element* elem = static_cast<Poco::XML::Element*>(groups->item(i));
      Poco::XML::Element* group = elem->getChildElement("detids");

      if ( ! group )
      {
        throw Mantid::Kernel::Exception::FileError("XML Group File, group contains no <detids> element:", filename);
      }
  
      std::string ids = group->getAttribute("val");

      Poco::StringTokenizer data(ids, ",", Poco::StringTokenizer::TOK_TRIM);

      if ( data.begin() != data.end() )
      {
        for ( Poco::StringTokenizer::Iterator it = data.begin(); it != data.end(); ++it )
        {
          // cast the string to an int
          int detID;
          try
          {
            detID = boost::lexical_cast<int>(*it);
          } catch ( boost::bad_lexical_cast & )
          {
            throw Mantid::Kernel::Exception::FileError("Could cast string to integer in input XML file", filename);
          }
  
          if ( calibration.find(detID) == calibration.end() )
          {
            // add detector to a group
            calibration[detID] = std::pair<int,int>(i+1, 1);
          }
        }
      }
    }

    progress(0.7);
  }
예제 #10
0
/**
 * @param filenames : List of files to search
 * @param exts : List of extensions to check against
 * @return list of archive locations
 */
std::string SNSDataArchive::getArchivePath(const std::set<std::string>& filenames, const std::vector<std::string>& exts) const
{
  std::set<std::string>::const_iterator iter = filenames.begin();
  std::string filename = *iter;

  //ICAT4 web service take upper case filename such as HYSA_2662
  std::transform(filename.begin(),filename.end(),filename.begin(),toupper);

  std::vector<std::string>::const_iterator iter2 = exts.begin();
  for(; iter2!=exts.end(); ++iter2)
  {
    g_log.debug() << *iter2 << ";";
  }
  g_log.debug()  << "\n";

  std::string baseURL("http://icat.sns.gov:8080/icat-rest-ws/datafile/filename/");

  std::string URL(baseURL + filename);
  g_log.debug() << "URL: " << URL << "\n";

  Poco::URI uri(URL);
  std::string path(uri.getPathAndQuery());

  Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
  Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, path, Poco::Net::HTTPMessage::HTTP_1_1);
  session.sendRequest(req);

  Poco::Net::HTTPResponse res;
  std::istream& rs = session.receiveResponse(res);
  g_log.debug() << "res.getStatus(): " << res.getStatus() << "\n";

  // Create a DOM document from the response.
  Poco::XML::DOMParser parser;
  Poco::XML::InputSource source(rs);
  Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parse(&source);

  std::vector<std::string> locations;

  // If everything went fine, return the XML document.
  // Otherwise look for an error message in the XML document.
  if (res.getStatus() == Poco::Net::HTTPResponse::HTTP_OK)
  {
    std::string location;
    Poco::AutoPtr<Poco::XML::NodeList> pList = pDoc->getElementsByTagName("location");
    for(unsigned long i = 0 ; i < pList->length(); i++)
    {
      location = pList->item(i)->innerText();
      g_log.debug() << "location: " << location << "\n";
      locations.push_back(location);
    }
  }
  else
  {
    std::string error(res.getReason());
    throw Poco::ApplicationException("HTTPRequest Error", error);
  }

  std::vector<std::string>::const_iterator ext = exts.begin();
  for (; ext != exts.end(); ++ext)
  {
    std::string datafile = filename + *ext;
    std::vector<std::string>::const_iterator iter = locations.begin();
    for(; iter!=locations.end(); ++iter)
    {
      if (boost::algorithm::ends_with((*iter), datafile))
      {
        return *iter;
      } // end if
    } // end for iter

  }  // end for ext
  return "";
}
예제 #11
0
bool Configure::load(void)
{
    std::ifstream in(SystemInfo::instance().getExecutePath() + "\\config\\sys.xml");
    Poco::XML::InputSource src(in);
    Poco::XML::DOMParser parser;

    try
    {
        Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parse(&src);
        Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ALL);
        Poco::XML::Node* pNode = it.nextNode();


        while (pNode)  
        {  
            if(pNode->nodeName() == "EncodChannel")
            {
                pNode = it.nextNode();
                if(pNode->nodeName() != "#text")
                {
                    continue; //No text node present
                }
                m_encodeChannel = pNode->nodeValue();
				Poco::XML::XMLString tt = Poco::XML::toXMLString(m_encodeChannel);
            }

            if(pNode->nodeName() == "InputTSPath")
            {
				getNetWorkPathAttr(pNode->attributes(),&m_inputTSPath);
                pNode = it.nextNode();
                if(pNode->nodeName() != "#text")
                {
                    continue; //No text node present
                }
				m_inputTSPath.path = pNode->nodeValue();
				m_inputTSPath.objectName = "o:";
            }

            if(pNode->nodeName() == "InputXMLPath")
            {
				getNetWorkPathAttr(pNode->attributes(),&m_inputXMLPath);
                pNode = it.nextNode();
                if(pNode->nodeName() != "#text")
                {
                    continue; //No text node present
                }
				m_inputXMLPath.path = pNode->nodeValue();
				m_inputXMLPath.objectName = "p:";
            }

            if(pNode->nodeName() == "OutputTSPath")
            {
				getNetWorkPathAttr(pNode->attributes(),&m_outputTSPath);
                pNode = it.nextNode();
                if(pNode->nodeName() != "#text")
                {
                    continue; //No text node present
                }
				m_outputTSPath.path = pNode->nodeValue();
				m_outputTSPath.objectName = "q:";
            }

            if(pNode->nodeName() == "OutputXMLPath")
            {
				getNetWorkPathAttr(pNode->attributes(),&m_outputXMLPath);
                pNode = it.nextNode();
                if(pNode->nodeName() != "#text")
                {
                    continue; //No text node present
                }
				m_outputXMLPath.path = pNode->nodeValue();
				m_outputXMLPath.objectName = "r:";
            }

            if(pNode->nodeName() == "OutputStream1")
            {
				getOutputStreamAttr(pNode->attributes(),&m_outputStream[0]);
                pNode = it.nextNode();
                if(pNode->nodeName() != "#text")
                {
                    continue; //No text node present
                }
            }
            if(pNode->nodeName() == "OutputStream2")
            {
				getOutputStreamAttr(pNode->attributes(),&m_outputStream[1]);
                pNode = it.nextNode();
                if(pNode->nodeName() != "#text")
                {
                    continue; //No text node present
                }
            }
            if(pNode->nodeName() == "OutputStream3")
            {
				getOutputStreamAttr(pNode->attributes(),&m_outputStream[2]);
                pNode = it.nextNode();
                if(pNode->nodeName() != "#text")
                {
                    continue; //No text node present
                }
            }
            if(pNode->nodeName() == "Storage")
            {
                if(pNode->attributes())//看看是否真有属性  
                {  
                    for(int i = 0 ; i < pNode->attributes()->length() ; i++)
                    {  
                        Poco::XML::Node* attr = pNode->attributes()->item(i);  
			            if(attr->nodeName() == "KeepingDateTime")
			            {
				            m_keepDateTime = boost::lexical_cast<int>(attr->nodeValue());
			            }
                    }//属性结束
                }
                pNode = it.nextNode();
                if(pNode->nodeName() != "#text")
                {
                    continue; //No text node present
                }
            }
			

            //LOG(INFO) << "name : " << pNode->nodeName() ;//取出当前节点的Name  
            //LOG(INFO)<< "value : " << pNode->nodeValue() ;//取出当前节点的Value  
            pNode = it.nextNode();//指向下一个node  
        }
    }
    catch(std::exception& e)
    {
        LOG(ERROR) << "parse xml file error." << e.what() ;
        return false;
    }

    this->loadChannelList();

    if(m_encodeChannel.empty() || m_encodeChannelID.empty() || m_encodeChannelPrefix.empty() ||
		m_inputTSPath.path.empty() || m_inputTSPath.objectName.empty() ||
		m_inputXMLPath.path.empty() || m_inputXMLPath.objectName.empty() ||
		m_outputTSPath.path.empty() || m_outputTSPath.objectName.empty() ||
		m_outputXMLPath.path.empty() || m_outputXMLPath.objectName.empty() ||
		m_outputStream[0].bitrate.empty() || m_outputStream[0].enable.empty() || m_outputStream[0].resolutionRatio.empty() ||
		m_outputStream[1].bitrate.empty() || m_outputStream[1].enable.empty() || m_outputStream[1].resolutionRatio.empty() ||
		m_outputStream[2].bitrate.empty() || m_outputStream[2].enable.empty() || m_outputStream[2].resolutionRatio.empty() ||
        m_keepDateTime == -2)
    {
        return false;
    }

    LOG(INFO) << "EncodChannel [" << Configure::instance().m_encodeChannel << "] ID[" << m_encodeChannelID << "] Prefix[" << m_encodeChannelPrefix << "].";
	LOG(INFO) << "InputTSPath [" << Configure::instance().m_inputTSPath.path << "]" << " as [" << Configure::instance().m_inputTSPath.objectName << "]";
	LOG(INFO) << "InputXMLPath [" << Configure::instance().m_inputXMLPath.path << "]" << " as [" << Configure::instance().m_inputXMLPath.objectName << "]";
	LOG(INFO) << "OutputTSPath [" << Configure::instance().m_outputTSPath.path << "]" << " as [" << Configure::instance().m_outputTSPath.objectName << "]";
	LOG(INFO) << "OutputXMLPath [" << Configure::instance().m_outputXMLPath.path << "]" << " as [" << Configure::instance().m_outputXMLPath.objectName << "]";
	LOG(INFO) << "OutputStream1 [" << Configure::instance().m_outputStream[0].enable << ", " << Configure::instance().m_outputStream[0].bitrate << ", " << Configure::instance().m_outputStream[0].resolutionRatio << "]";
    LOG(INFO) << "OutputStream2 [" << Configure::instance().m_outputStream[1].enable << ", " << Configure::instance().m_outputStream[1].bitrate << ", " << Configure::instance().m_outputStream[1].resolutionRatio << "]";
	LOG(INFO) << "OutputStream3 [" << Configure::instance().m_outputStream[2].enable << ", " << Configure::instance().m_outputStream[2].bitrate << ", " << Configure::instance().m_outputStream[2].resolutionRatio << "]";
	LOG(INFO) << "stoage keep DateTime [" << m_keepDateTime << "].";

    return true;
}
void DebugBreakpointManager::RestoreState(const Poco::Path& path)
{
  try
  {
    Poco::XML::DOMParser parser;

    Poco::FileInputStream reader(path.toString());
    Poco::XML::InputSource source(reader);

    //source.setSystemId(baseDir);
    Poco::XML::Document* doc = parser.parse(&source);
    Poco::XML::Element* breakpoints = doc->documentElement();

    if (breakpoints)
    {
      // restore object breakpoints
      Poco::XML::NodeList* elementList = breakpoints->getElementsByTagName(
          OBJECT_TAG);
      for (std::size_t i = 0; i < elementList->length(); i++)
      {
        Poco::XML::Element* elem =
            dynamic_cast<Poco::XML::Element*> (elementList->item(i));

        if (!elem->hasAttribute(ID_ATTR))
          continue;

        const std::string& attr = elem->getAttribute(ID_ATTR);

        int traceId = 0;
        try
        {
          traceId = Poco::NumberParser::parse(attr);
        } catch (const Poco::SyntaxException& e)
        {
          BERRY_WARN << e.displayText();
        }

        DebugUtil::GetBreakpointManager()->AddObjectBreakpoint(traceId);
      }
      elementList->release();

      // restore smartpointer breakpoints
      elementList = breakpoints->getElementsByTagName(SMARTPOINTER_TAG);
      for (std::size_t i = 0; i < elementList->length(); i++)
      {
        Poco::XML::Element* elem =
            dynamic_cast<Poco::XML::Element*> (elementList->item(i));

        if (!elem->hasAttribute(ID_ATTR))
          continue;

        const std::string& attr = elem->getAttribute(ID_ATTR);

        int spId = 0;
        try
        {
          spId = Poco::NumberParser::parse(attr);
        } catch (const Poco::SyntaxException& e)
        {
          BERRY_WARN << e.displayText();
        }

        DebugUtil::GetBreakpointManager()->AddSmartpointerBreakpoint(spId);
      }
      elementList->release();
    }

    doc->release();
  } catch (Poco::XML::SAXParseException& e)
  {
    BERRY_WARN << e.displayText();
  }
  catch (Poco::FileNotFoundException& /*e*/)
  {

  }
  catch (Poco::FileException& e)
  {
    BERRY_WARN << e.displayText();
  }
}
예제 #13
0
void DebugUtil::RestoreState()
{
    Poco::Path path;
    if (!GetPersistencePath(path)) return;

    path.setFileName(DEBUG_UTIL_XML);

    try
    {
        Poco::XML::DOMParser parser;

        Poco::FileInputStream reader(path.toString());
        Poco::XML::InputSource source(reader);

        //source.setSystemId(baseDir);
        Poco::XML::Document* doc = parser.parse(&source);
        Poco::XML::Element* debugutil = doc->documentElement();

        if (debugutil)
        {
            // restore traced objects
            Poco::XML::NodeList* elementList = debugutil->getElementsByTagName(TRACEOBJECT_TAG);
            for (std::size_t i = 0; i < elementList->length(); i++)
            {
                Poco::XML::Element* elem =
                    dynamic_cast<Poco::XML::Element*> (elementList->item(static_cast<unsigned long>(i)));

                if (!elem->hasAttribute(ID_ATTR)) continue;

                const std::string& attr = elem->getAttribute(ID_ATTR);

                int traceId = 0;
                try
                {
                    traceId = Poco::NumberParser::parse(attr);
                }
                catch (const Poco::SyntaxException& e)
                {
                    BERRY_WARN << e.displayText();
                }

                DebugUtil::TraceObject(traceId);
            }
            elementList->release();

            // restore traced classes
            elementList = debugutil->getElementsByTagName(TRACECLASS_TAG);
            for (std::size_t i = 0; i < elementList->length(); i++)
            {
                Poco::XML::Element* elem =
                    dynamic_cast<Poco::XML::Element*> (elementList->item(static_cast<unsigned long>(i)));

                if (!elem->hasAttribute(NAME_ATTR)) continue;

                const std::string& traceClass = elem->getAttribute(NAME_ATTR);
                if (!traceClass.empty())
                    DebugUtil::TraceClass(traceClass);
            }
            elementList->release();
        }

        doc->release();
    }
    catch (Poco::XML::SAXParseException& e)
    {
        BERRY_WARN << e.displayText();
    }
    catch (Poco::FileNotFoundException&)
    {

    }
    catch (Poco::FileException& e)
    {
        BERRY_WARN << e.displayText();
    }

    // restore BreakpointManager
    path.setFileName(DebugBreakpointManager::BREAKPOINTS_XML);
    GetBreakpointManager()->RestoreState(path);
}