bool OEBMetaInfoReader::isDublinCoreNamespace(const std::string &nsId) const {
	const std::map<std::string,std::string> &namespaceMap = namespaces();
	std::map<std::string,std::string>::const_iterator iter = namespaces().find(nsId);
	return
		((iter != namespaceMap.end()) &&
		 (ZLStringUtil::stringStartsWith(iter->second, ZLXMLNamespace::DublinCorePrefix) ||
		  ZLStringUtil::stringStartsWith(iter->second, ZLXMLNamespace::DublinCoreLegacyPrefix)));
}
Beispiel #2
0
	Class::Name Class::get(const GCTP_TYPEINFO &typeinfo)
	{
		Class::Name ret = {0, 0};
		for(NameSpaceMap::const_iterator i = namespaces().begin(); i != namespaces().end(); ++i) {
			for(ClassMap::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
				if(*((const GCTP_TYPEINFO *)j->second)==typeinfo) {
					ret.ns = i->first.c_str();
					ret.classname = j->first.c_str();
					return ret;
				}
			}
		}
		return ret;
	}
KoFilter::ConversionStatus XlsxXmlCommentsReader::readInternal()
{
    readNext();
    if (!isStartDocument()) {
        return KoFilter::WrongFormat;
    }

    // comments
    readNext();
    kDebug() << *this << namespaceUri();

    if (!expectEl("comments")) {
        return KoFilter::WrongFormat;
    }
    if (!expectNS(MSOOXML::Schemas::spreadsheetml)) {
        return KoFilter::WrongFormat;
    }

    QXmlStreamNamespaceDeclarations namespaces(namespaceDeclarations());
    for (int i = 0; i < namespaces.count(); i++) {
        kDebug() << "NS prefix:" << namespaces[i].prefix() << "uri:" << namespaces[i].namespaceUri();
    }
//! @todo find out whether the namespace returned by namespaceUri()
//!       is exactly the same ref as the element of namespaceDeclarations()
    if (!namespaces.contains(QXmlStreamNamespaceDeclaration(QString(), MSOOXML::Schemas::spreadsheetml))) {
        raiseError(i18n("Namespace \"%1\" not found", MSOOXML::Schemas::spreadsheetml));
        return KoFilter::WrongFormat;
    }
//! @todo expect other namespaces too...

    TRY_READ(comments)

    kDebug() << "===========finished============";
    return KoFilter::OK;
}
bool OEBDescriptionReader::isOPFNamespace(const std::string &nsId) const {
	const std::map<std::string,std::string> &namespaceMap = namespaces();
	std::map<std::string,std::string>::const_iterator iter = namespaceMap.find(nsId);
	return
		(iter != namespaceMap.end()) &&
		(iter->second == XMLNamespace::OpenPackagingFormat);
}
void OPDSXMLParser::namespaceListChangedHandler() {
	myDublinCoreNamespaceId.erase();
	myAtomNamespaceId.erase();
	myOpenSearchNamespaceId.erase();
	myCalibreNamespaceId.erase();
	myOpdsNamespaceId.erase();

	const std::map<std::string,std::string> &nsMap = namespaces();
	for (std::map<std::string,std::string>::const_iterator it = nsMap.begin(); it != nsMap.end(); ++it) {
		if (it->first.empty()) {
			continue;
		}
		if (it->second == XMLNamespace::DublinCoreTerms) {
			myDublinCoreNamespaceId = it->first;
		} else if (it->second == XMLNamespace::Atom) {
			myAtomNamespaceId = it->first;
		} else if (it->second == XMLNamespace::OpenSearch) {
			myOpenSearchNamespaceId = it->first;
		} else if (it->second == XMLNamespace::CalibreMetadata) {
			myCalibreNamespaceId = it->first;
		} else if (it->second == XMLNamespace::Opds) {
			myOpdsNamespaceId = it->first;
		}
	}
}
bool OEBDescriptionReader::isDublinCoreNamespace(const std::string &nsId) const {
	static const std::string DC_SCHEME_PREFIX = "http://purl.org/dc/elements";
	const std::map<std::string,std::string> &namespaceMap = namespaces();
	std::map<std::string,std::string>::const_iterator iter = namespaceMap.find(nsId);
	return
		(iter != namespaceMap.end()) &&
		ZLStringUtil::stringStartsWith(iter->second, DC_SCHEME_PREFIX);
}
Beispiel #7
0
void FB2BookReader::namespaceListChangedHandler() {
	const std::map<std::string,std::string> namespaceMap = namespaces();
	for (std::map<std::string,std::string>::const_iterator it = namespaceMap.begin(); it != namespaceMap.end(); ++it) {
		if (ZLStringUtil::stringStartsWith(it->second, XMLNamespace::XLink)) {
			myHrefAttributeName = it->first + ":href";
			return;
		}
	}
	myHrefAttributeName = "";
}
void FBReaderOrgDataParser::namespaceListChangedHandler() {
	myDCPrefix.erase();
	const std::map<std::string,std::string> &nsMap = namespaces();
	for (std::map<std::string,std::string>::const_iterator it = nsMap.begin(); it != nsMap.end(); ++it) {
		if (ZLStringUtil::stringStartsWith(it->second, XMLNamespace::DublinCorePrefix)) {
			myDCPrefix = it->first + ':';
			break;
		}
	}
}
void FB2BookReader::namespaceListChangedHandler() {
	const std::string XLINK_REFERENCE = "http://www.w3.org/1999/xlink";
	const std::map<std::string,std::string> namespaceMap = namespaces();
	for (std::map<std::string,std::string>::const_iterator it = namespaceMap.begin(); it != namespaceMap.end(); ++it) {
		if (ZLStringUtil::stringStartsWith(it->second, XLINK_REFERENCE)) {
			myHrefAttributeName = it->first + ":href";
			return;
		}
	}
	myHrefAttributeName = "";
}
bool OEBMetaInfoReader::isNSName(const std::string &fullName, const std::string &shortName, const std::string &fullNSId) const {
	const int prefixLength = fullName.length() - shortName.length() - 1;
	if (prefixLength <= 0 ||
			fullName[prefixLength] != ':' ||
			!ZLStringUtil::stringEndsWith(fullName, shortName)) {
		return false;
	}
	const std::map<std::string,std::string> &namespaceMap = namespaces();
	std::map<std::string,std::string>::const_iterator iter =
		namespaceMap.find(fullName.substr(0, prefixLength));
	return iter != namespaceMap.end() && iter->second == fullNSId;
}
Beispiel #11
0
void OEBBookReader::namespaceListChangedHandler() {
	const std::map<std::string,std::string> &namespaceMap = namespaces();
	std::map<std::string,std::string>::const_iterator iter = namespaceMap.begin();
	for (; iter != namespaceMap.end(); ++iter) {
		if (iter->second == XMLNamespace::OpenPackagingFormat) {
			break;
		}
	}
	if (iter != namespaceMap.end()) {
		myOPFSchemePrefix = iter->first + ":";
	} else {
		myOPFSchemePrefix.erase();
	}
}
Beispiel #12
0
KoFilter::ConversionStatus XlsxXmlDocumentReader::readInternal()
{
    kDebug() << "=============================";
    readNext();
    if (!isStartDocument()) {
        return KoFilter::WrongFormat;
    }

    // workbook
    readNext();
    kDebug() << *this << namespaceUri();

    if (!expectEl("workbook")) {
        return KoFilter::WrongFormat;
    }
    if (!expectNS(MSOOXML::Schemas::spreadsheetml)) {
        return KoFilter::WrongFormat;
    }
    /*
        const QXmlStreamAttributes attrs( attributes() );
        for (int i=0; i<attrs.count(); i++) {
            kDebug() << "1 NS prefix:" << attrs[i].name() << "uri:" << attrs[i].namespaceUri();
        }*/

    QXmlStreamNamespaceDeclarations namespaces(namespaceDeclarations());
    for (int i = 0; i < namespaces.count(); i++) {
        kDebug() << "NS prefix:" << namespaces[i].prefix() << "uri:" << namespaces[i].namespaceUri();
    }
//! @todo find out whether the namespace returned by namespaceUri()
//!       is exactly the same ref as the element of namespaceDeclarations()
    if (!namespaces.contains(QXmlStreamNamespaceDeclaration(QString(), MSOOXML::Schemas::spreadsheetml))) {
        raiseError(i18n("Namespace \"%1\" not found", MSOOXML::Schemas::spreadsheetml));
        return KoFilter::WrongFormat;
    }
//! @todo expect other namespaces too...

    TRY_READ(workbook)

//! @todo hardcoded font face list; look at fonts used by theme
    mainStyles->insertFontFace(KOdfFontData("Calibri"));
    mainStyles->insertFontFace(KOdfFontData("Arial"));
    mainStyles->insertFontFace(KOdfFontData("Tahoma"));

    kDebug() << "===========finished============";
    return KoFilter::OK;
}
KoFilter::ConversionStatus DocxXmlFontTableReader::read(MSOOXML::MsooXmlReaderContext* context)
{
    m_context = dynamic_cast<DocxXmlFontTableReaderContext*>(context);
    kDebug() << "=============================";
    readNext();
    if (!isStartDocument()) {
        return KoFilter::WrongFormat;
    }

    //w:document
    readNext();
    kDebug() << namespaceUri();

    if (!expectEl("w:fonts")) {
        return KoFilter::WrongFormat;
    }
    if (!expectNS(MSOOXML::Schemas::wordprocessingml)) {
        return KoFilter::WrongFormat;
    }
    /*
        const QXmlStreamAttributes attrs( attributes() );
        for (int i=0; i<attrs.count(); i++) {
            kDebug() << "1 NS prefix:" << attrs[i].name() << "uri:" << attrs[i].namespaceUri();
        }*/

    QXmlStreamNamespaceDeclarations namespaces(namespaceDeclarations());
    for (int i = 0; i < namespaces.count(); i++) {
        kDebug() << "NS prefix:" << namespaces[i].prefix() << "uri:" << namespaces[i].namespaceUri();
    }
//! @todo find out whether the namespace returned by namespaceUri()
//!       is exactly the same ref as the element of namespaceDeclarations()
    if (!namespaces.contains(QXmlStreamNamespaceDeclaration("w", MSOOXML::Schemas::wordprocessingml))) {
        raiseError(i18n("Namespace \"%1\" not found", MSOOXML::Schemas::wordprocessingml));
        return KoFilter::WrongFormat;
    }
//! @todo expect other namespaces too...

    TRY_READ(fonts)

    if (!expectElEnd("w:fonts")) {
        return KoFilter::WrongFormat;
    }

    kDebug() << "===========finished============";
    return KoFilter::OK;
}
Beispiel #14
0
bool ZLXMLReader::testTag(const std::string &ns, const std::string &name, const std::string &tag) const {
	const nsMap &nspaces = namespaces();

	if (name == tag) {
		const nsMap::const_iterator it = nspaces.find(std::string());
		return it != nspaces.end() && ns == it->second;
	}
	const int nameLen = name.size();
	const int tagLen = tag.size();
	if (tagLen < nameLen + 2) {
		return false;
	}
	if (ZLStringUtil::stringEndsWith(tag, name) && tag[tagLen - nameLen - 1] == ':') {
		const nsMap::const_iterator it = nspaces.find(tag.substr(0, tagLen - nameLen - 1));
		return it != nspaces.end() && ns == it->second;
	}
	return false;
}
Beispiel #15
0
void associative_container_helper::
format(assistant& a, const formattables::helper_properties& hp) const {
    {
        const auto d(hp.current());
        const auto qn(d.name_tree_qualified());
        auto snf(a.make_scoped_namespace_formatter(d.namespaces()));

        if (hp.direct_descendants().size() == 2) {
            const auto key(hp.direct_descendants().front());
            const auto value(hp.direct_descendants().back());
a.stream() << std::endl;
a.stream() << "inline std::ostream& operator<<(std::ostream& s, const " << qn << "& v) {" << std::endl;
a.stream() << "    s << \"[\";" << std::endl;
a.stream() << "    for (auto i(v.begin()); i != v.end(); ++i) {" << std::endl;
a.stream() << "        if (i != v.begin()) s << \", \";" << std::endl;
a.stream() << "        s << \"[ { \" << \"\\\"__type__\\\": \" << \"\\\"key\\\"\" << \", \" << \"\\\"data\\\": \";" << std::endl;
a.stream() << "        s << " << a.streaming_for_type(key, "i->first") << ";" << std::endl;
a.stream() << "        s << \" }, { \" << \"\\\"__type__\\\": \" << \"\\\"value\\\"\" << \", \" << \"\\\"data\\\": \";" << std::endl;
a.stream() << "        s << " << a.streaming_for_type(value, "i->second") << ";" << std::endl;
a.stream() << "        s << \" } ]\";" << std::endl;
a.stream() << "    }" << std::endl;
a.stream() << "    s << \" ] \";" << std::endl;
a.stream() << "    return s;" << std::endl;
a.stream() << "}" << std::endl;
a.stream() << std::endl;
        } else {
        const auto containee(hp.direct_descendants().front());
a.stream() << std::endl;
a.stream() << "inline std::ostream& operator<<(std::ostream& s, const " << qn << "& v) {" << std::endl;
a.stream() << "    s << \"[ \";" << std::endl;
a.stream() << "    for (auto i(v.begin()); i != v.end(); ++i) {" << std::endl;
a.stream() << "        if (i != v.begin()) s << \", \";" << std::endl;
a.stream() << "        s << " << a.streaming_for_type(containee, "*i") << ";" << std::endl;
a.stream() << "    }" << std::endl;
a.stream() << "    s << \"] \";" << std::endl;
a.stream() << "    return s;" << std::endl;
a.stream() << "}" << std::endl;
a.stream() << std::endl;
        }
    }
a.stream() << std::endl;
}
Beispiel #16
0
KoFilter::ConversionStatus DocxXmlHeaderReader::read(MSOOXML::MsooXmlReaderContext* context)
{
    m_context = static_cast<DocxXmlDocumentReaderContext*>(context);

    kDebug() << "=============================";
    readNext();
    if (!isStartDocument()) {
        return KoFilter::WrongFormat;
    }
    readNext();

    kDebug() << *this << namespaceUri();
    if (!expectEl(QList<QByteArray>() << "w:hdr")) {
        return KoFilter::WrongFormat;
    }
    if (!expectNS(MSOOXML::Schemas::wordprocessingml)) {
        return KoFilter::WrongFormat;
    }

    QXmlStreamNamespaceDeclarations namespaces(namespaceDeclarations());

    //! @todo find out whether the namespace returned by namespaceUri()
    //!       is exactly the same ref as the element of namespaceDeclarations()
    if (!namespaces.contains(QXmlStreamNamespaceDeclaration("w", MSOOXML::Schemas::wordprocessingml))) {
        raiseError(i18n("Namespace \"%1\" not found", MSOOXML::Schemas::wordprocessingml));
        return KoFilter::WrongFormat;
    }

    const QString qn(qualifiedName().toString());

    RETURN_IF_ERROR(read_hdr())

    if (!expectElEnd(qn)) {
        return KoFilter::WrongFormat;
    }
    kDebug() << "===========finished============";

    return KoFilter::OK;
}
Beispiel #17
0
void optional_helper::
format(assistant& a, const formattables::helper_properties& hp) const {
    {
        const auto d(hp.current());
        const auto nt_qn(d.name_tree_qualified());
        const auto n_qn(d.name_qualified());
        auto snf(a.make_scoped_namespace_formatter(d.namespaces()));
        const auto containee(hp.direct_descendants().front());
a.stream() << std::endl;
a.stream() << "inline std::ostream& operator<<(std::ostream& s, const " << nt_qn << "& v) {" << std::endl;
a.stream() << "    s << \"{ \" << \"\\\"__type__\\\": \" << \"\\\"" << n_qn << "\\\"\" << \", \";" << std::endl;
a.stream() << std::endl;
a.stream() << "    if (v)" << std::endl;
a.stream() << "        s << \"\\\"data\\\": \" << " << a.streaming_for_type(containee, "*v") << ";" << std::endl;
a.stream() << "    else" << std::endl;
a.stream() << "        s << \"\\\"data\\\": \"\"\\\"<null>\\\"\";" << std::endl;
a.stream() << "    s << \" }\";" << std::endl;
a.stream() << "    return s;" << std::endl;
a.stream() << "}" << std::endl;
a.stream() << std::endl;
    }
a.stream() << std::endl;
}
Beispiel #18
0
void
MetaBlock::postParse() {

    addNamespaces(parent_->namespaces());

    if (!method().empty()) {
        throw std::runtime_error("Method is not allowed in meta");
    }

    if (!params().empty()) {
        throw std::runtime_error("Params is not allowed in meta");
    }

    if (xsltDefined()) {
        throw std::runtime_error("Xslt is not allowed in meta");
    }

    if (lua_block_.get()) {
        if (lua_block_->xsltDefined()) {
            throw std::runtime_error("Xslt is not allowed in meta lua");
        }
        if (lua_block_->metaBlock()) {
            throw std::runtime_error("Meta is not allowed in meta lua");
        }
    }

    if (hasGuard()) {
        throw std::runtime_error("Guard is not allowed in meta");
    }

    if (root_name_.empty()) {
        root_name_.assign("meta");
    }
    else {
        std::string::size_type pos = root_name_.find(':');
        if (std::string::npos != pos) {
            std::string prefix = root_name_.substr(0, pos);
            root_name_.erase(0, pos + 1);

            if (root_name_.empty()) {
                throw std::runtime_error("Empty name in name attribute is not allowed in meta");
            }
            if (!prefix.empty()) {
                const std::map<std::string, std::string> names = namespaces();
                std::map<std::string, std::string>::const_iterator it = names.find(prefix);
                if (names.end() == it) {
                    std::stringstream str;
                    str << "Unknown " << parent_->name() << " block namespace: " << prefix;
                    throw std::runtime_error(str.str());
                }
                root_ns_ = xmlSearchNsByHref(node()->doc, node(), (const xmlChar*)it->second.c_str());
                if (NULL == root_ns_) {
                    std::stringstream str;
                    str << "Cannot find " << parent_->name() << " block namespace: " << prefix;
                    throw std::runtime_error(str.str());
                }
            }
        }
        else {
            root_ns_ = NULL;
        }
    }

    if (before_cache_save_lua_.get()) {
        Range code = getLuaCode(before_cache_save_lua_.get());
        if (!code.empty()) {
            key_.push_back('|');
            key_.append(HashUtils::hexMD5(code.begin(), code.size()));
        }
    }
}
Beispiel #19
0
	const GCTP_TYPEINFO *Class::get(const char *ns, const char *classname)
	{
		NameSpaceMap::iterator map = namespaces().find(ns);
		if(map != namespaces().end()) return map->second.get(classname);
		return 0;
	}