bool XmlConfigurationConverter::updateDocument(XmlDocument* document, std::string dtd,
		const Version& version, std::string rootElementName) {

	// update root element name
	XmlElement* root = document->getRootElement();
	if (!root) {
		return false;
	} // if
	root->setName(rootElementName);

	// update version entry in root element
	if (root->hasAttribute("version")) {
		root->getAttribute("version")->setValue(version.toString());
	} // if
	else {
		XmlAttribute* versionAttribute = new XmlAttribute("version", version.toString());
		root->addAttribute(versionAttribute);
	} // else

	// update dtd reference
	XmlDtdReference* dtdRef = document->getDtd();
	if (!dtdRef) {
		dtdRef = new XmlDtdReference(rootElementName, dtd);
		document->setDtd(dtdRef);
	} else {
		dtdRef->setName(rootElementName);
		dtdRef->setDtd(dtd);
	} // else

	return true;
} // updateRootElement
示例#2
0
void XmlParser::readConfig()
{
	XmlDocument* xmlConfigDoc = new XmlDocument(File(File::getCurrentWorkingDirectory().getChildFile(configFile)));
	XmlElement* xmlConfigElem = xmlConfigDoc->getDocumentElement();
	if (xmlConfigElem != NULL) 
	{
		XmlElement* pictures = xmlConfigElem->getChildByName(T("pictures"));
		if (pictures != NULL) 
		{
			if (pictures->hasAttribute(T("path"))) 
			{
				m_picturePath = pictures->getStringAttribute(T("path"));
			}
			else 
			{
				LOG_ERROR(T("Element \"pictures\" is incomplete"));
			}

		}
		else 
		{
			LOG_ERROR(T("Element \"pictures\" not found"));
		}
		delete xmlConfigElem;

	}
	else
	{
		LOG_ERROR((T("XML load failed: %ls"), (const juce_wchar*)xmlConfigDoc->getLastParseError()));
	}
	delete xmlConfigDoc;
}
示例#3
0
void CommandTableModel::buildFromXml(XmlElement *root)
{
	if (root->getTagName().compare("settings") != 0)
		return;

	removeAllRows();

	XmlElement* setting = root->getFirstChildElement();
	while ((setting) && (m_commandMap))
	{
		if (setting->hasAttribute("controller"))
		{
			MIDI_Message cc(setting->getIntAttribute("channel"), setting->getIntAttribute("controller"), true);
			addRow(cc.channel, cc.controller, true);

			// older versions of MIDI2LR stored the index of the string, so we should attempt to parse this as well
			if (setting->getIntAttribute("command", -1) != -1)
			{
				m_commandMap->addCommandforMessage(setting->getIntAttribute("command"), cc);
			}
			else
			{
				m_commandMap->addCommandforMessage(setting->getStringAttribute("command_string"), cc);
			}
		}
		else if (setting->hasAttribute("note"))
		{
			MIDI_Message note(setting->getIntAttribute("channel"), setting->getIntAttribute("note"), false);
			addRow(note.channel, note.pitch, false);

			// older versions of MIDI2LR stored the index of the string, so we should attempt to parse this as well
			if (setting->getIntAttribute("command", -1) != -1)
			{
				m_commandMap->addCommandforMessage(setting->getIntAttribute("command"), note);
			}
			else
			{
				m_commandMap->addCommandforMessage(setting->getStringAttribute("command_string"), note);
			}
		}
		setting = setting->getNextElement();
	}
}
示例#4
0
void TreeView::restoreOpennessState (const XmlElement& newState)
{
    if (rootItem != 0)
    {
        rootItem->restoreOpennessState (newState);

        if (newState.hasAttribute ("scrollPos"))
            viewport->setViewPosition (viewport->getViewPositionX(),
                                       newState.getIntAttribute ("scrollPos"));
    }
}
示例#5
0
    static KeyFileData getDataFromKeyFile (XmlElement xml)
    {
        KeyFileData data;

        data.licensee = getLicensee (xml);
        data.email = getEmail (xml);
        data.appID = getAppID (xml);

        if (xml.hasAttribute ("expiryTime") && xml.hasAttribute ("expiring_mach"))
        {
            data.keyFileExpires = true;
            data.machineNumbers.addArray (getMachineNumbers (xml, "expiring_mach"));
            data.expiryTime = Time (xml.getStringAttribute ("expiryTime").getHexValue64());
        }
        else
        {
            data.keyFileExpires = false;
            data.machineNumbers.addArray (getMachineNumbers (xml, "mach"));
        }

        return data;
    }
String AudioDeviceManager::initialiseFromXML (const XmlElement& xml,
                                              const bool selectDefaultDeviceOnFailure,
                                              const String& preferredDefaultDeviceName,
                                              const AudioDeviceSetup* preferredSetupOptions)
{
    lastExplicitSettings = new XmlElement (xml);

    String error;
    AudioDeviceSetup setup;

    if (preferredSetupOptions != nullptr)
        setup = *preferredSetupOptions;

    if (xml.getStringAttribute ("audioDeviceName").isNotEmpty())
    {
        setup.inputDeviceName = setup.outputDeviceName
            = xml.getStringAttribute ("audioDeviceName");
    }
    else
    {
        setup.inputDeviceName  = xml.getStringAttribute ("audioInputDeviceName");
        setup.outputDeviceName = xml.getStringAttribute ("audioOutputDeviceName");
    }

    currentDeviceType = xml.getStringAttribute ("deviceType");

    if (findType (currentDeviceType) == nullptr)
    {
        if (AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName))
            currentDeviceType = type->getTypeName();
        else if (availableDeviceTypes.size() > 0)
            currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
    }

    setup.bufferSize = xml.getIntAttribute ("audioDeviceBufferSize", setup.bufferSize);
    setup.sampleRate = xml.getDoubleAttribute ("audioDeviceRate", setup.sampleRate);

    setup.inputChannels .parseString (xml.getStringAttribute ("audioDeviceInChans",  "11"), 2);
    setup.outputChannels.parseString (xml.getStringAttribute ("audioDeviceOutChans", "11"), 2);

    setup.useDefaultInputChannels  = ! xml.hasAttribute ("audioDeviceInChans");
    setup.useDefaultOutputChannels = ! xml.hasAttribute ("audioDeviceOutChans");

    error = setAudioDeviceSetup (setup, true);

    midiInsFromXml.clear();

    forEachXmlChildElementWithTagName (xml, c, "MIDIINPUT")
        midiInsFromXml.add (c->getStringAttribute ("name"));

    const StringArray allMidiIns (MidiInput::getDevices());

    for (int i = allMidiIns.size(); --i >= 0;)
        setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));

    if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
        error = initialise (numInputChansNeeded, numOutputChansNeeded,
                            nullptr, false, preferredDefaultDeviceName);

    setDefaultMidiOutput (xml.getStringAttribute ("defaultMidiOutput"));

    return error;
}