Exemplo n.º 1
0
bool
OptionsCont::isUsableFileList(const std::string& name) const {
    Option* o = getSecure(name);
    // check whether the option is set
    //  return false i not
    if (!o->isSet()) {
        return false;
    }
    // check whether the list of files is valid
    bool ok = true;
    std::vector<std::string> files = getStringVector(name);
    if (files.size() == 0) {
        WRITE_ERROR("The file list for '" + name + "' is empty.");
        ok = false;
    }
    for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) {
        if (!FileHelpers::isReadable(*fileIt)) {
            if (*fileIt != "") {
                WRITE_ERROR("File '" + *fileIt + "' is not accessible (" + std::strerror(errno) + ").");
                ok = false;
            } else {
                WRITE_WARNING("Empty file name given; ignoring.");
            }
        }
    }
    return ok;
}
Exemplo n.º 2
0
void IdeMailBox::onPreRender()
{
	ControlBase::onPreRender();

	getStylesheet()->setBoolParam(PARAM_SECURE, getSecure());

	if(m_message.empty())
	{
		shared_ptr<XMLNode> folder_node = getDocument()->create(_S("folder"));
		switch(m_folder)
		{
		case messageFolderInbox:		renderFolder(messageFolderInbox, folder_node);
										break;

		case messageFolderTrash:		renderFolder(messageFolderTrash, folder_node);
										break;

		case messageFolderSentItems:	renderFolder(messageFolderSentItems, folder_node);
										break;

		default:						OS_ASSERTFALSE();
										break;
		}
	}
	else
	{
		renderMessage(m_message, getDocument()->create(_S("message")));
	}
}
Exemplo n.º 3
0
bool
OptionsCont::isUsableFileList(const std::string &name) const throw(InvalidArgument) {
    Option *o = getSecure(name);
    // check whether the option is set
    //  return false i not
    if (!o->isSet()) {
        return false;
    }
    // check whether the list of files is valid
    bool ok = true;
    std::vector<std::string> files = getStringVector(name);
    if (files.size()==0) {
        MsgHandler::getErrorInstance()->inform("The file list for '" + name + "' is empty.");
        ok = false;
    }
    for (std::vector<std::string>::const_iterator fileIt=files.begin(); fileIt!=files.end(); ++fileIt) {
        if (!FileHelpers::exists(*fileIt)) {
            if (*fileIt!="") {
                MsgHandler::getErrorInstance()->inform("File '" + *fileIt + "' does not exist.");
                ok = false;
            } else {
                MsgHandler::getWarningInstance()->inform("Empty file name given; ignoring.");
            }
        }
    }
    return ok;
}
Exemplo n.º 4
0
bool
OptionsCont::setDefault(const std::string& name, const std::string& value) {
    if (set(name, value)) {
        getSecure(name)->resetDefault();
        return true;
    }
    return false;
}
Exemplo n.º 5
0
void
OptionsCont::addDescription(const std::string& name,
                            const std::string& subtopic,
                            const std::string& description) {
    Option* o = getSecure(name);
    assert(o != 0);
    assert(find(mySubTopics.begin(), mySubTopics.end(), subtopic) != mySubTopics.end());
    o->setDescription(description);
    mySubTopicEntries[subtopic].push_back(name);
}
Exemplo n.º 6
0
std::vector<std::string>
OptionsCont::getSynonymes(const std::string &name) const throw(InvalidArgument) {
    Option *o = getSecure(name);
    std::vector<std::string> v(0);
    for (KnownContType::const_iterator i=myValues.begin(); i!=myValues.end(); i++) {
        if ((*i).second==o&&name!=(*i).first) {
            v.push_back((*i).first);
        }
    }
    return v;
}
Exemplo n.º 7
0
void
OptionsCont::addDescription(const std::string &name,
                            const std::string &subtopic,
                            const std::string &description) throw(InvalidArgument) {
    Option *o = getSecure(name);
    assert(o!=0);
    assert(o->myDescription=="");
    assert(find(mySubTopics.begin(), mySubTopics.end(), subtopic)!=mySubTopics.end());
    o->myDescription = description;
    mySubTopicEntries[subtopic].push_back(name);
}
Exemplo n.º 8
0
void
OptionsCont::writeConfiguration(std::ostream &os, bool filled,
                                bool complete, bool addComments) throw() {
    std::vector<std::string>::const_iterator i, j;
    os << "<configuration>" << std::endl << std::endl;
    for (i=mySubTopics.begin(); i!=mySubTopics.end(); ++i) {
        std::string subtopic = *i;
        if (subtopic=="Configuration") {
            continue;
        }
        for (size_t k=0; k<subtopic.length(); ++k) {
            if (subtopic[k]==' ') {
                subtopic[k] = '_';
            }
            if (subtopic[k]>='A'&&subtopic[k]<='Z') {
                subtopic[k] = subtopic[k] - 'A' + 'a';
            }
        }
        const std::vector<std::string> &entries = mySubTopicEntries[*i];
        bool hadOne = false;
        for (j=entries.begin(); j!=entries.end(); ++j) {
            Option *o = getSecure(*j);
            bool write = complete || (filled&&!o->isDefault());
            if (!write) {
                continue;
            }
            if (!hadOne) {
                os << "    <" << subtopic << ">" << std::endl;
            }
            // add the comment if wished
            if (addComments) {
                os << "        <!-- " << o->getDescription() << " -->" << std::endl;
            }
            // write the option and the value (if given)
            os << "        <" << *j << " value=\"";
            if (o->isSet()) {
                os << o->getValueString();
            }
            os << "\"/>" << std::endl;
            // append an endline if a comment was printed
            if (addComments) {
                os << std::endl;
            }
            hadOne = true;
        }
        if (hadOne) {
            os << "    </" << subtopic << ">" << std::endl << std::endl;
        }
    }
    os << "</configuration>" << std::endl;
}
Exemplo n.º 9
0
bool
OptionsCont::checkDependingSuboptions(const std::string &name, const std::string &prefix) const throw(InvalidArgument) {
    Option *o = getSecure(name);
    if (o->isSet()) {
        return true;
    }
    bool ok = true;
    for (KnownContType::const_iterator i=myValues.begin(); i!=myValues.end(); i++) {
        if ((*i).second->isSet() && !(*i).second->isDefault() && (*i).first.find(prefix) == 0) {
            MsgHandler::getErrorInstance()->inform("Option '" + (*i).first + "' needs option '" + name + "'.");
            ok = false;
        }
    }
    return ok;
}
Exemplo n.º 10
0
std::vector<std::string>
OptionsCont::getStringVector(const std::string &name) const throw(InvalidArgument) {
    Option *o = getSecure(name);
    std::string def = o->getString();
    if (def.find(';')!=std::string::npos&&!myHaveInformedAboutDeprecatedDivider) {
        MsgHandler::getWarningInstance()->inform("Please note that using ';' as list separator is deprecated.\n From 1.0 onwards, only ',' will be accepted.");
        myHaveInformedAboutDeprecatedDivider = true;
    }
    StringTokenizer st(def, ";,", true);
    std::vector<std::string> ret = st.getVector();
    for (std::vector<std::string>::iterator i=ret.begin(); i!=ret.end(); ++i) {
        (*i) = StringUtils::prune(*i);
    }
    return ret;
}
Exemplo n.º 11
0
bool
OptionsCont::set(const std::string &name, const std::string &value) throw(InvalidArgument) {
    Option *o = getSecure(name);
    if (!o->isWriteable()) {
        reportDoubleSetting(name);
        return false;
    }
    try {
        if (!o->set(value)) {
            return false;
        }
    } catch (InvalidArgument &e) {
        MsgHandler::getErrorInstance()->inform("While processing option '" + name + "':\n " + e.what());
        return false;
    }
    return true;
}
Exemplo n.º 12
0
bool
OptionsCont::set(const std::string& name, const std::string& value) {
    Option* o = getSecure(name);
    if (!o->isWriteable()) {
        reportDoubleSetting(name);
        return false;
    }
    try {
        if (!o->set(value)) {
            return false;
        }
    } catch (ProcessError& e) {
        WRITE_ERROR("While processing option '" + name + "':\n " + e.what());
        return false;
    }
    return true;
}
Exemplo n.º 13
0
void
OptionsCont::writeSchema(std::ostream& os, bool /* addComments */) {
    os << "<?xml version=\"1.0\"" << SUMOSAXAttributes::ENCODING << "?>\n\n";
    os << "<xsd:schema elementFormDefault=\"qualified\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n\n";
    os << "    <xsd:include schemaLocation=\"baseTypes.xsd\"/>\n";
    os << "    <xsd:element name=\"configuration\" type=\"configurationType\"/>\n\n";
    os << "    <xsd:complexType name=\"configurationType\">\n";
    os << "        <xsd:all>\n";
    for (std::vector<std::string>::const_iterator i = mySubTopics.begin(); i != mySubTopics.end(); ++i) {
        std::string subtopic = *i;
        if (subtopic == "Configuration") {
            continue;
        }
        std::replace(subtopic.begin(), subtopic.end(), ' ', '_');
        std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
        os << "            <xsd:element name=\"" << subtopic << "\" type=\"" << subtopic << "Type\" minOccurs=\"0\"/>\n";
    }
    os << "        </xsd:all>\n";
    os << "    </xsd:complexType>\n\n";
    for (std::vector<std::string>::const_iterator i = mySubTopics.begin(); i != mySubTopics.end(); ++i) {
        std::string subtopic = *i;
        if (subtopic == "Configuration") {
            continue;
        }
        std::replace(subtopic.begin(), subtopic.end(), ' ', '_');
        std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
        os << "    <xsd:complexType name=\"" << subtopic << "Type\">\n";
        os << "        <xsd:all>\n";
        const std::vector<std::string>& entries = mySubTopicEntries[*i];
        for (std::vector<std::string>::const_iterator j = entries.begin(); j != entries.end(); ++j) {
            Option* o = getSecure(*j);
            std::string type = o->getTypeName();
            std::transform(type.begin(), type.end(), type.begin(), tolower);
            if (type == "int[]") {
                type = "intArray";
            }
            os << "            <xsd:element name=\"" << *j << "\" type=\"" << type << "OptionType\" minOccurs=\"0\"/>\n";
        }
        os << "        </xsd:all>\n";
        os << "    </xsd:complexType>\n\n";
    }
    os << "</xsd:schema>\n";
}
Exemplo n.º 14
0
bool
OptionsCont::set(const std::string &name, bool value) throw(InvalidArgument) {
    Option *o = getSecure(name);
    if (!o->isBool()) {
        throw InvalidArgument("The option '" + name + "' is not a boolean attribute and requires an argument.");
    }
    if (!o->isWriteable()) {
        reportDoubleSetting(name);
        return false;
    }
    try {
        if (!o->set(value)) {
            return false;
        }
    } catch (InvalidArgument &e) {
        MsgHandler::getErrorInstance()->inform("While processing option '" + name + "':\n " + e.what());
        return false;
    }
    return true;
}
Exemplo n.º 15
0
bool
OptionsCont::checkDependingSuboptions(const std::string& name, const std::string& prefix) const {
    Option* o = getSecure(name);
    if (o->isSet()) {
        return true;
    }
    bool ok = true;
    std::vector<std::string> seenSynonymes;
    for (KnownContType::const_iterator i = myValues.begin(); i != myValues.end(); i++) {
        if (std::find(seenSynonymes.begin(), seenSynonymes.end(), (*i).first) != seenSynonymes.end()) {
            continue;
        }
        if ((*i).second->isSet() && !(*i).second->isDefault() && (*i).first.find(prefix) == 0) {
            WRITE_ERROR("Option '" + (*i).first + "' needs option '" + name + "'.");
            std::vector<std::string> synonymes = getSynonymes((*i).first);
            std::copy(synonymes.begin(), synonymes.end(), std::back_inserter(seenSynonymes));
            ok = false;
        }
    }
    return ok;
}
Exemplo n.º 16
0
void
OptionsCont::printHelp(std::ostream &os) throw() {
    std::vector<std::string>::const_iterator i, j;
    // print application description
    os << ' ' << std::endl;
    splitLines(os, myAppDescription , 0, 0);
    os << std::endl;
    // print usage BNF
    os << "Usage: " << myAppName << " [OPTION]*" << std::endl;
    os << ' ' << std::endl;
    // print usage examples
    if (myCallExamples.size()>1) {
        os << " Examples:" << std::endl;
    } else if (myCallExamples.size()!=0) {
        os << " Example:" << std::endl;
    }
    if (myCallExamples.size()!=0) {
        for (i=myCallExamples.begin(); i!=myCallExamples.end(); ++i) {
            os << "  " << myAppName << ' ' << (*i) << std::endl;
        }
    }
    os << ' ' << std::endl;
    // print additional text if any
    if (myAdditionalMessage.length()>0) {
        os << myAdditionalMessage << std::endl << ' ' << std::endl;
    }
    // print the options
    // check their sizes first
    //  we want to know how large the largest not-too-large-entry will be
    size_t tooLarge = 40;
    size_t maxSize = 0;
    for (i=mySubTopics.begin(); i!=mySubTopics.end(); ++i) {
        const std::vector<std::string> &entries = mySubTopicEntries[*i];
        for (j=entries.begin(); j!=entries.end(); ++j) {
            Option *o = getSecure(*j);
            // name, two leading spaces and "--"
            size_t csize = (*j).length() + 2 + 4;
            // abbreviation length ("-X, "->4chars) if any
            std::vector<std::string> synonymes = getSynonymes(*j);
            if (find_if(synonymes.begin(), synonymes.end(), abbreviation_finder())!=synonymes.end()) {
                csize += 4;
            }
            // the type name
            if (!o->isBool()) {
                csize += 1 + o->getTypeName().length();
            }
            // divider
            csize += 2;
            if (csize<tooLarge&&maxSize<csize) {
                maxSize = csize;
            }
        }
    }

    for (i=mySubTopics.begin(); i!=mySubTopics.end(); ++i) {
        os << ' ' << *i << " Options:" << std::endl;
        const std::vector<std::string> &entries = mySubTopicEntries[*i];
        for (j=entries.begin(); j!=entries.end(); ++j) {
            // start length computation
            size_t csize = (*j).length() + 2;
            Option *o = getSecure(*j);
            os << "  ";
            // write abbreviation if given
            std::vector<std::string> synonymes = getSynonymes(*j);
            std::vector<std::string>::iterator a = find_if(synonymes.begin(), synonymes.end(), abbreviation_finder());
            if (a!=synonymes.end()) {
                os << '-' << (*a) << ", ";
                csize += 4;
            }
            // write leading '-'/"--"
            os << "--";
            csize += 2;
            // write the name
            os << *j;
            // write the type if not a bool option
            if (!o->isBool()) {
                os << ' ' << o->getTypeName();
                csize += 1 + o->getTypeName().length();
            }
            csize += 2;
            // write the description formatting it
            os << "  ";
            size_t r;
            for (r=maxSize; r>csize; --r) {
                os << ' ';
            }
            std::string desc = o->getDescription();
            size_t offset = csize > tooLarge ? csize : maxSize;
            splitLines(os, desc, offset, maxSize);
        }
        os << std::endl;
    }
}
Exemplo n.º 17
0
SUMOReal
OptionsCont::getFloat(const std::string& name) const {
    Option* o = getSecure(name);
    return o->getFloat();
}
Exemplo n.º 18
0
bool
OptionsCont::isWriteable(const std::string &name) throw(InvalidArgument) {
    Option *o = getSecure(name);
    return o->isWriteable();
}
Exemplo n.º 19
0
bool
OptionsCont::isBool(const std::string &name) const throw(InvalidArgument) {
    Option *o = getSecure(name);
    return o->isBool();
}
Exemplo n.º 20
0
int
OptionsCont::getInt(const std::string& name) const {
    Option* o = getSecure(name);
    return o->getInt();
}
Exemplo n.º 21
0
const IntVector&
OptionsCont::getIntVector(const std::string& name) const {
    Option* o = getSecure(name);
    return o->getIntVector();
}
Exemplo n.º 22
0
bool
OptionsCont::isBool(const std::string& name) const {
    Option* o = getSecure(name);
    return o->isBool();
}
Exemplo n.º 23
0
const IntVector &
OptionsCont::getIntVector(const std::string &name) const throw(InvalidArgument) {
    Option *o = getSecure(name);
    return o->getIntVector();
}
Exemplo n.º 24
0
SUMOReal
OptionsCont::getFloat(const std::string &name) const throw(InvalidArgument) {
    Option *o = getSecure(name);
    return o->getFloat();
}
Exemplo n.º 25
0
bool
OptionsCont::isWriteable(const std::string& name) {
    Option* o = getSecure(name);
    return o->isWriteable();
}
Exemplo n.º 26
0
void
OptionsCont::writeConfiguration(std::ostream& os, bool filled,
                                bool complete, bool addComments) const {
    os << "<?xml version=\"1.0\"" << SUMOSAXAttributes::ENCODING << "?>\n\n";
    os << "<configuration xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/" << myAppName << "Configuration.xsd\">" << std::endl << std::endl;
    for (std::vector<std::string>::const_iterator i = mySubTopics.begin(); i != mySubTopics.end(); ++i) {
        std::string subtopic = *i;
        if (subtopic == "Configuration" && !complete) {
            continue;
        }
        std::replace(subtopic.begin(), subtopic.end(), ' ', '_');
        std::transform(subtopic.begin(), subtopic.end(), subtopic.begin(), tolower);
        const std::vector<std::string>& entries = mySubTopicEntries.find(*i)->second;
        bool hadOne = false;
        for (std::vector<std::string>::const_iterator j = entries.begin(); j != entries.end(); ++j) {
            Option* o = getSecure(*j);
            bool write = complete || (filled && !o->isDefault());
            if (!write) {
                continue;
            }
            if (!hadOne) {
                os << "    <" << subtopic << ">" << std::endl;
            }
            // add the comment if wished
            if (addComments) {
                os << "        <!-- " << StringUtils::escapeXML(o->getDescription()) << " -->" << std::endl;
            }
            // write the option and the value (if given)
            os << "        <" << *j << " value=\"";
            if (o->isSet() && (filled || o->isDefault())) {
                os << o->getValueString();
            }
            if (complete) {
                std::vector<std::string> synonymes = getSynonymes(*j);
                if (!synonymes.empty()) {
                    os << "\" synonymes=\"";
                    for (std::vector<std::string>::const_iterator s = synonymes.begin(); s != synonymes.end(); ++s) {
                        if (s != synonymes.begin()) {
                            os << " ";
                        }
                        os << (*s);
                    }
                }
                os << "\" type=\"" << o->getTypeName();
                if (!addComments) {
                    os << "\" help=\"" << StringUtils::escapeXML(o->getDescription());
                }
            }
            os << "\"/>" << std::endl;
            // append an endline if a comment was printed
            if (addComments) {
                os << std::endl;
            }
            hadOne = true;
        }
        if (hadOne) {
            os << "    </" << subtopic << ">" << std::endl << std::endl;
        }
    }
    os << "</configuration>" << std::endl;
}
Exemplo n.º 27
0
std::string
OptionsCont::getString(const std::string &name) const throw(InvalidArgument) {
    Option *o = getSecure(name);
    return o->getString();
}
Exemplo n.º 28
0
void IdeMailBox::renderMessage(const ObjectID &id, shared_ptr<XMLNode> node)
{
	shared_ptr<ObjectsMessage> message;

	shared_ptr<DataLocalMessage> local_message = getPortal()->getMessenger()->getMessage(getPage()->getDatabase(), getSessionAccount(), id, true);
	if(local_message != nullptr)
	{
		// Decodifica il messaggio
		message = local_message->decode(getSessionAccount()->getPrivateKey());
	}

	if(message == nullptr)
		return;

	shared_ptr<OMLContext> messageContext = getPage()->parseOmlEx(message->body, false, true, getSecure(), false, omlRenderModeOsiris, String::EMPTY, String::EMPTY);
	if(messageContext == nullptr)
		return;

	shared_ptr<XMLPortalExporter> messageExporter(OS_NEW XMLPortalExporter(node, getPage(), XMLPortalExporter::emFull));
	local_message->exportXML(messageExporter, message->subject, messageContext->getOutput(), messageContext->getSecureCheck());

	shared_ptr<XMLNode> node_actions = node->addChild(_S("actions"));

	shared_ptr<ObjectsUser> author = objects_user_cast(getPage()->getObject(local_message->author));
	if(author != nullptr)
	{
		shared_ptr<XMLNode> action_reply = node_actions->addChild(_S("action"));
		action_reply->setAttributeString(_S("name"), _S("reply"));

		ordered_map<std::wstring, std::wstring> params;
		params.set(OS_URL_PARAM_QUOTE, (_W("re: ") + message->subject).to_wide());
		action_reply->setAttributeString(_S("href"), getPortal()->getSendMessageLink(author->id, params));
	}

	if(local_message->folder == static_cast<uint32>(messageFolderTrash))
	{
		shared_ptr<XMLNode> action_delete = node_actions->addChild(_S("action"));
		action_delete->setAttributeString(_S("name"), _S("restore"));
		action_delete->setAttributeString(_S("href"), getEventCommand(EVENT_ONRESTOREMESSAGE, id.toUTF16()));
	}
	else
	{
		shared_ptr<XMLNode> action_delete = node_actions->addChild(_S("action"));
		action_delete->setAttributeString(_S("name"), _S("delete"));
		action_delete->setAttributeString(_S("href"), getEventCommand(EVENT_ONDELETEMESSAGE, id.toUTF16()));
	}

	if(getSecure())
	{
		bool unsafe = messageContext->getSecureCheck() == false;
		if(unsafe == false)
		{
			shared_ptr<ObjectsUser> messageAuthor = objects_user_cast(getPage()->getObject(local_message->author));
			if(messageAuthor != nullptr)
			{
				shared_ptr<OMLContext> markContext = getPage()->parseOmlEx(messageAuthor->mark, false, true, getSecure(), false, omlRenderModeOsiris, String::EMPTY, String::EMPTY);
				if(markContext != nullptr)
					unsafe = markContext->getSecureCheck() == false;
			}
		}

		if(unsafe)
		{
			shared_ptr<XMLNode> action_delete = node_actions->addChild(_S("action"));
			action_delete->setAttributeString(_S("name"), _S("show"));
			action_delete->setAttributeString(_S("href"), getPortal()->getPrivateMessageLink(id, false));
		}
	}
}