Isis Developer Reference
|
Allows applications to translate Xml label files. More...
#include <XmlToPvlTranslationManager.h>
Public Member Functions | |
XmlToPvlTranslationManager (const QString &transFile) | |
Constructs and initializes an XmlToPvlTranslationManager object from the given Pvl translation file. More... | |
XmlToPvlTranslationManager (std::istream &transStrm) | |
Constructs and initializes an XmlToPvlTranslationManager object from the given input stream. More... | |
XmlToPvlTranslationManager (FileName &inputLabel, const QString &transFile) | |
Constructs and initializes an XmlToPvlTranslationManager object from the given Pvl translation file and input label. More... | |
XmlToPvlTranslationManager (FileName &inputLabel, std::istream &transStrm) | |
Constructs and initializes an XmlToPvlTranslationManager object from the given input stream and input label. More... | |
virtual | ~XmlToPvlTranslationManager () |
Destroys the XmlToPvlTranslationManager object. More... | |
virtual QString | Translate (QString translationGroupName, int findex=0) |
Returns a translated value. More... | |
void | Auto (FileName &inputLabel, Pvl &outputLabel) |
Automatically translate all the output names flagged with the Auto keyword in the translation table and store the translated key, value pairs in the argument pvl. More... | |
void | SetLabel (FileName &inputLabel) |
Reads an Xml label file and internalizes it for translation. More... | |
virtual void | Auto (Pvl &outputLabel) |
Automatically translate all the output names tagged as Auto in the translation table If a output name does not translate an error will be thrown by one of the support members. More... | |
QString | Translate (const QString translationGroupName, const QString inputKeyValue="") const |
Translates a single output value from the given translation group name and input value. More... | |
virtual void | Auto (Pvl &outputLabel) |
Automatically translate all the output names tagged as Auto in the translation table If a output name does not translate an error will be thrown by one of the support members. More... | |
virtual QStringList | parseSpecification (QString specification) const |
Parses and validates a dependency specification. More... | |
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. More... | |
virtual QString | InputKeywordName (const QString translationGroupName) const |
Returns the input keyword name from the translation table corresponding to the output name argument. More... | |
QString | InputDefault (const QString translationGroupName) const |
Returns the input default value from the translation table corresponding to the output name argument. More... | |
void | AddTable (std::istream &transStm) |
Adds the contents of a translation table to the searchable groups/keys Also performs a verification, to ensure that the translation table is valid. More... | |
void | AddTable (const QString &transFile) |
Adds the contents of a translation table to the searchable groups/keys. More... | |
Protected Member Functions | |
virtual std::vector< std::pair< QString, int > > | validKeywords () const |
Returns a vector of valid keyword names and their sizes. More... | |
bool | checkDependencies (QDomElement element, PvlKeyword dependencies, bool isDebug) const |
Checks if a element in the xml label satisfies a list of dependencies. More... | |
void | parseFile (const FileName &xmlFileName) |
Opens, parses, and internalizes an Xml label file. More... | |
virtual PvlKeyword | DoTranslation (const QString translationGroupName) |
Translate the requested output name to output values using the input name and values or default value. More... | |
virtual PvlContainer * | CreateContainer (const QString translationGroupName, Pvl &pvl) |
Creates all parent PVL containers for an output keyword. More... | |
Pvl & | TranslationTable () |
Protected accessor for pvl translation table passed into class. More... | |
const Pvl & | TranslationTable () const |
Protected accessor for const pvl translation table passed into class. More... | |
bool | hasInputDefault (const QString translationGroupName) |
Determines whether the given group has a default input value. More... | |
bool | IsAuto (const QString translationGroupName) |
Determines whether the given group should be automatically translated. More... | |
bool | IsOptional (const QString translationGroupName) |
Determines whether the translation group is optional. More... | |
PvlKeyword | OutputPosition (const QString translationGroupName) |
Retrieves the OutputPosition PvlKeyword for the translation group with the given name. More... | |
QString | OutputName (const QString translationGroupName) |
Retrieves a string containing the value of the OutputName keyword for the translation group with the given name. More... | |
const PvlGroup & | findTranslationGroup (const QString translationGroupName) const |
Searches for translation group with the given name. More... | |
Allows applications to translate Xml label files.
This class allows for translating Xml label files into Pvl objects. The translation process is driven by the output keyword names. Given an output keyword name, the Translate method uses the translation table to find the input value and then translates it into the output value.
The translation table is a Pvl object containing a Pvl group for each output keyword. The translation group for an output keyword is named the output keyword's name. The required PvlKeywords in a translation group are:
There are also optional keywords to modify the translation:
TYPE@NAME:VALUE
. The type is either tag
or att
indicating to check the value of an element of attribute respectively. An example Xml translation table can be found at $ISISROOT/appdata/translations/XmlLabel.trn.
Isis::XmlToPvlTranslationManager::XmlToPvlTranslationManager | ( | const QString & | transFile | ) |
Constructs and initializes an XmlToPvlTranslationManager object from the given Pvl translation file.
If this constructor is used, the user will need to set the input label before translating. This may be done by using SetLabel(FileName inputLabel) or Auto(FileName inputLabel, Pvl outputLabel).
transFile | The translation file to be used to tranlate keywords in the input label. |
References Isis::PvlTranslationTable::AddTable().
Isis::XmlToPvlTranslationManager::XmlToPvlTranslationManager | ( | std::istream & | transStrm | ) |
Constructs and initializes an XmlToPvlTranslationManager object from the given input stream.
If this constructor is used, the user will need to set the input label before translating. This may be done by using SetLabel(FileName inputLabel) or Auto(FileName inputLabel, Pvl outputLabel).
transStrm | A stream containing the tranlation table to be used to tranlate keywords in the input label. |
References Isis::PvlTranslationTable::AddTable().
Isis::XmlToPvlTranslationManager::XmlToPvlTranslationManager | ( | FileName & | inputLabel, |
const QString & | transFile | ||
) |
Constructs and initializes an XmlToPvlTranslationManager object from the given Pvl translation file and input label.
inputLabel | The Xml holding the input label. |
transFile | The translation file to be used to tranlate keywords in the input label. |
References Isis::PvlTranslationTable::AddTable(), and parseFile().
Isis::XmlToPvlTranslationManager::XmlToPvlTranslationManager | ( | FileName & | inputLabel, |
std::istream & | transStrm | ||
) |
Constructs and initializes an XmlToPvlTranslationManager object from the given input stream and input label.
inputLabel | The Xml holding the input label. |
transStrm | A stream containing the tranlation table to be used to tranlate keywords in the input label. |
References Isis::PvlTranslationTable::AddTable(), and parseFile().
|
virtual |
Destroys the XmlToPvlTranslationManager object.
|
inherited |
Adds the contents of a translation table to the searchable groups/keys.
transFile | The name of the translation file to be added. |
References Isis::Pvl::read().
|
inherited |
Adds the contents of a translation table to the searchable groups/keys Also performs a verification, to ensure that the translation table is valid.
transStm | The stream to be added. |
IException::User | - "Unable to find InputKey for group in translation file." |
IException::User | - "Keyword is not valid. Error in file." |
IException::User | - "Keyword does not have correct number of elements. Error in file." |
References _FILEINFO_, Isis::PvlContainer::hasKeyword(), Isis::PvlContainer::keywords(), Isis::PvlContainer::name(), Isis::PvlKeyword::name(), and Isis::PvlKeyword::size().
Referenced by Isis::LabelTranslationManager::LabelTranslationManager(), and XmlToPvlTranslationManager().
Automatically translate all the output names flagged with the Auto keyword in the translation table and store the translated key, value pairs in the argument pvl.
inputLabel | The input label file to be translated. |
outputLabel | The output translated Pvl. |
References Auto(), and parseFile().
|
virtualinherited |
Automatically translate all the output names tagged as Auto in the translation table If a output name does not translate an error will be thrown by one of the support members.
The results of the translations will be stored in the outputLabel PVL based on the OutputPosition keywords in the translation table.
outputLabel | The PVL to add the translated keywords to. |
Reimplemented in Isis::PvlToPvlTranslationManager.
References Isis::LabelTranslationManager::CreateContainer(), Isis::LabelTranslationManager::DoTranslation(), Isis::PvlObject::group(), Isis::PvlObject::groups(), Isis::PvlTranslationTable::IsAuto(), Isis::PvlTranslationTable::IsOptional(), Isis::PvlContainer::name(), and Isis::PvlTranslationTable::TranslationTable().
void Isis::LabelTranslationManager::Auto |
Automatically translate all the output names tagged as Auto in the translation table If a output name does not translate an error will be thrown by one of the support members.
The results of the translations will be stored in the outputLabel PVL based on the OutputPosition keywords in the translation table.
outputLabel | The PVL to add the translated keywords to. |
Referenced by Auto().
|
protected |
Checks if a element in the xml label satisfies a list of dependencies.
Checks if a element in the xml label satisfies a list of dependencies. The dependencies are requirements on the values of attributes of the element and/or the values of sibling elements. The dependencies are specified by strings that are formatted as follows [tag/att]@[tagName/attName]|[value]
or [tagName/attName]|[value]
element | The element to check dependencies on. |
dependencies | A multi-valued keyword were every entry specifies a requirement upon either an attribute of the element or a sibling of the element. |
IException::Unknown | "Parsing error, dependency type is not [att] or [tag]." |
References _FILEINFO_, Isis::LabelTranslationManager::parseSpecification(), Isis::PvlKeyword::size(), Isis::toString(), and Isis::IException::Unknown.
Referenced by Translate().
|
protectedvirtualinherited |
Creates all parent PVL containers for an output keyword.
If any parent containers already exist then they will not be recreated.
translationGroupName | The name of the output keyword. The OutputPosition keyword in the translation group for translationGroupName will be used to determine which containers are made. |
pvl | The PVL file to create the containers in. |
Reimplemented in Isis::PvlToPvlTranslationManager.
References Isis::PvlObject::addGroup(), Isis::PvlObject::addObject(), Isis::PvlObject::findGroup(), Isis::PvlObject::findObject(), Isis::PvlObject::hasGroup(), Isis::PvlObject::hasObject(), Isis::PvlTranslationTable::OutputPosition(), and Isis::PvlKeyword::size().
Referenced by Isis::LabelTranslationManager::Auto(), and Isis::PvlToPvlTranslationManager::CreateContainer().
|
protectedvirtualinherited |
Translate the requested output name to output values using the input name and values or default value.
outputName | The output name used to identify the input keyword to be translated. |
@TODO output units
Reimplemented in Isis::PvlToPvlTranslationManager.
References Isis::LabelTranslationManager::Translate().
Referenced by Isis::LabelTranslationManager::Auto().
|
protectedinherited |
Searches for translation group with the given name.
translationGroupName | The name of the PVL translation group used to identify the input/output keywords to be translated. Often, this is the same as the output keyword name. |
IException::Programmer | - "Unable to find translation group in file." |
References _FILEINFO_, and Isis::PvlContainer::fileName().
|
protectedinherited |
Determines whether the given group has a default input value.
This method returns true if the translation group contains a PvlKeyword with the name "InputDefault". Note: no value needs to be assigned to this keyword.
translationGroupName | The name of the PVL translation group used to identify the input/output keywords to be translated. Often, this is the same as the output keyword name. |
References Isis::PvlContainer::hasKeyword().
Referenced by Translate().
|
inherited |
Returns the input default value from the translation table corresponding to the output name argument.
translationGroupName | The name of the PVL translation group used to identify the input/output keywords to be translated. Often, this is the same as the output keyword name. |
References Isis::PvlContainer::hasKeyword().
Referenced by Translate().
|
virtualinherited |
Returns the input group name from the translation table corresponding to the output name argument.
translationGroupName | The name of the PVL translation group used to identify the input/output keywords to be translated. Often, this is the same as the output keyword name. |
inst | The occurence number of the "InputGroup" keyword (first one is zero) |
IException::Programmer | - "Keyword [InputPosition] cannot have a comma [,] in the value." |
References _FILEINFO_, Isis::PvlContainer::begin(), Isis::PvlContainer::end(), Isis::PvlContainer::findKeyword(), and Isis::PvlKeyword::size().
Referenced by Isis::PvlToPvlTranslationManager::DoTranslation(), Isis::PvlToXmlTranslationManager::doTranslation(), Isis::PvlToPvlTranslationManager::InputHasKeyword(), Isis::PvlToXmlTranslationManager::InputHasKeyword(), Isis::PvlToPvlTranslationManager::InputKeyword(), Isis::PvlToXmlTranslationManager::InputKeyword(), Isis::PvlToPvlTranslationManager::Translate(), and Isis::PvlToXmlTranslationManager::Translate().
|
virtualinherited |
Returns the input keyword name from the translation table corresponding to the output name argument.
translationGroupName | The name of the PVL translation group used to identify the input/output keywords to be translated. Often, this is the same as the output keyword name. |
IException::Programmer |
References Isis::PvlContainer::hasKeyword().
Referenced by Isis::PvlToXmlTranslationManager::doTranslation(), Isis::PvlToPvlTranslationManager::InputHasKeyword(), Isis::PvlToXmlTranslationManager::InputHasKeyword(), Isis::PvlToPvlTranslationManager::InputKeyword(), Isis::PvlToXmlTranslationManager::InputKeyword(), Isis::PvlToPvlTranslationManager::Translate(), and Isis::PvlToXmlTranslationManager::Translate().
|
protectedinherited |
Determines whether the given group should be automatically translated.
This method returns true if the translation group contains a PvlKeyword with the name "Auto". Note: no value is assigned to this keyword.
translationGroupName | The name of the PVL translation group used to identify the input/output keywords to be translated. Often, this is the same as the output keyword name. |
References Isis::PvlContainer::hasKeyword().
Referenced by Isis::LabelTranslationManager::Auto(), Isis::PvlToPvlTranslationManager::Auto(), and Isis::PvlToXmlTranslationManager::Auto().
|
protectedinherited |
Determines whether the translation group is optional.
This method returns true if the translation group contains a PvlKeyword with the name "Optional". Note: no value is assigned to this keyword.
translationGroupName | The name of the PVL translation group used to identify the input/output keywords to be translated. Often, this is the same as the output keyword name. |
References Isis::PvlContainer::hasKeyword().
Referenced by Isis::LabelTranslationManager::Auto(), Isis::PvlToPvlTranslationManager::Auto(), and Isis::PvlToXmlTranslationManager::Auto().
|
protectedinherited |
Retrieves a string containing the value of the OutputName keyword for the translation group with the given name.
translationGroupName | The name of the PVL translation group used to identify the input/output keywords to be translated. Often, this is the same as the output keyword name. |
References Isis::PvlContainer::hasKeyword().
Referenced by Isis::PvlToPvlTranslationManager::DoTranslation(), and Isis::PvlToXmlTranslationManager::doTranslation().
|
protectedinherited |
Retrieves the OutputPosition PvlKeyword for the translation group with the given name.
translationGroupName | The name of the PVL translation group used to identify the input/output keywords to be translated. Often, this is the same as the output keyword name. |
IException::Programmer | - "Unable to find translation keyword [OutputPostion] in translation group in file." |
References _FILEINFO_, and Isis::PvlContainer::hasKeyword().
Referenced by Isis::LabelTranslationManager::CreateContainer(), and Isis::PvlToXmlTranslationManager::createParentElements().
|
protected |
Opens, parses, and internalizes an Xml label file.
xmlFileName | The Xml label file. |
IException::Unknown | "Could not open label file." |
IException::Unknown | "XML read/parse error in file." |
References _FILEINFO_, Isis::FileName::expanded(), Isis::toString(), and Isis::IException::Unknown.
Referenced by Auto(), SetLabel(), and XmlToPvlTranslationManager().
|
virtualinherited |
Parses and validates a dependency specification.
specification | The dependency specification string. |
IException::Programmer | "Malformed dependency specification." |
IException::Programmer | "Specification does not have two components separated by [@], the type of dependency and the name-value pair. |
IException::Programmer | "Dependency type specification is invalid. Valid types are [att] and [tag]" |
IException::Programmer | "Name-value specification does not have two components separated by [|]." |
References _FILEINFO_, and Isis::IException::Programmer.
Referenced by Isis::PvlToXmlTranslationManager::addAttributes(), Isis::PvlToXmlTranslationManager::addSiblings(), checkDependencies(), Isis::PvlToXmlTranslationManager::createParentElements(), and Isis::PvlToXmlTranslationManager::doTranslation().
void Isis::XmlToPvlTranslationManager::SetLabel | ( | FileName & | inputLabel | ) |
Reads an Xml label file and internalizes it for translation.
inputLabel | The input label file |
References parseFile().
|
inherited |
Translates a single output value from the given translation group name and input value.
translationGroupName | The name of the PVL translation group used to identify the input/output keywords to be translated. Often, this is the same as the output keyword name. |
inputKeyValue | The value to be translated, from the input keyword. |
IException::Programmer | - "No value or default value to translate for translation group." |
IException::Programmer | - "Unable to find translation value in file." |
References _FILEINFO_, Isis::PvlContainer::begin(), Isis::PvlContainer::end(), Isis::PvlContainer::fileName(), Isis::PvlContainer::findKeyword(), and Isis::PvlContainer::hasKeyword().
Referenced by Isis::PvlToPvlTranslationManager::DoTranslation(), Isis::PvlToXmlTranslationManager::doTranslation(), Isis::PvlToPvlTranslationManager::Translate(), Translate(), and Isis::PvlToXmlTranslationManager::Translate().
|
virtual |
Returns a translated value.
The translation group name is used to find the input group, keyword, default and tranlations in the translation table. If the keyword does not exist in the input label, the input default if available will be used as the input value. This input value is then used to search all of the translations. If a match is found the translated value is returned.
translationGroupName | The name of the PVL translation group used to identify the input/output keywords to be translated. Often, this is the same as the output keyword name. |
index | The index into the input keyword array. Defaults to 0 |
IException::Unknown | "Failed to translate output value." |
IException::Unknown | "Cannot translate value. Xml files can only store a single value in each element." |
IException::Unknown | "Unable to retrieve translation group from translation table." |
IException::Unknown | "Unable to retrieve [InputPosition] keyword from translation group." |
IException::Unknown | "Unable to retrieve [InputKey] keyword from translation group." |
IException::Unknown | "Failed traversing input position. Element does not have the named child element." |
IException::Unknown | "Could not find an input value or default value." |
IException::Unknown | "Input element does not have the named attribute." |
Implements Isis::LabelTranslationManager.
References _FILEINFO_, Isis::PvlContainer::begin(), checkDependencies(), Isis::PvlContainer::end(), Isis::PvlObject::findGroup(), Isis::PvlContainer::findKeyword(), Isis::PvlTranslationTable::hasInputDefault(), Isis::PvlContainer::hasKeyword(), Isis::PvlTranslationTable::InputDefault(), Isis::PvlKeyword::name(), Isis::PvlKeyword::size(), Isis::toString(), Isis::PvlTranslationTable::Translate(), Isis::PvlTranslationTable::TranslationTable(), and Isis::IException::Unknown.
|
protectedinherited |
Protected accessor for pvl translation table passed into class.
This method returns a reference to the translation table member.
Referenced by Isis::LabelTranslationManager::Auto(), Isis::PvlToPvlTranslationManager::Auto(), Isis::PvlToXmlTranslationManager::Auto(), Isis::PvlToPvlTranslationManager::DoTranslation(), Isis::PvlToPvlTranslationManager::InputKeyword(), Isis::PvlToXmlTranslationManager::InputKeyword(), and Translate().
|
protectedinherited |
Protected accessor for const pvl translation table passed into class.
This method returns a const reference to the translation table member.
|
protectedvirtual |
Returns a vector of valid keyword names and their sizes.
A size of -1 indicates that the keyword can be any size.
Reimplemented from Isis::PvlTranslationTable.
References Isis::PvlTranslationTable::validKeywords().