Пример #1
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";
  }
}
Пример #2
0
bool ofXml::removeContents() {
    if(element && element->hasChildNodes())
    {

		Poco::XML::Node* swap;
		Poco::XML::Node* n = element->firstChild();
		while(n->nextSibling() != nullptr)
		{
			swap = n->nextSibling();
			element->removeChild(n);
			n = swap;
		}
		
        return true;
    }
    return false;
}
Poco::XML::Node* XMLConfiguration::findElement(const std::string& name, Poco::XML::Node* pNode, bool create)
{
	Poco::XML::Node* pChild = pNode->firstChild();
	while (pChild)
	{
		if (pChild->nodeType() == Poco::XML::Node::ELEMENT_NODE && pChild->nodeName() == name)
			return pChild;
		pChild = pChild->nextSibling();
	}
	if (create)
	{
		Poco::AutoPtr<Poco::XML::Element> pElem = pNode->ownerDocument()->createElement(name);
		pNode->appendChild(pElem);
		return pElem;
	}
	else return 0;
}
Пример #4
0
Expression::Pointer
StandardElementHandler::Create(ExpressionConverter* converter, Poco::XML::Element* element)
{
    std::string name= element->nodeName();
    if (ExpressionTagNames::INSTANCEOF == name) {
        Expression::Pointer result(new InstanceofExpression(element));
        return result;
    } else if (ExpressionTagNames::TEST == name) {
        Expression::Pointer result(new TestExpression(element));
        return result;
    } else if (ExpressionTagNames::OR == name) {
        CompositeExpression::Pointer result(new OrExpression());
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::AND == name) {
        CompositeExpression::Pointer result(new AndExpression());
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::NOT == name) {
        Poco::XML::Node* child = element->firstChild();
        while (child != 0) {
            if (child->nodeType() == Poco::XML::Node::ELEMENT_NODE) {
                Expression::Pointer result(new NotExpression(converter->Perform(static_cast<Poco::XML::Element*>(child))));
                return result;
            }
            child = child->nextSibling();
        }
    } else if (ExpressionTagNames::WITH == name) {
        CompositeExpression::Pointer result(new WithExpression(element));
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::ADAPT == name) {
        CompositeExpression::Pointer result(new AdaptExpression(element));
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::ITERATE == name) {
        CompositeExpression::Pointer result(new IterateExpression(element));
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::COUNT == name) {
        Expression::Pointer result(new CountExpression(element));
        return result;
    } else if (ExpressionTagNames::SYSTEM_TEST == name) {
        Expression::Pointer result(new SystemTestExpression(element));
        return result;
    } else if (ExpressionTagNames::RESOLVE == name) {
        CompositeExpression::Pointer result(new ResolveExpression(element));
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::ENABLEMENT == name) {
        CompositeExpression::Pointer result(new EnablementExpression(element));
        this->ProcessChildren(converter, element, result);
        return result;
    } else if (ExpressionTagNames::EQUALS == name) {
        Expression::Pointer result(new EqualsExpression(element));
        return result;
    } else if (ExpressionTagNames::REFERENCE == name) {
        Expression::Pointer result(new ReferenceExpression(element));
        return result;
    }
    return Expression::Pointer();
}