Beispiel #1
0
bool ofXml::setToChild(int index)
{
    
    if(!element) {
        if((Poco::XML::Element*) document->documentElement()->firstChild()) {
            element = (Poco::XML::Element*) document->documentElement()->firstChild();
        } else {
            ofLogWarning("ofXml") << "setToChild(): no element created yet";
            return false;
        }
    }
    
	unsigned long numberOfChildren = 0;
    Poco::XML::NodeList *list = element->childNodes();

    for(unsigned long i=0; i < list->length() && numberOfChildren < index + 1; i++) {
        if(list->item(i) && list->item(i)->nodeType() == Poco::XML::Node::ELEMENT_NODE) {
            if(numberOfChildren == index) {
                element = (Poco::XML::Element*) list->item(i);
                return true;
            }
            numberOfChildren++;
        }
    }
    
    return false;
    
}
/**
Create the transform object.
@param coordTransElement : xml coordinate transform element
@return a fully constructed coordinate transform object.
*/
Mantid::API::CoordTransform *CoordTransformAffineParser::createTransform(
    Poco::XML::Element *coordTransElement) const {
  typedef Mantid::API::SingleValueParameterParser<Mantid::API::InDimParameter>
      InDimParameterParser;
  typedef Mantid::API::SingleValueParameterParser<Mantid::API::OutDimParameter>
      OutDimParameterParser;
  using namespace Poco::XML;
  if ("CoordTransform" != coordTransElement->localName()) {
    std::string message = "This is not a coordinate transform element: " +
                          coordTransElement->localName();
    throw std::invalid_argument(message);
  }
  if ("CoordTransformAffine" !=
      coordTransElement->getChildElement("Type")->innerText()) {
    // Delegate
    if (!m_successor) {
      throw std::runtime_error(
          "CoordTransformAffineParser has no successor parser.");
    }
    return m_successor->createTransform(coordTransElement);
  }

  Element *paramListElement =
      coordTransElement->getChildElement("ParameterList");
  Poco::XML::NodeList *parameters =
      paramListElement->getElementsByTagName("Parameter");

  // Add input dimension parameter.
  InDimParameterParser inDimParser;
  Poco::XML::Element *parameter =
      dynamic_cast<Poco::XML::Element *>(parameters->item(0));
  Mantid::API::InDimParameter *inDim =
      inDimParser.createWithoutDelegation(parameter);

  // Add output dimension parameter.
  OutDimParameterParser outDimParser;
  parameter = dynamic_cast<Poco::XML::Element *>(parameters->item(1));
  Mantid::API::OutDimParameter *outDim =
      outDimParser.createWithoutDelegation(parameter);

  // Add affine matrix parameter.
  AffineMatrixParameterParser affineMatrixDimParser;
  parameter = dynamic_cast<Poco::XML::Element *>(parameters->item(2));
  AffineMatrixParameter *affineMatrix =
      affineMatrixDimParser.createParameter(parameter);

  // Generate the coordinate transform with the matrix and return.
  CoordTransformAffine *transform =
      new CoordTransformAffine(inDim->getValue(), outDim->getValue());
  transform->setMatrix(affineMatrix->getAffineMatrix());
  return transform;
}
Beispiel #3
0
int ofXml::getNumChildren() const
{
	if(!element) return 0;

    int numberOfChildren = 0;
    Poco::XML::NodeList *list = element->childNodes();
    
    for(unsigned long i=0; i < list->length(); i++) {
        if(list->item(i) && list->item(i)->nodeType() == Poco::XML::Node::ELEMENT_NODE) {
            numberOfChildren++;
        }
    }
    return numberOfChildren;
}
Beispiel #4
0
 ImplicitFunctionParameterParser* ImplicitFunctionParameterParserFactoryImpl::createImplicitFunctionParameterParserFromXML(Poco::XML::Element* parametersElement) const
 {
   if(parametersElement->localName() != "ParameterList")
   {
     throw std::runtime_error("Expected passed element to be ParameterList.");
   }
   Poco::XML::NodeList* parameters = parametersElement->getElementsByTagName("Parameter");
   ImplicitFunctionParameterParser* paramParser = NULL;
   ImplicitFunctionParameterParser* nextParser = NULL;
   for(unsigned long i = 0 ; i < parameters->length(); i++)
   {
     Poco::XML::Element* parameter = dynamic_cast<Poco::XML::Element*>(parameters->item(i));
     std::string paramParserName = parameter->getChildElement("Type")->innerText() + "Parser"; //Append parser to the name. Fixed convention
     ImplicitFunctionParameterParser* childParamParser = this->createUnwrapped(paramParserName);
     if(paramParser != NULL)
     {
       nextParser->setSuccessorParser(childParamParser);
     }
     else
     {
       paramParser = childParamParser;
     }
     nextParser = childParamParser;
   }
   return paramParser;
 }
