7 #include "LabelTranslationManager.h" 
   15 #include "IException.h" 
   19 #include "PvlContainer.h" 
   21 #include "PvlKeyword.h" 
   22 #include "PvlObject.h" 
   23 #include "XmlToPvlTranslationManager.h" 
   39   XmlToPvlTranslationManager::XmlToPvlTranslationManager(
const QString &transFile)
 
   71                                                          const QString &transFile)
 
   88                                                          std::istream &transStrm)
 
  121     validKeywords.push_back(pair<QString, int>(
"InputKeyAttribute",      -1));
 
  122     validKeywords.push_back(pair<QString, int>(
"InputKeyDependencies",   -1));
 
  167       QString msg = 
"Cannot translate value at index [" + 
toString(index) +
 
  168                     "]. Xml files can only store a single value in each element.";
 
  175       transGroup = transTable.
findGroup(translationGroupName);
 
  178       QString msg = 
"Unable to retrieve translation group from translation table.";
 
  185       inputPosition = transGroup[
"InputPosition"];
 
  188       QString msg = 
"Unable to retrieve [InputPosition] keyword from " 
  189                     "translation group.";
 
  192     QString inputParentName = inputPosition[inputPosition.
size() - 1];
 
  197       inputKey = transGroup[
"InputKey"][0];
 
  200       QString msg = 
"Unable to retrieve [InputKey] keyword from " 
  201                     "translation group.";
 
  204     QString attributeName;
 
  205     if (transGroup.
hasKeyword(
"InputKeyAttribute")) {
 
  206       attributeName = transGroup[
"InputKeyAttribute"][0];
 
  211     if (transGroup.
hasKeyword(
"InputKeyDependencies")) {
 
  212       keyDependencies = transGroup[
"InputKeyDependencies"];
 
  216     bool isDebug = transGroup.
hasKeyword(
"Debug");
 
  220       cout << endl << 
"          ====================          " << endl;
 
  221       cout << endl << 
"Translating output keyword: " << translationGroupName << endl;
 
  222       cout << endl << 
"Translation group:" << endl;
 
  223       cout << transGroup << endl << endl;
 
  227     QDomElement inputParentElement = 
m_xmlLabel.documentElement();
 
  230       cout << endl << 
"Finding input element:" << endl << endl;
 
  231       cout << inputParentElement.tagName() << endl;
 
  238     QDomElement oldInputParentElement = inputParentElement;
 
  240     while(it != transGroup.
end()) {
 
  242       inputParentElement = oldInputParentElement;
 
  244         for (
int i = 0; i < inputPosition.
size(); i++) {
 
  245           childName = inputPosition[i];
 
  246           inputParentElement = inputParentElement.firstChildElement(childName);
 
  247           if(inputParentElement.isNull()) {
 
  252             cout << indent << inputParentElement.tagName() << endl;
 
  255         if (!inputParentElement.isNull()) {
 
  258         it = transGroup.
findKeyword(
"InputPosition", it + 1, transGroup.
end());
 
  261     if (inputParentElement.isNull()) {
 
  264           cout << endl << 
"Could not traverse input position, " <<
 
  265             "using default value: " <<
 
  271         QString msg = 
"Failed traversing input position. [" +
 
  272           inputPosition.
name() + 
"] element does not have a child element named [" +
 
  278     QDomElement inputKeyElement = inputParentElement.firstChildElement(inputKey);
 
  281       cout << indent << inputKeyElement.tagName() << endl;
 
  285     while ( !inputParentElement.isNull() &&
 
  288         cout << endl << 
"Dependencies failed, checking next candidate." << endl;
 
  291       inputKeyElement = inputKeyElement.nextSiblingElement(inputKey);
 
  293       while ( inputKeyElement.isNull() ) {
 
  294         inputParentElement = inputParentElement.nextSiblingElement(inputParentName);
 
  296         if ( inputParentElement.isNull() ) {
 
  299         inputKeyElement = inputParentElement.firstChildElement(inputKey);
 
  304     if ( inputParentElement.isNull() ) {
 
  307           cout << endl << 
"No input value found, using default value: " <<
 
  313         QString msg = 
"Could not find an input or default value that fits the given input " 
  314                       "keyword dependencies.";
 
  320     QString inputValue = inputKeyElement.text();
 
  322     if (attributeName.size() > 0) {
 
  323       if ( inputKeyElement.hasAttribute(attributeName) ) {
 
  324         inputValue = inputKeyElement.attribute(attributeName);
 
  328           cout << endl << 
"No input value found, using default value: " <<
 
  334         QString msg = 
"Input element [" + inputKeyElement.tagName() +
 
  335                       "] does not have an attribute named [" +
 
  336                       attributeName + 
"].";
 
  341           cout << endl << 
"Translating input value: " << inputValue << endl;
 
  346       QString msg = 
"Failed to translate output value for [" + translationGroupName + 
"].";
 
  377       cout << endl << 
"Testing dependencies:" << endl;
 
  379     for (
int i = 0; i < dependencies.
size(); i++) {
 
  382       if (specification.size() != 3) { 
 
  386         cout << endl << 
"Testing dependency number " << 
toString(i+1) << endl;
 
  387         cout << 
"  Specification:    " << dependencies[i] << endl;
 
  389         cout << 
"  Dependency type:  " << specification[0] << endl;
 
  390         cout << 
"  Dependency name:  " << specification[1] << endl;
 
  391         cout << 
"  Dependency value: " << specification[2] << endl;
 
  393       if (specification[0] == 
"att") {
 
  394         if ( element.hasAttributes() ) {
 
  395           QDomNamedNodeMap atts = element.attributes();
 
  396           QString attributeValue = atts.namedItem(specification[1]).nodeValue();
 
  399             cout << 
"  Attribute name:   " << atts.namedItem(specification[1]).nodeName();
 
  400             cout << 
"  Attribute value:  " << attributeValue << endl;
 
  402           if ( attributeValue != specification[2] ) {
 
  414       else if (specification[0] == 
"tag") {
 
  415         QDomElement candidateSibling = element.parentNode().firstChildElement(specification[1]);
 
  416         QString siblingValue = candidateSibling.text();
 
  419           cout << 
"  Tag name:         " << candidateSibling.tagName() << endl;
 
  420           cout << 
"  Tag value:        " << siblingValue << endl;
 
  422         if (siblingValue != specification[2] ) {
 
  430         QString msg = 
"Parsing error, dependency type [" + specification[0] +
 
  431                       "] is not [att] or [tag].";
 
  465      QFile xmlFile(xmlFileName.
expanded());
 
  466      if ( !xmlFile.open(QIODevice::ReadOnly) ) {
 
  467        QString msg = 
"Could not open label file [" + xmlFileName.
expanded() +
 
  474      if ( !
m_xmlLabel.setContent(&xmlFile, 
false, &errmsg, &errline, &errcol) ) {
 
  476        QString msg = 
"XML read/parse error in file [" + xmlFileName.
expanded()
 
  478             + 
"], message: " + errmsg;