예제 #1
0
void SimulationMaker::readParameterElement(QObject* parent)
{
    Q_ASSERT(reader->isStartElement() && parent);

    QString name = attributeValue("name", parent);
    QString value = attributeValue("value", "");
    QString variableName = attributeValue("variable", "");

    bool hasValue = !value.isEmpty();
    bool hasVariable = !variableName.isEmpty();
    if (hasValue && hasVariable)
        throw Exception("Parameter '" + name +
                        "' cannot have both a 'value' and a 'variable' attribute", parent);
    if (!hasValue && !hasVariable)
        throw Exception("Parameter '" + name +
                        "' must have either a 'value' or a 'variable' attribute", parent);

    ParameterBase *parameter = seekOneChild<ParameterBase*>(name, parent);
    if (hasValue)
        parameter->setValueFromString(value.trimmed());
    else
        redirectedParameters.append(RedirectedParameter(parameter, variableName));

	nextElementDelim();
	Q_ASSERT(reader->isEndElement());
	nextElementDelim();
}
예제 #2
0
void SimulationMaker::readVariableElement(QObject* parent)
{
	Q_ASSERT(reader->isStartElement() && parent);
    OutputVariable::Raw raw;

    raw.label = attributeValue("label");
    if (raw.label.isEmpty())
        throw Exception(message("Missing 'label' attribute for 'variable' element"));

    raw.axis = attributeValue("axis");
    if (raw.axis.isEmpty())
        throw Exception(message("Missing 'axis' attribute for 'variable' element"));

    QString value = attributeValue("value");
    if (value.isEmpty())
        throw Exception(message("Missing 'value' attribute for 'variable' element"));

    QStringList parts = value.split("[");
    if (parts.size() != 2 || parts[1].right(1) != "]" || parts[1].size() == 1)
        throw Exception(message("Value of variable is not of the form 'x/y/z[state]' "));

    raw.modelName = parts[0];
    raw.stateNameInModel = parts[1].left(parts[1].size()-1);

    OutputVariable::appendVariable(raw, parent);

    nextElementDelim();
    Q_ASSERT(reader->isEndElement());
    nextElementDelim();
}
예제 #3
0
/*!
  Returns the value of the user label attribute of this tuple.
  The user label can be of the following forms:
   - a simple text string
   - a attribute name - will be replaced with the current value
   - a \ref QString argument comma-separated list where the first
     argument is a format string (see \ref QString::arg()) with
     parameters %1-%9, plus %+1-9, %++1-9 etc. The subsequent
     arguments can be simple text strings or attribute names.
*/
const QString QmvTuple::userLabelValue() const
{
    QStringList ul_list = parent_class->userLabelList();
    QString ulv;

        // null
    if ( ul_list.count() == 0 )
        return ulv;

        // the first arg may be a QString format list
    if ( tupleAttribute( ul_list[0] ) )
            ulv.append( attributeValue( ul_list[0] ));
    else
        ulv.append(ul_list[0] );

        // muliple arguments, so expand with arg()
    for ( int i = 1; i < ul_list.count(); i ++ )
    {
            // a kludge to get more than 9 arguments
        if ( i > 9 && i % 9 == 1 )
            ulv.replace( QRegExp("%\\+"), "%" );
        if ( tupleAttribute( ul_list[i] ) )
            ulv = ulv.arg( attributeValue( ul_list[i] ));
        else
            ulv = ulv.arg(ul_list[i] );
    }
        
    return(ulv);

}
예제 #4
0
void FB2TagInfoReader::startElementHandler(const char *tag, const char **attributes) {
	if ((SUBGENRE_TAG == tag) || (SUBGENRE_ALT_TAG == tag)) {
		const char *id = attributeValue(attributes, "value");
		if (id != 0) {
			myGenreIds.push_back(id);
		}
	} else if (CATEGORY_NAME_TAG == tag) {
		const char *lang = attributeValue(attributes, "lang");
		if ((lang != 0) && (myLanguage == lang)) {
			const char *name = attributeValue(attributes, "genre-title");
			if (name != 0) {
				myCategoryName = name;
				ZLUnicodeUtil::utf8Trim(myCategoryName);
			}
		}
	} else if (SUBCATEGORY_NAME_TAG == tag) {
		const char *lang = attributeValue(attributes, "lang");
		if ((lang != 0) && (myLanguage == lang)) {
			const char *name = attributeValue(attributes, "title");
			if (name != 0) {
				mySubCategoryName = name;
				ZLUnicodeUtil::utf8Trim(mySubCategoryName);
			}
		}
	}
}
예제 #5
0
void XHTMLReader::startElementHandler(const char *tag, const char **attributes) {
	static const std::string HASH = "#";
	const char *id = attributeValue(attributes, "id");
	if (id != 0) {
		myModelReader.addHyperlinkLabel(myReferenceName + HASH + id);
	}

	const std::string sTag = ZLUnicodeUtil::toLower(tag);

	const char *aClass = attributeValue(attributes, "class");
	const std::string sClass = (aClass != 0) ? aClass : "";

	if (myStyleSheetTable.doBreakBefore(sTag, sClass)) {
		myModelReader.insertEndOfSectionParagraph();
	}
	myDoPageBreakAfterStack.push_back(myStyleSheetTable.doBreakAfter(sTag, sClass));

	XHTMLTagAction *action = ourTagActions[sTag];
	if (action != 0) {
		action->doAtStart(*this, attributes);
	}

	const int sizeBefore = myStyleEntryStack.size();
	addStyleEntry(sTag, "");
	addStyleEntry("", sClass);
	addStyleEntry(sTag, sClass);
	const char *style = attributeValue(attributes, "style");
	if (style != 0) {
		shared_ptr<ZLTextStyleEntry> entry = myStyleParser.parseString(style);
		myModelReader.addControl(*entry);
		myStyleEntryStack.push_back(entry);
	}
	myCSSStack.push_back(myStyleEntryStack.size() - sizeBefore);
}
예제 #6
0
void ZLEncodingCollectionReader::startElementHandler(const char *tag, const char **attributes) {
	if (GROUP == tag) {
		const char *name = attributeValue(attributes, NAME.c_str());
		if (name != 0) {
			myCurrentSet = new ZLEncodingSet(name);
		}
	} else if (!myCurrentSet.isNull()) {
		if (ENCODING == tag) {
			const char *name = attributeValue(attributes, NAME.c_str());
			const char *region = attributeValue(attributes, REGION.c_str());
			if ((name != 0) && (region != 0)) {
				const std::string sName = name;
				myCurrentInfo = new ZLEncodingConverterInfo(sName, region);
				myNames.push_back(sName);
			}
		} else if (!myCurrentInfo.isNull()) {
			const char *name = 0;
			if (CODE == tag) {
				name = attributeValue(attributes, NUMBER.c_str());
			} else if (ALIAS == tag) {
				name = attributeValue(attributes, NAME.c_str());
			}
			if (name != 0) {
				const std::string sName = name;
				myCurrentInfo->addAlias(sName);
				myNames.push_back(sName);
			}
		}
	}
}
예제 #7
0
void FB2DescriptionReader::startElementHandler(int tag, const char **attributes) {
	switch (tag) {
		case _BODY:
			myReturnCode = true;
			interrupt();
			break;
		case _TITLE_INFO:
			myReadState = READ_SOMETHING;
			break;
		case _BOOK_TITLE:
			if (myReadState == READ_SOMETHING) {
				myReadState = READ_TITLE;
			}
			break;
		case _GENRE:
			if (myReadState == READ_SOMETHING) {
				myReadState = READ_GENRE;
			}
			break;
		case _AUTHOR:
			if (myReadState == READ_SOMETHING) {
				myReadState = READ_AUTHOR;
			}
			break;
		case _LANG:
			if (myReadState == READ_SOMETHING) {
				myReadState = READ_LANGUAGE;
			}
			break;
		case _FIRST_NAME:
			if (myReadState == READ_AUTHOR) {
				myReadState = READ_AUTHOR_NAME_0;
			}
			break;
		case _MIDDLE_NAME:
			if (myReadState == READ_AUTHOR) {
				myReadState = READ_AUTHOR_NAME_1;
			}
			break;
		case _LAST_NAME:
			if (myReadState == READ_AUTHOR) {
				myReadState = READ_AUTHOR_NAME_2;
			}
			break;
		case _SEQUENCE:
			if (myReadState == READ_SOMETHING) {
				const char *name = attributeValue(attributes, "name");
				if (name != 0) {
					std::string seriesName = name;
					ZLStringUtil::stripWhiteSpaces(seriesName);
					myBook.setSeriesName(seriesName);
					const char *number = attributeValue(attributes, "number");
					myBook.setNumberInSeries( (number != 0) ? atoi(number) : 0 );
				}
			}
			break;
		default:
			break;
	}
}
예제 #8
0
bool SimulationMaker::readOutputElement(QObject* parent)
{
	Q_ASSERT(reader->isStartElement() && parent);
	

    QString objectName = attributeValue("name");
	if (objectName.isEmpty()) objectName = "anonymous";
    QString type = attributeValue("type").toLower();

    Output *output;
    try {
        output = OutputMaker::create(type, objectName, parent);
    }
    catch (Exception &ex) {
        throw Exception(message(ex.message()));
    }

	nextElementDelim();
	while (!reader->hasError() && reader->isStartElement()) {
        if (elementNameEquals("parameter")) {
            readParameterElement(output);
        }
        else if (elementNameEquals("variable")) {
            readVariableElement(output);
        }
        else {
            throw Exception(message(
                    "Unknown element in 'output' element: " + elementName()));
		}
	}	
	Q_ASSERT(reader->isEndElement());
	nextElementDelim();
    return output;
}	
예제 #9
0
void XHTMLReader::startElementHandler(const char *tag, const char **attributes) {
	static const std::string HASH = "#";
	const char *id = attributeValue(attributes, "id");
	if (id != 0) {
		myModelReader.addHyperlinkLabel(myReferenceAlias + HASH + id);
	}

	const std::string sTag = ZLUnicodeUtil::toLower(tag);

	std::vector<std::string> classesList;
	const char *aClasses = attributeValue(attributes, "class");
	if (aClasses != 0) {
		const std::vector<std::string> split = ZLStringUtil::split(aClasses, " ");
		for (std::vector<std::string>::const_iterator it = split.begin(); it != split.end(); ++it) {
			if (!it->empty()) {
				classesList.push_back(*it);
			}
		}
	}
	if (classesList.empty()) {
		classesList.push_back("");
	}

	bool breakBefore = false;
	bool breakAfter = false;
	for (std::vector<std::string>::const_iterator it = classesList.begin(); it != classesList.end(); ++it) {
		// TODO: use 3-value logic (yes, no, inherit)
		if (myStyleSheetTable.doBreakBefore(sTag, *it)) {
			breakBefore = true;
		}
		// TODO: use 3-value logic (yes, no, inherit)
		if (myStyleSheetTable.doBreakAfter(sTag, *it)) {
			breakAfter = true;
		}
	}
	if (breakBefore) {
		myModelReader.insertEndOfSectionParagraph();
	}
	myDoPageBreakAfterStack.push_back(breakAfter);

	XHTMLTagAction *action = getAction(sTag);
	if (action != 0 && action->isEnabled(myReadState)) {
		action->doAtStart(*this, attributes);
	}

	const int sizeBefore = myStyleEntryStack.size();
	addTextStyleEntry(sTag, "");
	for (std::vector<std::string>::const_iterator it = classesList.begin(); it != classesList.end(); ++it) {
		addTextStyleEntry("", *it);
		addTextStyleEntry(sTag, *it);
		const char *style = attributeValue(attributes, "style");
		if (style != 0) {
			//ZLLogger::Instance().println("CSS", std::string("parsing style attribute: ") + style);
			shared_ptr<ZLTextStyleEntry> entry = myStyleParser->parseSingleEntry(style);
			addTextStyleEntry(*entry);
			myStyleEntryStack.push_back(entry);
		}
	}
	myCSSStack.push_back(myStyleEntryStack.size() - sizeBefore);
}
예제 #10
0
void FB2MigrationReader::startElementHandler(int tag, const char **attributes) {
	switch (tag) {
		case _BODY:
			interrupt();
			break;
		case _TITLE_INFO:
			myReadState = READ_SOMETHING;
			break;
		case _GENRE:
			if ((myReadState == READ_SOMETHING) && myUpdateTags) {
				myReadState = READ_GENRE;
			}
			break;
		case _SEQUENCE:
			if ((myReadState == READ_SOMETHING) && myUpdateSeries) {
				const char *name = attributeValue(attributes, "name");
				if (name != 0) {
					std::string seriesTitle = name;
					ZLUnicodeUtil::utf8Trim(seriesTitle);
					myInfo.SeriesTitleOption.setValue(seriesTitle);
					const char *number = attributeValue(attributes, "number");
					myInfo.IndexInSeriesOption.setValue((number != 0) ? std::string(number) : std::string());
				}
			}
			break;
		default:
			break;
	}
}
예제 #11
0
void XHTMLReader::startElementHandler(const char *tag, const char **attributes) {
	static const std::string HASH = "#";
	const char *id = attributeValue(attributes, "id");
	const char *inlineStyle = attributeValue(attributes, "style");
	const char *klass = attributeValue(attributes, "class");
	if (id != 0) {
		myModelReader.addHyperlinkLabel(myReferenceName + HASH + id);
	}

	const std::string sTag = ZLUnicodeUtil::toLower(tag);
	myElementStack.push_back(StyleSheetTable::Element(sTag, klass, id));

	myStyleStack.resize(myStyleStack.size() + 1);
	StyleSheetTable::Style *style = &myStyleStack.back();
	if (myStyleStack.size() > 1) {
		style->inherit(myStyleStack.at(myStyleStack.size()-2));
	}

	myStyleSheetTable.applyStyles(myElementStack, *style);
	if (inlineStyle) {
		style->apply(myStyleParser.parseString(inlineStyle));
	}

	myParseStack.resize(myParseStack.size() + 1);
	ParseContext &prev(myParseStack.at(myParseStack.size()-2));
	ParseContext &context(myParseStack.back());
	if (style->TextStyle.opacitySupported()) {
		int opacity = prev.opacity;
		opacity *= style->TextStyle.opacity();
		opacity /= 255;
		context.opacity = opacity;
	} else {
		context.opacity = prev.opacity;
	}

	// Don't collect empty styles
	if (style->empty()) {
		myStyleStack.resize(myStyleStack.size()-1);
		style = NULL;
	} else {
		context.styleIndex = myStyleStack.size() - 1;
		if (style->PageBreakBefore == B3_TRUE) {
			addPageBreak();
		}
	}

	XHTMLTagAction *action = ourTagActions[sTag];
	if (action != 0) {
		action->doAtStart(*this, attributes);
	}

	if (context.kind >= 0) {
		context.decoration = ZLTextStyleCollection::Instance().decoration(context.kind);
	}

	if (myModelReader.paragraphIsOpen()) {
		applyStyles(myParseStack.back());
	}
}
예제 #12
0
void FB2MetaInfoReader::startElementHandler(int tag, const char **attributes) {
	switch (tag) {
		case _BODY:
			myReturnCode = true;
			interrupt();
			break;
		case _TITLE_INFO:
			myReadState = READ_SOMETHING;
			break;
		case _BOOK_TITLE:
			if (myReadState == READ_SOMETHING) {
				myReadState = READ_TITLE;
			}
			break;
		case _GENRE:
			if (myReadState == READ_SOMETHING) {
				myReadState = READ_GENRE;
			}
			break;
		case _AUTHOR:
			if (myReadState == READ_SOMETHING) {
				myReadState = READ_AUTHOR;
			}
			break;
		case _LANG:
			if (myReadState == READ_SOMETHING) {
				myReadState = READ_LANGUAGE;
			}
			break;
		case _FIRST_NAME:
			if (myReadState == READ_AUTHOR) {
				myReadState = READ_AUTHOR_NAME_0;
			}
			break;
		case _MIDDLE_NAME:
			if (myReadState == READ_AUTHOR) {
				myReadState = READ_AUTHOR_NAME_1;
			}
			break;
		case _LAST_NAME:
			if (myReadState == READ_AUTHOR) {
				myReadState = READ_AUTHOR_NAME_2;
			}
			break;
		case _SEQUENCE:
			if (myReadState == READ_SOMETHING) {
				const char *name = attributeValue(attributes, "name");
				if (name != 0) {
					std::string seriesTitle = name;
					ZLUnicodeUtil::utf8Trim(seriesTitle);
					const char *number = attributeValue(attributes, "number");
					myBook.setSeries(seriesTitle, number != 0 ? std::string(number) : std::string());
				}
			}
			break;
		default:
			break;
	}
}
예제 #13
0
void EpubEncryptionFileReader::startElementHandler(const char *tag, const char **attributes) {
	switch (myState) {
		case READ_SUCCESS:
			break;
		case READ_NONE:
			if (testTag(ZLXMLNamespace::EpubContainer, "encryption", tag)) {
				myState = READ_ENCRYPTION;
			} else {
				interrupt();
			}
			break;
		case READ_ENCRYPTION:
			if (testTag(ZLXMLNamespace::XMLEncryption, "EncryptedData", tag)) {
				myState = READ_ENCRYPTED_DATA;
			} else {
				interrupt();
			}
			break;
		case READ_ENCRYPTED_DATA:
			if (testTag(ZLXMLNamespace::XMLEncryption, "EncryptionMethod", tag)) {
				const char *algorithm = attributeValue(attributes, "Algorithm");
				if (algorithm != 0) {
					myAlgorithm = algorithm;
				} else {
					interrupt();
				}
			} else if (testTag(ZLXMLNamespace::XMLDigitalSignature, "KeyInfo", tag)) {
				myState = READ_KEY_INFO;
			} else if (testTag(ZLXMLNamespace::XMLEncryption, "CipherData", tag)) {
				myState = READ_CIPHER_DATA;
			} else {
				interrupt();
			}
			break;
		case READ_KEY_INFO:
			if (testTag(ZLXMLNamespace::XMLDigitalSignature, "KeyName", tag)) {
				myState = READ_KEY_NAME;
				myKeyName.clear();
			} else {
				interrupt();
			}
			break;
		case READ_KEY_NAME:
			interrupt();
			break;
		case READ_CIPHER_DATA:
			if (testTag(ZLXMLNamespace::XMLEncryption, "CipherReference", tag)) {
				const char *uri = attributeValue(attributes, "URI");
				if (uri != 0) {
					myUri = uri;
				} else {
					interrupt();
				}
			} else {
				interrupt();
			}
			break;
	}
}
예제 #14
0
bool SimulationMaker::readModelElement(QObject* parent)
{
	Q_ASSERT(reader->isStartElement());
	
    QString modelType = attributeValue("type", "anonymous");
    QString objectName = attributeValue("name", "anonymous");
    QString hide = attributeValue("hide", "");
    QString instancesStr = attributeValue("instances", "");

    bool manyInstances = !instancesStr.isEmpty();
    int instances = 1;
    if (manyInstances) {
        bool ok(true);
        instances = instancesStr.toInt(&ok);
        if (!ok || instances <= 0)
            throw Exception("instances must a number larger than zero");
    }

    Model *model;
    try {
        for (int i = 0; i < instances; ++i) {
            QString objectInstanceName = objectName;
            if (manyInstances)
                objectInstanceName += "(" + QString::number(i+1) + ")";

            model = ModelMaker::create(modelType, objectInstanceName, parent);

            if (!hide.isEmpty()) {
                bool isHidden = UniSim::stringToValue<bool>(hide);
                model->setHide(isHidden);
            }
        }
    }
    catch (Exception &ex) {
        throw Exception(message(ex.message()), parent);
    }

	nextElementDelim();
	while (!reader->hasError() && reader->isStartElement()) {
        if (elementNameEquals("model")) {
			readModelElement(model);
        }
        else if (elementNameEquals("dataset")){
            readDatasetElement(model);
        }
        else if (elementNameEquals("parameter")){
            readParameterElement(model);
        }
        else {
            throw Exception(message("Unexpected element: '" + elementName() + "'"), parent);
        }
	}	
	Q_ASSERT(reader->isEndElement());
	nextElementDelim();
	
	return model;
}
예제 #15
0
Simulation* SimulationMaker::parse(QString fileName_)
{
	QString simName, simVersion;

    redirectedParameters.clear();
    outputVariableParam.clear();
    outputParameterParam.clear();
    outputDataParam.clear();

    emit beginExpansion();
    fileName = compileToFile(fileName_);
    emit endExpansion();

    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly)) throw Exception(message("Cannot open file: '"+fileName+"' for reading."));
	reader->setDevice(&file);

    if (!nextElementDelim()) throw Exception(message("File is not in valid XML format"));
    if (elementNameNotEquals("simulation")) throw Exception(message("Root element must be 'simulation'"));

    simName = attributeValue("name", "anonymous");
    simVersion = attributeValue("version", "1.0");
	
	Simulation *sim = new Simulation(simName, simVersion);
    UniSim::setSimulationObject(sim);

	nextElementDelim();
    int iCon=0, iMod=0, iOut=0;
    while (!reader->hasError() && reader->isStartElement()) {
        if (elementNameEquals("integrator") || elementNameEquals("controller")) {
			if (readIntegratorElement(sim)) ++iCon;
        } else if (elementNameEquals("model")) {
			if (readModelElement(sim)) ++iMod;
        } else if (elementNameEquals("output")) {
			if (readOutputElement(sim)) ++iOut;
		} else {
            throw Exception(message("Unexpected element: '" + elementName() + "'"), sim);


		}
	}
	Q_ASSERT(reader->isEndElement());
    if (reader->hasError()) throw Exception(message(""));
    if (iCon==0) throw Exception(message("Missing 'integrator' element in 'simulation'"));
    else if (iCon>1) throw Exception(message("Only one 'integrator' element allowed in 'simulation'"));
    if (iMod==0) throw Exception(message("Missing 'model' element in 'simulation'"));
    if (iOut==0) throw Exception(message("Missing 'output' element in 'simulation'"));

    redirectParameters();

    reader->clear();
    emit beginInitialization();
    sim->initialize(_sequence, this);
    emit endInitialization();

    return sim;
}
void StyleReader::startElementHandler(const char *tag, const char **attributes) {
	static const std::string BASE = "base";
	static const std::string STYLE = "style";

	if (BASE == tag) {
		myCollection.myBaseStyle = new BaseTextStyle(attributeValue(attributes, "family"), intValue(attributes, "fontSize"));
	} else if (STYLE == tag) {
		const char *idString = attributeValue(attributes, "id");
		const char *name = attributeValue(attributes, "name");
		if ((idString != 0) && (name != 0)) {
			TextKind id = (TextKind)atoi(idString);
			TextStyleDecoration *decoration;

			int fontSizeDelta = intValue(attributes, "fontSizeDelta");
			Boolean3 bold = b3Value(attributes, "bold");
			Boolean3 italic = b3Value(attributes, "italic");
			int verticalShift = intValue(attributes, "vShift");
			Boolean3 allowHyphenations = b3Value(attributes, "allowHyphenations");
			bool isHyperlink = booleanValue(attributes, "isHyperlink");

			if (booleanValue(attributes, "partial")) {
				decoration = new TextStyleDecoration(name, fontSizeDelta, bold, italic, verticalShift, allowHyphenations);
			} else {
				int spaceBefore = intValue(attributes, "spaceBefore");
				int spaceAfter = intValue(attributes, "spaceAfter");
				int leftIndent = intValue(attributes, "leftIndent");
				int rightIndent = intValue(attributes, "rightIndent");
				int firstLineIndentDelta = intValue(attributes, "firstLineIndentDelta");

				AlignmentType alignment = ALIGN_UNDEFINED;
				const char *alignmentString = attributeValue(attributes, "alignment");
				if (alignmentString != 0) {
					if (strcmp(alignmentString, "left") == 0) {
						alignment = ALIGN_LEFT;
					} else if (strcmp(alignmentString, "rigth") == 0) {
						alignment = ALIGN_RIGHT;
					} else if (strcmp(alignmentString, "center") == 0) {
						alignment = ALIGN_CENTER;
					} else if (strcmp(alignmentString, "justify") == 0) {
						alignment = ALIGN_JUSTIFY;
					}
				}
				double lineSpace = doubleValue(attributes, "lineSpace");

				decoration = new FullTextStyleDecoration(name, fontSizeDelta, bold, italic, spaceBefore, spaceAfter, leftIndent, rightIndent, firstLineIndentDelta, verticalShift, alignment, lineSpace, allowHyphenations);
			}
			if (isHyperlink) {
				decoration->setHyperlinkStyle();
			}
			myCollection.myDecorationMap.insert(std::pair<TextKind,TextStyleDecoration*>(id, decoration));
		}
	}
}
예제 #17
0
Simulation* SimulationMaker::parse(QString fileName_)
{
    fileName = fileName_;
	QString simName, simVersion;

    XmlExpander expander(fileName, "_expanded");
	emit beginExpansion();
	expander.expand();
	emit endExpansion();	
    fileName = expander.newFileName();
	
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly)) throw Exception(message("Cannot open file: '"+fileName+"' for reading."));
	reader->setDevice(&file);

    if (!nextElementDelim()) throw Exception(message("File is not in valid XML format"));
    if (elementNameNotEquals("simulation")) throw Exception(message("Root element must be 'simulation'"));

    simName = attributeValue("name");
	if (simName.isEmpty()) simName = "anonymous";
    simVersion = attributeValue("version");
	if (simVersion.isEmpty()) simVersion = "1.0";
	
	Simulation *sim = new Simulation(simName, simVersion);
    UniSim::setSimulationObject(sim);

	nextElementDelim();
    int iCon=0, iMod=0, iOut=0;
    while (!reader->hasError() && reader->isStartElement()) {
        if (elementNameEquals("integrator") || elementNameEquals("controller")) {
			if (readIntegratorElement(sim)) ++iCon;
        } else if (elementNameEquals("model")) {
			if (readModelElement(sim)) ++iMod;
        } else if (elementNameEquals("output")) {
			if (readOutputElement(sim)) ++iOut;
		} else {
            throw Exception(message("Unknown element in 'simulation' element: " + elementName()));
		}
	}
	Q_ASSERT(reader->isEndElement());
    if (reader->hasError()) throw Exception(message(""));
    if (iCon==0) throw Exception(message("Missing 'integrator' element in 'simulation'"));
    else if (iCon>1) throw Exception(message("Only one 'integrator' element allowed in 'simulation'"));
    if (iMod==0) throw Exception(message("Missing 'model' element in 'simulation'"));
    if (iOut==0) throw Exception(message("Missing 'output' element in 'simulation'"));

	reader->clear();
    emit beginInitialization();
    sim->initialize(_sequence);
    emit endInitialization();

    return sim;
}
예제 #18
0
void OEBBookReader::startElementHandler(const char *tag, const char **xmlattributes) {
	AppLog("OEBBookReader::startElementHandler");
	std::string tagString = ZLUnicodeUtil::toLower(tag);
	if (!myOPFSchemePrefix.empty() &&
			ZLStringUtil::stringStartsWith(tagString, myOPFSchemePrefix)) {
		tagString = tagString.substr(myOPFSchemePrefix.length());
	}
	if (MANIFEST == tagString) {
		myState = READ_MANIFEST;
	} else if (SPINE == tagString) {
		const char *toc = attributeValue(xmlattributes, "toc");
		if (toc != 0) {
			myNCXTOCFileName = myIdToHref[toc];
		}
		myState = READ_SPINE;
	} else if (GUIDE == tagString) {
		myState = READ_GUIDE;
	} else if (TOUR == tagString) {
		myState = READ_TOUR;
	} else if ((myState == READ_MANIFEST) && (ITEM == tagString)) {
		const char *id = attributeValue(xmlattributes, "id");
		const char *href = attributeValue(xmlattributes, "href");
		if ((id != 0) && (href != 0)) {
			myIdToHref[id] = MiscUtil::decodeHtmlURL(href);
		}
	} else if ((myState == READ_SPINE) && (ITEMREF == tagString)) {
		const char *id = attributeValue(xmlattributes, "idref");
		if (id != 0) {
			const std::string &fileName = myIdToHref[id];
			if (!fileName.empty()) {
				myHtmlFileNames.push_back(fileName);
			}
		}
	} else if ((myState == READ_GUIDE) && (REFERENCE == tagString)) {
		const char *type = attributeValue(xmlattributes, "type");
		const char *title = attributeValue(xmlattributes, "title");
		const char *href = attributeValue(xmlattributes, "href");
		if (href != 0) {
			const std::string reference = MiscUtil::decodeHtmlURL(href);
			if (title != 0) {
				myGuideTOC.push_back(std::make_pair(std::string(title), reference));
			}
			static const std::string COVER_IMAGE = "other.ms-coverimage-standard";
			if ((type != 0) && (COVER_IMAGE == type)) {
				myModelReader.setMainTextModel();
				myModelReader.addImageReference(reference);
				myModelReader.addImage(reference, new ZLFileImage(ZLFile(myFilePrefix + reference), 0));
			}
		}
	} else if ((myState == READ_TOUR) && (SITE == tagString)) {
		const char *title = attributeValue(xmlattributes, "title");
		const char *href = attributeValue(xmlattributes, "href");
		if ((title != 0) && (href != 0)) {
			myTourTOC.push_back(std::make_pair(title, MiscUtil::decodeHtmlURL(href)));
		}
	}
}
예제 #19
0
void XHTMLImageFinder::startElementHandler(const char *tag, const char **attributes) {
	const char *reference = 0;
	if (TAG_IMG == tag) {
		reference = attributeValue(attributes, "src");
	} else if (TAG_IMAGE == tag) {
		reference = attributeValue(
			attributes, FullNamePredicate(ZLXMLNamespace::XLink, "href")
		);
	}
	if (reference != 0) {
		myImage = new ZLFileImage(ZLFile(myPathPrefix + reference), "", 0);
		interrupt();
	}
}
void ZLStatisticsXMLReader::startElementHandler(const char *tag, const char **attributes) {
	if (STATISTICS_TAG == tag) {
		size_t volume = atoi(attributeValue(attributes, "volume"));
		unsigned long long squaresVolume = atoll(attributeValue(attributes, "squaresVolume"));
		//std::cerr << "XMLReader: frequencies sum & ^2: " << volume << ":" << squaresVolume << "\n";
		myStatisticsPtr = new ZLArrayBasedStatistics( atoi(attributeValue(attributes, "charSequenceSize")), atoi(attributeValue(attributes, "size")), volume, squaresVolume);
	} else if (ITEM_TAG == tag) {
		const char *sequence = attributeValue(attributes, "sequence");
		const char *frequency = attributeValue(attributes, "frequency");
		if ((sequence != 0) && (frequency != 0)) {
			std::string hexString(sequence);
			myStatisticsPtr->insert(ZLCharSequence(hexString), atoi(frequency));
		}
	}
}
예제 #21
0
void ZLToolbarCreator::startElementHandler(const char *tag, const char **attributes) {
	static const std::string BUTTON = "button";
	static const std::string MENU_BUTTON = "menuButton";
	static const std::string TOGGLE_BUTTON = "toggleButton";
	static const std::string TEXT_FIELD = "textField";
	static const std::string COMBO_BOX = "comboBox";
	static const std::string SEPARATOR = "separator";
	if (BUTTON == tag) {
		const char *id = attributeValue(attributes, "id");
		if (id != 0) {
			myToolbar.addPlainButton(id);
		}
	} else if (MENU_BUTTON == tag) {
		const char *id = attributeValue(attributes, "id");
		if (id != 0) {
			myToolbar.addMenuButton(id);
		}
	} else if (TOGGLE_BUTTON == tag) {
		const char *id = attributeValue(attributes, "id");
		const char *groupId = attributeValue(attributes, "group");
		const char *isDefault = attributeValue(attributes, "default");
		if ((id != 0) && (groupId != 0)) {
			myToolbar.addToggleButton(id, groupId, isDefault != 0);
			/*
			if (isDefault != 0) {
				button.press();
			}
			*/
		}
	} else if ((TEXT_FIELD == tag) || (COMBO_BOX == tag)) {
		const char *id = attributeValue(attributes, "id");
		const char *parameterId = attributeValue(attributes, "parameterId");
		const char *maxWidth = attributeValue(attributes, "maxWidth");
		const char *symbolSet = attributeValue(attributes, "symbols");
		if ((id != 0) && (parameterId != 0) && (maxWidth != 0)) {
			int nMaxWidth = atoi(maxWidth);
			ZLToolbar::ParameterItem::SymbolSet sSet =
				((symbolSet != 0) && (std::string(symbolSet) == "digits")) ?
					ZLToolbar::ParameterItem::SET_DIGITS :
					ZLToolbar::ParameterItem::SET_ANY;
			if (nMaxWidth > 0) {
				myToolbar.addParameterItem(
					(TEXT_FIELD == tag) ?
						ZLToolbar::Item::TEXT_FIELD :
						ZLToolbar::Item::COMBO_BOX,
					id, parameterId, nMaxWidth, sSet
				);
			}
		}
	} else if (SEPARATOR == tag) {
		myToolbar.addSeparator();
	}
}
예제 #22
0
std::shared_ptr<LogicalParameter> LogicalParameter::fromXML(BaseLib::Obj* baseLib, xml_node<>* node)
{
	std::shared_ptr<LogicalParameter> parameter;
	try
	{
		xml_attribute<>* attr = node->first_attribute("type");
		if(attr != nullptr)
		{
			std::string attributeValue(attr->value());
			if(attributeValue == "option") parameter.reset(new LogicalParameterEnum(baseLib, node));
			else if(attributeValue == "integer") parameter.reset(new LogicalParameterInteger(baseLib, node));
			else if(attributeValue == "float") parameter.reset(new LogicalParameterFloat(baseLib, node));
			else if(attributeValue == "boolean") parameter.reset(new LogicalParameterBoolean(baseLib, node));
			else if(attributeValue == "string") parameter.reset(new LogicalParameterString(baseLib, node));
			else if(attributeValue == "action") parameter.reset(new LogicalParameterAction(baseLib, node));
			else  parameter.reset(new LogicalParameterInteger(baseLib, node));
		}
		else parameter.reset(new LogicalParameterInteger(baseLib, node));
	}
    catch(const std::exception& ex)
    {
    	baseLib->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(const Exception& ex)
    {
    	baseLib->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(...)
    {
    	baseLib->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
    return parameter;
}
예제 #23
0
LogicalParameterAction::LogicalParameterAction(BaseLib::Obj* baseLib, xml_node<>* node) : LogicalParameterAction(baseLib)
{
	try
	{
		type = Type::Enum::typeAction;
		for(xml_attribute<>* attr = node->first_attribute(); attr; attr = attr->next_attribute())
		{
			std::string attributeName(attr->name());
			std::string attributeValue(attr->value());
			if(attributeName == "unit") unit = attributeValue;
			else if(attributeName != "type") _bl->out.printWarning("Warning: Unknown attribute for \"logical\" with type boolean: " + attributeName);
		}
	}
    catch(const std::exception& ex)
    {
    	_bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(const Exception& ex)
    {
    	_bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(...)
    {
    	_bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
}
예제 #24
0
LogicalParameterString::LogicalParameterString(BaseLib::Obj* baseLib, xml_node<>* node) : LogicalParameterString(baseLib)
{
	try
	{
		type = Type::Enum::typeString;
		for(xml_attribute<>* attr = node->first_attribute(); attr; attr = attr->next_attribute())
		{
			std::string attributeName(attr->name());
			std::string attributeValue(attr->value());
			if(attributeName == "default")
			{
				defaultValue = attributeValue;
				defaultValueExists = true;
			}
			else if(attributeName == "unit") unit = attributeValue;
			else if(attributeName == "use_default_on_failure") {} //ignore, not necessary - all values are initialized
			else if(attributeName != "type") _bl->out.printWarning("Warning: Unknown attribute for \"logical\" with type string: " + attributeName);
		}
	}
    catch(const std::exception& ex)
    {
    	_bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(const Exception& ex)
    {
    	_bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(...)
    {
    	_bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
}
예제 #25
0
std::string LitResDataParser::stringAttributeValue(const char **attributes, const char *name) {
	if (attributes == 0) {
		return std::string();
	}
	const char *value = attributeValue(attributes, name);
	return value != 0 ? value : std::string();
}
LogicalParameterBoolean::LogicalParameterBoolean(BaseLib::Obj* baseLib, xml_node<>* node) : LogicalParameterBoolean(baseLib)
{
	try
	{
		type = Type::Enum::typeBoolean;
		for(xml_attribute<>* attr = node->first_attribute(); attr; attr = attr->next_attribute())
		{
			std::string attributeName(attr->name());
			std::string attributeValue(attr->value());
			if(attributeName == "default")
			{
				if(attributeValue == "true") defaultValue = true;
				defaultValueExists = true;
			}
			else if(attributeName == "unit") unit = attributeValue;
			else if(attributeName != "type") _bl->out.printWarning("Warning: Unknown attribute for \"logical\" with type boolean: " + attributeName);
		}
		for(xml_node<>* logicalNode = node->first_node(); logicalNode; logicalNode = logicalNode->next_sibling())
		{
			_bl->out.printWarning("Warning: Unknown node in \"logical\" with type boolean: " + std::string(logicalNode->name()));
		}
	}
    catch(const std::exception& ex)
    {
    	_bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(const Exception& ex)
    {
    	_bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(...)
    {
    	_bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
}
void OEBDescriptionReader::startElementHandler(const char *tag, const char **attributes) {
	const std::string tagString = ZLUnicodeUtil::toLower(tag);
	if ((METADATA == tagString) || (DC_METADATA == tagString)) {
		myDCMetadataTag = tagString;
		myReadMetaData = true;
	} else if (myReadMetaData) {
		if (ZLStringUtil::stringEndsWith(tagString, TITLE_TAG)) {
			if (isDublinCoreNamespace(tagString.substr(0, tagString.length() - TITLE_TAG.length()))) {
				myReadState = READ_TITLE;
			}
		} else if (ZLStringUtil::stringEndsWith(tagString, AUTHOR_TAG)) {
			if (isDublinCoreNamespace(tagString.substr(0, tagString.length() - AUTHOR_TAG.length()))) {
				const char *role = attributeValue(attributes, "role");
				if (role == 0) {
					myReadState = READ_AUTHOR2;
				} else if (AUTHOR_ROLE == role) {
					myReadState = READ_AUTHOR;
				}
			}
		} else if (ZLStringUtil::stringEndsWith(tagString, SUBJECT_TAG)) {
			if (isDublinCoreNamespace(tagString.substr(0, tagString.length() - SUBJECT_TAG.length()))) {
				myReadState = READ_SUBJECT;
			}
		}
	}
}
예제 #28
0
void FBReaderOrgDataParser::startElementHandler(const char *tag, const char **attributes) {
	if (BOOK_TAG == tag) {
		const char *id = attributeValue(attributes, "id");
		if (id != 0) {
			myCurrentBook = new NetworkBookInfo(id);
		}
	} else if ((myCurrentBook != 0) && (URL_TAG == tag)) {
		const char *type = attributeValue(attributes, "type");
		if (type != 0) {
			myURLType = type;
		} else {
			myURLType.erase();
		}
	}
	myBuffer.clear();
}
예제 #29
0
/*!
  Returns the value of the user key of this tuple.

*/
const QString QmvTuple::userkeyValue()
{
    if (parentClass()->userKey())
        return(attributeValue(parentClass()->userKey()));
    else
        return 0;
}
예제 #30
0
/*!
  Returns the value of the primary key of this tuple.

*/
const QString QmvTuple::primarykeyValue()
{
    if (parentClass()->primaryKey())
        return(attributeValue(parentClass()->primaryKey()));
    else
        return 0;
}