Exemplo n.º 1
0
bool OdtWriter::writeCompressed(QIODevice* device, const QTextDocument* document)
{
	QtZipWriter zip(device);
	if (zip.status() != QtZipWriter::NoError) {
		return false;
	}

	zip.setCompressionPolicy(QtZipWriter::NeverCompress);
	zip.addFile(QString::fromLatin1("mimetype"),
		"application/vnd.oasis.opendocument.text");
	zip.setCompressionPolicy(QtZipWriter::AlwaysCompress);

	zip.addFile(QString::fromLatin1("META-INF/manifest.xml"),
		"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
		"<manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\" manifest:version=\"1.2\">\n"
		" <manifest:file-entry manifest:full-path=\"/\" manifest:version=\"1.2\" manifest:media-type=\"application/vnd.oasis.opendocument.text\"/>\n"
		" <manifest:file-entry manifest:full-path=\"content.xml\" manifest:media-type=\"text/xml\"/>\n"
		" <manifest:file-entry manifest:full-path=\"styles.xml\" manifest:media-type=\"text/xml\"/>\n"
		"</manifest:manifest>\n");

	zip.addFile(QString::fromLatin1("content.xml"),
		writeDocument(document));

	zip.addFile(QString::fromLatin1("styles.xml"),
		writeStylesDocument(document));

	zip.close();

	return zip.status() == QtZipWriter::NoError;
}
Exemplo n.º 2
0
int writeDocumentToFile(Document *doc, const char* filename)
{
    writeDocument(doc);
    int returnVal = saveSBOLDocument(filename);
	cleanupSBOLWriter();
	return returnVal;
}
Exemplo n.º 3
0
char* writeDocumentToString(Document *doc)
{
    writeDocument(doc);
    // WARNING: Does not check for proper xmlChar* allocation
    xmlChar* out;
    int s;
    xmlDocDumpMemory(OUTPUT, &out, &s);
    cleanupSBOLWriter();
    return (char *)out;
}
Exemplo n.º 4
0
int XmlToKross::start()
{
    inclass=0;
    while (!xml.atEnd())
    {
        QXmlStreamReader::TokenType t=xml.readNext(); 
        QString str;
        
        switch(t)
        {
            case QXmlStreamReader::Invalid:
                qDebug() << "invalid token!" << xml.errorString() << endl;
                break;
            case QXmlStreamReader::StartDocument:
                writeDocument();
                break;
            case QXmlStreamReader::StartElement:
//                         qDebug() << "Element " << xml.name().toString() << endl;
                str=xml.name().toString();
                if(str=="Class")
                {
                    inclass++;
                    if(inclass==1) writeClass(xml.attributes().value(QString(), "name").toString(), QString(), QList<QStringList>());
                }
                else if(str=="Function")
                {
                    QString funcname=xml.attributes().value(QString(), "name").toString();
                    QString rettype=xml.attributes().value(QString(), "type_name").toString();
                    
                    bool isConst=xml.attributes().value(QString(), "constant").toString()==QChar('1');
                    bool isVirtual=xml.attributes().value(QString(), "virtual").toString()==QChar('1');
                    currentMethod=method();
                    currentMethod.access=xml.attributes().value(QString(), "access").toString();
                    currentMethod.funcname=funcname;
                    currentMethod.returnType=rettype;
                    currentMethod.isConst=isConst;
                    currentMethod.isVirtual=isVirtual;
                    if(!definedClasses.isEmpty() && ( funcname==definedClasses.last() || funcname=='~'+definedClasses.last() ) )
                        currentMethod.access="constructor";
                }
                else if(str=="Argument")
                {
                    method::argument arg;
                    arg.name=xml.attributes().value(QString(), "name").toString();
                    arg.type=xml.attributes().value(QString(), "type_name").toString();
                    arg.def=xml.attributes().value(QString(), "defaultvalue").toString();
                    QString context=xml.attributes().value(QString(), "context").toString();
                    if(!arg.def.isEmpty() && arg.type.startsWith(context))
                        arg.def.prepend(context+"::");
                    
                    currentMethod.args.append(arg);
                }
                else if(str=="Namespace")
                {
                    QString name=xml.attributes().value(QString(), "name").toString();
                    
                    qDebug() << "entering to namespace " << name << inNamespace;
                    if(inNamespace!=name)
                    {
                        if(!inNamespace.isEmpty())
                            inNamespace.append("::");
                        inNamespace.append(name);
                        writeNamespace(name);
                        qDebug() << "current status" << inNamespace;
                    }
                }
                else if(str=="Variable" && inclass==1 &&
                    xml.attributes().value(QString(), "access").toString()=="public")
                {
                    writeVariable(xml.attributes().value(QString(), "name").toString(),
                                    xml.attributes().value(QString(), "type_name").toString(), xml.attributes().value(QString(), "type_constant").toString()=="1");
                }
                else if(str=="Enum")
                {
                    flags.clear();
                    flags.append(xml.attributes().value(QString(), "name").toString());
                }
                else if(str=="Enumerator")
                    flags.append(xml.attributes().value(QString(), "name").toString());
                break;
            case QXmlStreamReader::EndDocument:
                writeEndDocument();
                break;
            case QXmlStreamReader::EndElement:
                str=xml.name().toString();
                if(str=="Class")
                {
                    if(inclass==1) writeEndClass();
                    inclass--;
                }
                else if(str=="Function" && currentMethod.access=="public" && inclass==1)
                    writeEndFunction(currentMethod);
                else if(str=="Enum")
                    writeEndEnum(flags);
                else if(str=="Namespace")
                {
                    inNamespace.resize(inNamespace.lastIndexOf("::"));
                }
                break;
            default:
                break;
        }
    }
    if (xml.error())
    {
        qDebug() << "error!" << xml.errorString();
        return 2;
    }
    return 0;
}
Exemplo n.º 5
0
		std::string BsonSerializer::serialize(const AnyValue & any) const
		{
			auto value = any.as<Bundle>();
			auto res = writeDocument(value);
			return std::string(res.begin(), res.end());
		}