Beispiel #5
0
int ofXml::getNumChildren(const string& path) const
{
	if(!element) return 0;

    int numberOfChildren = 0;
    Poco::XML::NodeList *list = element->childNodes();

    for(unsigned long i=0; i < list->length(); i++) {
        if(list->item(i) && list->item(i)->nodeType() == Poco::XML::Node::ELEMENT_NODE) {
            string nodeName = list->item(i)->localName();
            if(path.compare(nodeName) == 0) {
                numberOfChildren++;
            }
        }
    }
    
    return numberOfChildren;
    
}
Beispiel #6
0
    ImplicitFunctionParser* ImplicitFunctionParserFactoryImpl::createImplicitFunctionParserFromXML(Poco::XML::Element* functionElement) const
    {
      std::string name = functionElement->localName();
      if(name != "Function")
      {
        throw std::runtime_error("Root node must be a Funtion element. Unable to determine parsers.");
      }

      Poco::XML::Element* typeElement = functionElement->getChildElement("Type");
      std::string functionParserName = typeElement->innerText() + "Parser";
      ImplicitFunctionParser* functionParser = this->createUnwrapped(functionParserName);

      Poco::XML::Element* parametersElement = functionElement->getChildElement("ParameterList");

      //Get the parameter parser for the current function parser and append that to the function parser.
      ImplicitFunctionParameterParser* paramParser = Mantid::API::ImplicitFunctionParameterParserFactory::Instance().createImplicitFunctionParameterParserFromXML(parametersElement);
      functionParser->setParameterParser(paramParser);

      Poco::XML::NodeList* childFunctions = functionElement->getElementsByTagName("Function");
      ImplicitFunctionParser* childParser = NULL;
      for(unsigned long i = 0; i < childFunctions->length(); i++)
      {
        Poco::XML::Node* childFunctionNode = childFunctions->item(i);

        //Recursive call to handle nested parameters.
        Poco::XML::Element* childFunctionElement =( Poco::XML::Element*)childFunctionNode;
        ImplicitFunctionParser* tempParser = createImplicitFunctionParserFromXML(childFunctionElement);
        if(i==0)
        {
         childParser = tempParser;
         //Add the first child function parser to the parent (composite) directly.
         functionParser->setSuccessorParser(childParser);
        }
        else
        {
          //Add all other function parsers are added as successors to those before them in the loop.
          childParser->setSuccessorParser(tempParser);
          childParser = tempParser;
        }
      }

      return functionParser;
    }
Beispiel #7
0
bool ofXml::removeContents(const string& path) {
    
    Poco::XML::Element *e;
    if(element) {
        e = (Poco::XML::Element*) element->getNodeByPath(path);
    } else {
        ofLogWarning("ofXml") << "clearContents(): no element set yet";
        return false;
    }
    
    if(e) {
        Poco::XML::NodeList *list = e->childNodes();
        for(unsigned long i = 0; i < list->length(); i++) {
            element->removeChild(list->item(i));
        }
        list->release();
        return true;
    }
    return false;
}
  /**
   * 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);
  }
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();
  }
}
Beispiel #10
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);
}