54 XmlToPvlTranslationManager::XmlToPvlTranslationManager(
const QString &transFile)
86 const QString &transFile)
103 std::istream &transStrm)
136 validKeywords.push_back(pair<QString, int>(
"InputKeyAttribute", -1));
137 validKeywords.push_back(pair<QString, int>(
"InputKeyDependencies", -1));
182 QString msg =
"Cannot translate value at index [" +
toString(index) +
183 "]. Xml files can only store a single value in each element.";
190 transGroup = transTable.
findGroup(translationGroupName);
193 QString msg =
"Unable to retrieve translation group from translation table.";
200 inputPosition = transGroup[
"InputPosition"];
203 QString msg =
"Unable to retrieve [InputPosition] keyword from " 204 "translation group.";
207 QString inputParentName = inputPosition[inputPosition.
size() - 1];
212 inputKey = transGroup[
"InputKey"][0];
215 QString msg =
"Unable to retrieve [InputKey] keyword from " 216 "translation group.";
219 QString attributeName;
220 if (transGroup.
hasKeyword(
"InputKeyAttribute")) {
221 attributeName = transGroup[
"InputKeyAttribute"][0];
226 if (transGroup.
hasKeyword(
"InputKeyDependencies")) {
227 keyDependencies = transGroup[
"InputKeyDependencies"];
231 bool isDebug = transGroup.
hasKeyword(
"Debug");
235 cout << endl <<
" ==================== " << endl;
236 cout << endl <<
"Translating output keyword: " << translationGroupName << endl;
237 cout << endl <<
"Translation group:" << endl;
238 cout << transGroup << endl << endl;
242 QDomElement inputParentElement =
m_xmlLabel.documentElement();
245 cout << endl <<
"Finding input element:" << endl << endl;
246 cout << inputParentElement.tagName() << endl;
253 QDomElement oldInputParentElement = inputParentElement;
255 while(it != transGroup.
end()) {
257 inputParentElement = oldInputParentElement;
259 for (
int i = 0; i < inputPosition.
size(); i++) {
260 childName = inputPosition[i];
261 inputParentElement = inputParentElement.firstChildElement(childName);
262 if(inputParentElement.isNull()) {
267 cout << indent << inputParentElement.tagName() << endl;
270 if (!inputParentElement.isNull()) {
273 it = transGroup.
findKeyword(
"InputPosition", it + 1, transGroup.
end());
276 if (inputParentElement.isNull()) {
279 cout << endl <<
"Could not traverse input position, " <<
280 "using default value: " <<
286 QString msg =
"Failed traversing input position. [" +
287 inputPosition.
name() +
"] element does not have a child element named [" +
293 QDomElement inputKeyElement = inputParentElement.firstChildElement(inputKey);
296 cout << indent << inputKeyElement.tagName() << endl;
300 while ( !inputParentElement.isNull() &&
303 cout << endl <<
"Dependencies failed, checking next candidate." << endl;
306 inputKeyElement = inputKeyElement.nextSiblingElement(inputKey);
308 while ( inputKeyElement.isNull() ) {
309 inputParentElement = inputParentElement.nextSiblingElement(inputParentName);
311 if ( inputParentElement.isNull() ) {
314 inputKeyElement = inputParentElement.firstChildElement(inputKey);
319 if ( inputParentElement.isNull() ) {
322 cout << endl <<
"No input value found, using default value: " <<
328 QString msg =
"Could not find an input or default value that fits the given input " 329 "keyword dependencies.";
335 QString inputValue = inputKeyElement.text();
337 if (attributeName.size() > 0) {
338 if ( inputKeyElement.hasAttribute(attributeName) ) {
339 inputValue = inputKeyElement.attribute(attributeName);
343 cout << endl <<
"No input value found, using default value: " <<
349 QString msg =
"Input element [" + inputKeyElement.tagName() +
350 "] does not have an attribute named [" +
351 attributeName +
"].";
356 cout << endl <<
"Translating input value: " << inputValue << endl;
361 QString msg =
"Failed to translate output value for [" + translationGroupName +
"].";
392 cout << endl <<
"Testing dependencies:" << endl;
394 for (
int i = 0; i < dependencies.
size(); i++) {
397 if (specification.size() != 3) {
401 cout << endl <<
"Testing dependency number " <<
toString(i+1) << endl;
402 cout <<
" Specification: " << dependencies[i] << endl;
404 cout <<
" Dependency type: " << specification[0] << endl;
405 cout <<
" Dependency name: " << specification[1] << endl;
406 cout <<
" Dependency value: " << specification[2] << endl;
408 if (specification[0] ==
"att") {
409 if ( element.hasAttributes() ) {
410 QDomNamedNodeMap atts = element.attributes();
411 QString attributeValue = atts.namedItem(specification[1]).nodeValue();
414 cout <<
" Attribute name: " << atts.namedItem(specification[1]).nodeName();
415 cout <<
" Attribute value: " << attributeValue << endl;
417 if ( attributeValue != specification[2] ) {
429 else if (specification[0] ==
"tag") {
430 QDomElement candidateSibling = element.parentNode().firstChildElement(specification[1]);
431 QString siblingValue = candidateSibling.text();
434 cout <<
" Tag name: " << candidateSibling.tagName() << endl;
435 cout <<
" Tag value: " << siblingValue << endl;
437 if (siblingValue != specification[2] ) {
445 QString msg =
"Parsing error, dependency type [" + specification[0] +
446 "] is not [att] or [tag].";
480 QFile xmlFile(xmlFileName.
expanded());
481 if ( !xmlFile.open(QIODevice::ReadOnly) ) {
482 QString msg =
"Could not open label file [" + xmlFileName.
expanded() +
489 if ( !
m_xmlLabel.setContent(&xmlFile,
false, &errmsg, &errline, &errcol) ) {
491 QString msg =
"XML read/parse error in file [" + xmlFileName.
expanded()
493 +
"], message: " + errmsg;
PvlKeywordIterator end()
Return the ending iterator.
QDomDocument m_xmlLabel
The contents of the xml label.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
bool hasInputDefault(const QString translationGroupName)
Determines whether the given group has a default input value.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
File name manipulation and expansion.
virtual QStringList parseSpecification(QString specification) const
Parses and validates a dependency specification.
void SetLabel(FileName &inputLabel)
Reads an Xml label file and internalizes it for translation.
PvlKeywordIterator begin()
Return the beginning iterator.
Namespace for the standard library.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
virtual QString Translate(QString translationGroupName, int findex=0)
Returns a translated value.
QString Translate(const QString translationGroupName, const QString inputKeyValue="") const
Translates a single output value from the given translation group name and input value.
void AddTable(std::istream &transStm)
Adds the contents of a translation table to the searchable groups/keys Also performs a verification...
int size() const
Returns the number of values stored in this keyword.
virtual std::vector< std::pair< QString, int > > validKeywords() const
Returns a vector of valid keyword names and their sizes.
Pvl & TranslationTable()
Protected accessor for pvl translation table passed into class.
Contains multiple PvlContainers.
#define _FILEINFO_
Macro for the filename and line number.
A single keyword-value pair.
A type of error that cannot be classified as any of the other error types.
XmlToPvlTranslationManager(const QString &transFile)
Constructs and initializes an XmlToPvlTranslationManager object from the given Pvl translation file...
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
virtual std::vector< std::pair< QString, int > > validKeywords() const
Returns a vector of valid keyword names and their sizes.
Container for cube-like labels.
void parseFile(const FileName &xmlFileName)
Opens, parses, and internalizes an Xml label file.
void Auto(FileName &inputLabel, Pvl &outputLabel)
Automatically translate all the output names flagged with the Auto keyword in the translation table a...
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
bool checkDependencies(QDomElement element, PvlKeyword dependencies, bool isDebug) const
Checks if a element in the xml label satisfies a list of dependencies.
QString name() const
Returns the keyword name.
Namespace for ISIS/Bullet specific routines.
virtual ~XmlToPvlTranslationManager()
Destroys the XmlToPvlTranslationManager object.
Allows applications to translate simple text files.
QString InputDefault(const QString translationGroupName) const
Returns the input default value from the translation table corresponding to the output name argument...
QList< PvlKeyword >::const_iterator ConstPvlKeywordIterator
The const keyword iterator.