7#include "LabelTranslationManager.h"
10#include <QDomDocument>
14#include "IException.h"
18#include "PvlContainer.h"
20#include "PvlKeyword.h"
22#include "PvlToXmlTranslationManager.h"
50 const QString &transFile)
82 validKeywords.push_back(pair<QString, int>(
"OutputAttributes", -1));
83 validKeywords.push_back(pair<QString, int>(
"OutputSiblings", -1));
110 while((grp =
InputGroup(transGroupName, inst++)).name() !=
"") {
134 QDomElement &parentElement) {
137 QString transGroupName = transGroup.name();
140 while (grp.name() !=
"") {
152 QString untranslatedValue = inputKeyword[0];
155 QString units = inputKeyword.unit();
156 if (outputName.size() == 2 && outputName[0] ==
"att") {
157 parentElement.setAttribute(outputName[1], translatedValue);
158 if (transGroup.hasKeyword(
"OutputAttributes")) {
159 addAttributes(transGroup.findKeyword(
"OutputAttributes"), parentElement);
163 QDomElement newElement = parentElement.ownerDocument().createElement(outputName[0]);
165 parentElement.appendChild(newElement);
166 if (transGroup.hasKeyword(
"OutputAttributes")) {
167 addAttributes(transGroup.findKeyword(
"OutputAttributes"), newElement);
171 if (transGroup.hasKeyword(
"OutputSiblings")) {
172 addSiblings(transGroup.findKeyword(
"OutputSiblings"), parentElement);
183 QDomElement newElement = parentElement.ownerDocument().createElement(
OutputName(transGroupName));
185 parentElement.appendChild(newElement);
186 if (transGroup.hasKeyword(
"OutputAttributes")) {
187 addAttributes(transGroup.findKeyword(
"OutputAttributes"), newElement);
189 if (transGroup.hasKeyword(
"OutputSiblings")) {
190 addSiblings(transGroup.findKeyword(
"OutputSiblings"), parentElement);
208 QDomDocument &outputLabel) {
228 QDomElement element = outputLabel.documentElement();
256 int instanceNumber = 0;
258 bool anInputGroupFound =
false;
260 while(inputGroupKeyword.name() !=
"") {
262 if(containingGroup != NULL) {
263 anInputGroupFound =
true;
271 inputGroupKeyword =
InputGroup(transGroupName, instanceNumber);
274 if(anInputGroupFound) {
275 QString msg =
"Unable to find input keyword [" +
InputKeywordName(transGroupName) +
276 "] for output name [" + transGroupName +
"] in file [" +
281 QString container =
"";
283 for(
int i = 0; i <
InputGroup(transGroupName).size(); i++) {
284 if(i > 0) container +=
",";
289 QString msg =
"Unable to find input group [" + container +
"] for output name [" +
312 while((grp =
InputGroup(transGroupName, inst++)).name() !=
"") {
334 if(inputGroup.size() == 1 &&
344 objectIndex < inputGroup.size() - 1;
346 if(currentObject->hasObject(inputGroup[objectIndex])) {
347 currentObject = ¤tObject->
findObject(inputGroup[objectIndex]);
355 if(currentObject->hasObject(inputGroup[objectIndex])) {
356 return ¤tObject->findObject(inputGroup[objectIndex]);
358 else if(currentObject->hasGroup(inputGroup[objectIndex])) {
359 return ¤tObject->findGroup(inputGroup[objectIndex]);
379 QDomElement &xmlRootElement) {
384 QDomElement *currentElement = &xmlRootElement;
389 if (containers.size() > 0 && currentElement->tagName() == containers[0]) {
394 while (i < containers.size()) {
400 bool addNewElement =
false;
402 if (specifications.size() == 2 && specifications[0] ==
"new") {
403 addNewElement =
true;
409 QDomElement childElement = xmlRootElement.ownerDocument().createElement(specifications[1]);
410 *currentElement = currentElement->appendChild(childElement).toElement();
414 else if (currentElement->namedItem(containers[i]).isNull()) {
415 QDomElement childElement = xmlRootElement.ownerDocument().createElement(specifications[0]);
416 *currentElement = currentElement->appendChild(childElement).toElement();
421 *currentElement = currentElement->firstChildElement(containers[i]);
425 return currentElement;
439 QDomElement &parent) {
441 for (
int i = 0; i < outputSiblings.size(); i++) {
443 parsedSibling.reserve(5);
445 if (parsedSibling.size() != 2) {
447 QString msg =
"Malformed OutputSibling [" + outputSiblings[i] +
"]. OutputSiblings must" +
448 " be in the form of tag|value";
452 if (parent.namedItem(parsedSibling[0]).isNull()) {
454 QDomElement childElement = parent.ownerDocument().createElement(parsedSibling[0]);
456 parent.appendChild(childElement).toElement();;
472 QDomElement &element) {
475 for (
int i = 0; i < outputAttributes.size(); i++) {
478 if (parsedAttribute.size() != 2) {
479 QString msg =
"Malformed output attribute [" + outputAttributes[i] +
480 "]. OutputAttributes must be in the form of att@attribute_name|value";
483 element.setAttribute(parsedAttribute[0], parsedAttribute[1]);
502 QDomElement newElement = parent.ownerDocument().createElement(name);
505 parent.appendChild(newElement).toElement();;
519 QDomText valueText = element.ownerDocument().createTextNode(value);
521 element.appendChild(valueText);
524 element.setAttribute(
"unit", units);
539 element.firstChild().setNodeValue(value);
541 element.setAttribute(
"unit", units);
@ Programmer
This error is for when a programmer made an API call that was illegal.
Allows applications to translate simple text files.
virtual QStringList parseSpecification(QString specification) const
Parses and validates a dependency specification.
Contains more than one keyword-value pair.
QString fileName() const
Returns the filename used to initialise the Pvl object.
Contains multiple PvlContainers.
Container for cube-like labels.
A single keyword-value pair.
static bool stringEqual(const QString &string1, const QString &string2)
Checks to see if two QStrings are equal.
Contains Pvl Groups and Pvl Objects.
PvlGroup & group(const int index)
Return the group at the specified index.
int groups() const
Returns the number of groups contained.
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
void SetLabel(Pvl &inputLabel)
Internalizes a Pvl formatted label for translation.
PvlToXmlTranslationManager(const QString &transFile)
Constructs and initializes a TranslationManager object from given the Pvl translation file.
void doTranslation(PvlGroup transGroup, QDomElement &parent)
Translate the requested output name to output values using the input name and values or default value...
virtual ~PvlToXmlTranslationManager()
Destroys the TranslationManager object.
QDomElement * createParentElements(const QString translationGroupName, QDomElement &xml)
Read the OutputPosition for the translation group name passed and create any parent elements specifie...
static void resetElementValue(QDomElement &element, QString value, QString units="")
Reset the QDomElement's value, and units, if units != "".
static void setElementValue(QDomElement &element, QString value, QString units="")
Set the QDomElement's value, and units, if units != "".
virtual bool InputHasKeyword(const QString translationGroupName)
Indicates if the input keyword corresponding to the output name exists in the label.
virtual QString Translate(QString translationGroupName, int inputIndex=0)
Returns a translated value.
void addSiblings(PvlKeyword outputSiblings, QDomElement &parent)
Take in outputSiblings PvlKeyword and turn each sibling into its corresponding QDomElement.
virtual std::vector< std::pair< QString, int > > validKeywords() const
Returns a vector of valid keyword names and their sizes.
void addAttributes(PvlKeyword something, QDomElement &parent)
Take in the outputAttributes PvlKeyword and add each attribute to the appropriate element given as an...
virtual const PvlKeyword & InputKeyword(const QString translationGroupName) const
Uses the translation file group name to find the input label's PvlKeyword that corresponds to the Inp...
virtual const PvlContainer * GetContainer(const PvlKeyword &inputGroup) const
Return a container from the input label with the path given by the "InputPosition" keyword of the tra...
void Auto(QDomDocument &outputLabel)
Automatically translate all the output names found in the translation table.
static void addElement(QDomElement &parent, QString name, QString value, QString units="")
Add a QDomElement to the given parent with the indicated value and units.
Pvl m_inputLabel
A Pvl object for the input label file.
bool IsOptional(const QString translationGroupName)
Determines whether the translation group is optional.
PvlKeyword OutputPosition(const QString translationGroupName)
Retrieves the OutputPosition PvlKeyword for the translation group with the given name.
virtual std::vector< std::pair< QString, int > > validKeywords() const
Returns a vector of valid keyword names and their sizes.
QString Translate(const QString translationGroupName, const QString inputKeyValue="") const
Translates a single output value from the given translation group name and input value.
QString OutputName(const QString translationGroupName)
Retrieves a string containing the value of the OutputName keyword for the translation group with the ...
virtual QString InputKeywordName(const QString translationGroupName) const
Returns the input keyword name from the translation table corresponding to the output name argument.
virtual PvlKeyword InputGroup(const QString translationGroupName, const int inst=0) const
Returns the input group name from the translation table corresponding to the output name argument.
bool IsAuto(const QString translationGroupName)
Determines whether the given group should be automatically translated.
Pvl & TranslationTable()
Protected accessor for pvl translation table passed into class.
This is free and unencumbered software released into the public domain.
Namespace for the standard library.