コード例 #1
0
ファイル: BDoc.cpp プロジェクト: tixsys/esteid
/**
 * Saves the container using the <code>serializer</code> implementation provided in
 * <code>readFrom()</code> method.
 *
 * @throws IOException is thrown if there was a failure saving BDOC container. For example added
 *         document does not exist.
 * @throws BDocException is thrown if BDoc class is not correctly initialized.
 */
void digidoc::BDoc::save() throw(IOException, BDocException)
{
    // Check that serializer is provided.
    if(serializer.get() == NULL)
    {
        THROW_BDOCEXCEPTION("You can not use save() method if you didn't open a container with readFrom() method. Use saveTo() method in case of new a BDoc container.");
    }

    // Check that at least one document is in container.
    if( documents.empty() )
    {
        THROW_BDOCEXCEPTION("Can not save, BDoc container is empty.");
    }

    // Create new container.
    serializer->create();

    // Create mimetype file and add it to container.
    serializer->addFile("mimetype", createMimetype());

    // Create manifest file and add it to container.
    // NB! Don't change the order of signatures in list after manifest is created,
    //     otherwise manifest has incorrect signature mimetypes.
    serializer->addFile("META-INF/manifest.xml", createManifest());

    // Add all documents to container.
    for(std::vector<Document>::const_iterator iter = documents.begin(); iter != documents.end(); iter++)
    {
        serializer->addFile(util::File::fileName(iter->getPath()), iter->getPath());
    }

    // Add all signatures to container.
    unsigned int i = 0;
    for(std::vector<Signature*>::const_iterator iter = signatures.begin(); iter != signatures.end(); iter++)
    {
        serializer->addFile(util::String::format("META-INF/signature%u.xml", i++), (*iter)->saveToXml());
    }

    // Save container.
    serializer->save();
}
コード例 #2
0
bool
aBackup::exportData(const QString& rcfile, const QString &archfile, bool withTemplates )
{
	QDir dir;
	int prg=0;
	int totalSteps=10;
        QString temp;
	QString tmpDirName;
	QString srcDirName;
	QStringList templatesName;

#ifndef _Windows
	temp = getenv("TMPDIR");
	if(temp=="" || temp.isEmpty())
		temp = P_tmpdir;
#else
	temp = getenv("TEMP");
#endif
	tmpDirName = QString(temp+"/%1").arg(QDateTime::currentDateTime().toTime_t());
	tmpDirName = QDir::convertSeparators(tmpDirName);
	//printf("copy name = %s\n",tmpDirName.ascii());
	if(!dir.mkdir(tmpDirName))
	{
		setLastError(tr("Can't create directory %s").arg(tmpDirName));
		aLog::print(aLog::Error, tr("aBackup create temporary directory"));
		return true;
	}
	else
	{
		aLog::print(aLog::Debug, tr("aBackup create temporary directory %1").arg(tmpDirName));

	}
	if(!dir.mkdir(tmpDirName+"/META-INF"))
	{
		setLastError(tr("Can't create directory %s").arg(tmpDirName+"/META-INF"));
		aLog::print(aLog::Error, tr("aBackup create temporary directory"));
		cleanupTmpFiles(tmpDirName, &templatesName);
		return true;
	}
	else
	{
		aLog::print(aLog::Debug, tr("aBackup create temporary directory %1").arg(tmpDirName+"/META-INF"));
	}
	aCfg cfg;
	// create copy of metadata
	if(cfg.readrc( rcfile ))
	{
		setLastError(tr("Invalid resource file"));
		aLog::print(aLog::Error, tr("aBackup invalid *.rc file"));
		cleanupTmpFiles(tmpDirName, &templatesName);
		return true;
	}
	else
	{
		aLog::print(aLog::Debug, tr("aBackup valid *.rc file"));
	}
	qApp->processEvents();

	if(withTemplates)
	{
		srcDirName = QDir::convertSeparators(cfg.rc.value("workdir"));
		aLog::print(aLog::Debug, tr("aBackup workdir=%1").arg(srcDirName));
		dir.setPath(srcDirName);
		templatesName = dir.entryList("templ_*.odt;templ_*.ods");
		for(uint i=0; i<templatesName.count(); i++)
		{
			//ayTests::print2log("f:\\ERROR.log", "aBackup", tmpDirName + "/templates/"+templatesName[i]);
			aLog::print(aLog::Debug, tr("aBackup template %1 %2").arg(i).arg(tmpDirName + "/templates/"+templatesName[i]));
//			file.remove();
		}
	}


	emit(progress(++prg,totalSteps));
	if(cfg.write( tmpDirName+"/busines-schema.cfg" ))
	{
		setLastError(tr("Can't write resource file"));
		aLog::print(aLog::Error, tr("aBackup write %1 file").arg(tmpDirName+"/busines-schema.cfg"));
		cleanupTmpFiles(tmpDirName, &templatesName);
		return true;
	}
	else
	{
		aLog::print(aLog::Debug, tr("aBackup write %1 file").arg(tmpDirName+"/busines-schema.cfg"));

	}
	qApp->processEvents();
	emit(progress(++prg,totalSteps));
	// create dump
	if(dumpBase(rcfile,tmpDirName, prg, totalSteps )==true)
	{
		cleanupTmpFiles(tmpDirName, &templatesName);
		aLog::print(aLog::Error, tr("aBackup dump base error"));
		return true;
	}
	else
	{
		aLog::print(aLog::Debug, tr("aBackup bump base"));
	}

	if(writeXml(QDir::convertSeparators(tmpDirName+"/META-INF/manifest.xml"), createManifest(templatesName))==true)
	{
		setLastError(tr("Can't write file META-INF/manifest.xml"));
		aLog::print(aLog::Error, tr("aBackup write manifest.xml"));
		cleanupTmpFiles(tmpDirName, &templatesName);
		return true;
	}
	else
	{
		aLog::print(aLog::Debug, tr("aBackup write manifest.xml"));
	}
//	printf("%s\n",(createManifest(templatesName)).toString().ascii());
	if(withTemplates)
	{
		QString destNamePref = tmpDirName + "/templates";
		dir.mkdir(destNamePref);
		bool res = false;
		for(uint i=0; i<templatesName.count(); i++)
		{
//				printf("copy %s to %s\n", QString(srcDirName+"/"+templatesName[i]).ascii(), QString(destNamePref+"/"+templatesName[i]).ascii());
			if(!aService::copyFile(QDir::convertSeparators(srcDirName+"/"+templatesName[i]), QDir::convertSeparators(destNamePref+"/"+templatesName[i]), true))
			{
				setLastError(tr("Can't copy template file"));
				res&=true;
			}

		}
	}

	if(zipArchive(archfile + ".bsa", tmpDirName)==true)
	{
//		setLastError(tr("Can't zip archive"));
		cleanupTmpFiles(tmpDirName, &templatesName);
		aLog::print(aLog::Error, tr("aBackup zip archive"));
		return true;
	}
	else
	{
		aLog::print(aLog::Debug, tr("aBackup zip archive"));
	}
	// remove files and directories
	cleanupTmpFiles(tmpDirName, &templatesName);
	emit (progress(++prg,totalSteps));
	setLastError(tr("Data export done without errors"));
	aLog::print(aLog::Debug, tr("aBackup export data ok"));

	return false;
}
コード例 #3
0
ファイル: WPGImport.cpp プロジェクト: JeremiasE/KFormula
KoFilter::ConversionStatus WPGImport::convert( const QByteArray& from, const QByteArray& to )
{
  if ( from != "application/x-wpg" )
    return KoFilter::NotImplemented;

  if ( to != "application/vnd.oasis.opendocument.graphics" )
    return KoFilter::NotImplemented;


  WPXInputStream* input = new libwpg::WPGFileStream( m_chain->inputFile().toLocal8Bit() );
  if (input->isOLEStream())
  {
    WPXInputStream* olestream = input->getDocumentOLEStream();
    if (olestream)
    {
      delete input;
      input = olestream;
    }
  }

  if (!libwpg::WPGraphics::isSupported(input))
  {
    std::cerr << "ERROR: Unsupported file format (unsupported version) or file is encrypted!" << std::endl;
    delete input;
    return KoFilter::NotImplemented;
  }

  // do the conversion
  std::ostringstream tmpStringStream;
  FileOutputHandler tmpHandler(tmpStringStream);
  OdgExporter exporter(&tmpHandler);
  libwpg::WPGraphics::parse(input, &exporter);
  delete input;


  // create output store
  KoStore* storeout;
  storeout = KoStore::createStore( m_chain->outputFile(), KoStore::Write,
    "application/vnd.oasis.opendocument.graphics", KoStore::Zip );

  if ( !storeout )
  {
    kWarning() << "Couldn't open the requested file.";
    return KoFilter::FileNotFound;
  }

#if 0
  if ( !storeout->open( "styles.xml" ) )
  {
    kWarning() << "Couldn't open the file 'styles.xml'.";
    return KoFilter::CreationError;
  }
  //storeout->write( createStyles() );
  storeout->close();
#endif

  if ( !storeout->open( "content.xml" ) )
  {
    kWarning() << "Couldn't open the file 'content.xml'.";
    return KoFilter::CreationError;
  }
  storeout->write(tmpStringStream.str().c_str());
  storeout->close();

  // store document manifest
  storeout->enterDirectory( "META-INF" );
  if ( !storeout->open( "manifest.xml" ) )
  {
     kWarning() << "Couldn't open the file 'META-INF/manifest.xml'.";
     return KoFilter::CreationError;
  }
  storeout->write( createManifest() );
  storeout->close();

  // we are done!
  delete storeout;

  return KoFilter::OK;
}