Exemplo n.º 1
0
int main(int argC, char* /* argV[] */)
{

	XmlManager xmlmanager;
	xmlmanager.CreateDocument();
	xmlmanager.PrintDocumentToScreen();

	std::string test = "trial3.xml";
	xmlmanager.PrintDocumentToFile(test.c_str());

	XmlManager xmlmanager2;
	std::string test2 = "test.xml";
	xmlmanager2.ImportDocument(test2.c_str());
	std::cerr << "worked so far..." << std::endl;
	
//	xmlmanager2.PrintDocumentToScreen();
//	xmlmanager2.CreateDocument();

//	xmlmanager2.PrintDocumentToScreen();


	cerr << "Doc = " << endl << xmlmanager2.getDocumentAsString() << endl;

	cerr << "node: " << xercesc::XMLString::transcode( 
		xmlmanager2.doc->getChildNodes()->item(1)->getChildNodes()->item(2)->getNodeValue() ) << endl;



	return 0;
}
// --------------------------------------------------------------------
static void dict_to_dbxml_proc (map <string,Unit> dict_aa,string containerName)
{
	XmlManager mgr;

	if (mgr.existsContainer(containerName))
		{
		mgr.removeContainer(containerName);
		}

	XmlContainer cont = mgr.createContainer(containerName);

	XmlUpdateContext uc = mgr.createUpdateContext();

	map <string,Unit>:: iterator it = dict_aa.begin ();

	while (it != dict_aa.end ())
		{
		string key = (*it).first;
		Unit unit_aa = (*it).second;

		string row_aa = "<" + key + "><name>" + unit_aa["name"] \
			+ "</name><population>" + unit_aa["population"] \
			+ "</population><date_mod>" + unit_aa["date_mod"] \
			+ "</date_mod></" + key + ">";

		cont.putDocument (key,row_aa,uc);
		it++;
		}
}
Exemplo n.º 3
0
void SettingsDialog::exportForGCStar(){
    XmlManager manager;
    QList<QMultiMap<QString, QString> > base;
    if(insSettingsManager->getSettings(Xml).toBool()){
        base = manager.readBase();
    }
    else{
        //On crée manuellement la liste
    SqlManager sql;
        QSqlQuery requete = sql.query("SELECT livres.id, livres.titre, livres.ISBN, livres.coauteurs, livres.synopsis, livres.couverture, livres.pages, livres.edition, livres.langue, livres.classement, livres.exemplaires, livres.commentaire, livres.lu, livres.note, livres.empruntable, livres.prete, livres.annee, auteurs.nom, editeurs.nom AS nom_editeur FROM livres LEFT JOIN auteurs ON livres.auteur = auteurs.id LEFT JOIN editeurs ON livres.editeur = editeurs.id ORDER BY id");
        while(requete.next()){
            QMultiMap <QString, QString> livre;
            livre.insert("id", requete.record().value("id").toString());
            livre.insert("titre", requete.record().value("titre").toString());
            livre.insert("isbn", requete.record().value("isbn").toString());
            livre.insert("synopsis", requete.record().value("synopsis").toString());
            livre.insert("couverture", requete.record().value("couverture").toString());
            livre.insert("pages", requete.record().value("pages").toString());
            livre.insert("edition", requete.record().value("edition").toString());
            livre.insert("langue", requete.record().value("langue").toString());
            livre.insert("classement", requete.record().value("classement").toString());
            livre.insert("commentaire", requete.record().value("commentaire").toString());
            livre.insert("editeur", requete.record().value("nom_editeur").toString());
            livre.insert("annee", requete.record().value("annee").toString());
            livre.insert("lu", requete.record().value("lu").toBool() ? "True" : "False");
            livre.insert("prete", requete.record().value("prete").toBool() ? "True" : "False");
            base.append(livre);
        }
    }
    manager.exportCurrentAsGCStar(base);
    return;
}
Exemplo n.º 4
0
void putDocWithMyCompression(XmlManager& mgr,
			     const string& containerName,
			     XmlDocument& xdoc,
			     XmlUpdateContext& uc,
			     XmlCompression& myCompression)
{
	// Define an unique name to use for registering the compression
	string compressionName = "myCompression";
	
	// Register custom class
	mgr.registerCompression(compressionName.c_str(), myCompression);

	// Set the container type as WholedocContainer
	// and use the custom compression
	XmlContainerConfig contConf;
	contConf.setAllowCreate(true);
	contConf.setContainerType(XmlContainer::WholedocContainer);
	contConf.setCompressionName(compressionName.c_str());

	// Create container
	XmlContainer cont = mgr.createContainer(containerName, contConf);

	// Put Document
	cont.putDocument(xdoc, uc);
}
Exemplo n.º 5
0
std::string getValue( XmlTransaction &txn, XmlManager &mgr, const XmlDocument &document,
					 const std::string &XPath, XmlQueryContext &context )
{
	/////////////////////////////////////////////////////////////////////////////////
	///////////    Return specific information from a document. /////////////////////
	///////////   !!!!!! Assumes a result set of size 1 !!!!!!! /////////////////////
	/////////////////////////////////////////////////////////////////////////////////

	// Exception handling omitted....

	//Perform the query
	XmlQueryExpression doc_expr = mgr.prepare(txn, XPath, context);
	XmlResults result = doc_expr.execute( txn, XmlValue(document), context);

	//We require a result set size of 1.
	assert( result.size() == 1 );

	//Get the value. If we allowed the result set to be larger than size 1,
	//we would have to loop through the results, processing each as is
	//required by our application.
	XmlValue value;
	result.next(value);

	return value.asString();

}
Exemplo n.º 6
0
int MgRepository::VerifyAccess(CREFSTRING dirPath,
                               CREFSTRING fileName, bool checkVersion)
{
    int dbVersion = 0;
    STRING pathname = dirPath;
    MgFileUtil::AppendSlashToEndOfPath(pathname);
    pathname += fileName;

    // Check if the database is currently opened by any other application.
    if (!MgFileUtil::VerifySafeFileAccess(pathname))
    {
        MgStringCollection arguments;
        arguments.Add(pathname);

        throw new MgRepositoryOpenFailedException(
            L"MgRepository.VerifyAccess",
            __LINE__, __WFILE__, &arguments, L"MgRepositoryAlreadyOpened", NULL);
    }

    if (checkVersion)
    {
        // Note that this very first instance of XmlManager will eliminate
        // unnecessary XMLPlatformUtils::Initialize/Terminate calls.
        XmlManager xmlMan;

        dbVersion = xmlMan.existsContainer(MgUtil::WideCharToMultiByte(pathname));

        // Check if the database version is compatible.
        if (0 != dbVersion && MG_DBXML_CURRENT_VERSION != dbVersion)
        {
            MgStringCollection whatArguments;
            whatArguments.Add(pathname);
            MgStringCollection whyArguments;
            STRING version;
            MgUtil::Int32ToString(dbVersion, version);
            whyArguments.Add(version);
            MgUtil::Int32ToString(MG_DBXML_CURRENT_VERSION, version);
            whyArguments.Add(version);

            throw new MgRepositoryOpenFailedException(
                L"MgRepository.VerifyAccess",
                __LINE__, __WFILE__, &whatArguments, L"MgRepositoryVersionMismatch", &whyArguments);
        }
    }

    return dbVersion;
}
Exemplo n.º 7
0
string getContent(XmlManager& mgr,
		  const string& containerName,
		  const string& docName)
{
	XmlContainer cont = mgr.openContainer(containerName);
	string content;
	cont.getDocument(docName).getContent(content);
	return content;
}
Exemplo n.º 8
0
void doQuery( XmlTransaction &txn, XmlManager &db, const XmlContainer &container, const std::string &query )
{
	////////////////////////////////////////////////////////////////////////
	//////  Performs a simple query (no context) against the   ///////
	//////  provided container.                                      ///////
	////////////////////////////////////////////////////////////////////////

	///// some defensive code eliminated for clarity //

	// Perform the query. Result type is by default Result Document
	std::string fullQuery = "collection('" + container.getName() + "')" + query;
	try {
		std::cout << "Exercising query '" << fullQuery << "' " << std::endl;
		std::cout << "Return to continue: ";
		getc(stdin);

		XmlQueryContext context = db.createQueryContext();

		XmlResults results( db.query( txn, fullQuery, context) );
		XmlValue value;
		while( results.next(value) ) {
			// Obtain the value as a string and print it to stdout
			std::cout << value.asString() << std::endl;
		}

		std::cout << (unsigned int) results.size()
			<< " objects returned for expression '"
			<< fullQuery << "'\n" << std::endl;

	}
	catch(XmlException &e) {
		std::cerr << "Query " << fullQuery << " failed\n";
		std::cerr << e.what() << "\n";
		txn.abort();
		exit( -1 );
	}
	catch(std::exception &e) {
		std::cerr << "Query " << fullQuery << " failed\n";
		std::cerr << e.what() << "\n";
		txn.abort();
		exit( -1 );
	}
}
Exemplo n.º 9
0
Environment::Environment(XmlManager &db, SigBlock &sigblock)
	: sigBlock_(sigblock),
	  db_(db),
	  txn_(0),
	  context_(db.createQueryContext()),
	  uc_(db.createUpdateContext()),
	  container_(0),
	  query_(0),
	  results_(0),
	  lineNo_(0),
	  documentProjection_(true),
	  interactive_(false),
	  ignoreErrors_(false),
	  transactions_(false),
	  debugging_(false),
	  verbose_(false),
	  quit_(false),
	  shell_(0)
{
	sigBlock_.setListener(this);
}
Exemplo n.º 10
0
void getDetails( XmlTransaction &txn, XmlManager &mgr, const XmlContainer &container, const std::string &query, XmlQueryContext &context )
{
	////////////////////////////////////////////////////////////////////////
	//////  Performs an query (in context) against the         ///////
	//////  provided container.                                      ///////
	////////////////////////////////////////////////////////////////////////

	///// some defensive code eliminated for clarity //

	// Perform the query. Result type is by default Result Document
	std::string fullQuery = "collection('" + container.getName() + "')" + query;
	try {
		std::cout << "Exercising query '" << fullQuery << "' " << std::endl;
		std::cout << "Return to continue: ";
		getc(stdin);

		XmlResults results( mgr.query( txn, fullQuery, context ) );
		XmlValue value;
		std::cout << "\n\tProduct : Price : Inventory Level\n";
		while( results.next(value) ) {
			/// Retrieve the value as a document
			XmlDocument theDocument = value.asDocument();

			/// Obtain information of interest from the document. Note that the
			//  wildcard in the query expression allows us to not worry about what
			//  namespace this document uses.
			std::string item = getValue( txn, mgr, theDocument, "fn:string(/*/product)", context);
			std::string price = getValue( txn, mgr, theDocument, "fn:string(/*/inventory/price)", context);
			std::string inventory = getValue( txn, mgr, theDocument, "fn:string(/*/inventory/inventory)", context);

			std::cout << "\t" << item << " : " << price << " : " << inventory << std::endl;

		}
		std::cout << "\n";
		std::cout << (unsigned int) results.size()
			<< " objects returned for expression '"
			<< fullQuery << "'\n" << std::endl;
	}
	//Catches XmlException
	catch(std::exception &e) {
		std::cerr << "Query " << fullQuery << " failed\n";
		std::cerr << e.what() << "\n";
		txn.abort();
		exit(-1);
	}
}
Exemplo n.º 11
0
void putDocWithoutDefaultCompression(XmlManager& mgr,
				     const string& containerName,
				     XmlDocument& xdoc,
				     XmlUpdateContext& uc)
{
	// Set the container type as WholedocContainer and turn off
	// the default compression
	XmlContainerConfig contConf;
	contConf.setAllowCreate(true);
	contConf.setContainerType(XmlContainer::WholedocContainer);
	contConf.setCompressionName(XmlContainerConfig::NO_COMPRESSION);

	// Create container
	XmlContainer cont = mgr.createContainer(containerName, contConf);
	
	// Put Document
	cont.putDocument(xdoc, uc);
}
Exemplo n.º 12
0
void putDocWithDefaultCompression(XmlManager& mgr,
				  const string& containerName,
				  XmlDocument& xdoc,
				  XmlUpdateContext& uc)
{
	// Set the container type as WholedocContainer and
	// use the default compression
	XmlContainerConfig contConf;
	contConf.setAllowCreate(true);
	contConf.setContainerType(XmlContainer::WholedocContainer);

	// The following line is unnecessary because default compression
	// would take effect if user do not turn off it explicitly.
	contConf.setCompressionName(XmlContainerConfig::DEFAULT_COMPRESSION);

	// Create container
	XmlContainer cont = mgr.createContainer(containerName, contConf);

	// Put Document
	cont.putDocument(xdoc, uc);
}
Exemplo n.º 13
0
void doContextQuery( XmlTransaction &txn, XmlManager &mgr, const std::string cname,
					const std::string &query, XmlQueryContext &context )
{
	////////////////////////////////////////////////////////////////////////
	//////  Performs a simple query (with context) against the ///////
	//////  provided container.                                      ///////
	////////////////////////////////////////////////////////////////////////

	///// some defensive code eliminated for clarity //

	// Perform the query. Result type is by default Result Document
	std::string fullQuery = "collection('" + cname + "')" + query;
	try {
		std::cout << "Exercising query '" << fullQuery << "' " << std::endl;
		std::cout << "Return to continue: ";
		getc(stdin);
		std::cout << "\n";

		XmlResults results( mgr.query(txn, fullQuery, context ) );
		XmlValue value;
		while(results.next(value)) {
			// Get the document's name and print it to the console
			XmlDocument theDocument = value.asDocument();
			std::cout << "Document name: " << theDocument.getName() << std::endl;
			std::cout << value.asString() << std::endl;
		}

		std::cout << (unsigned int)results.size()
			<< " objects returned for expression '" << fullQuery
			<< "'\n" << std::endl;

	}
	//Catches XmlException
	catch(std::exception &e) {
		std::cerr << "Query " << fullQuery << " failed\n";
		std::cerr << e.what() << "\n";
		txn.abort();
		exit( -1 );
	}
}
Exemplo n.º 14
0
int main (int argc, char * argv [])
{
    using Pslrk::Core::Exception;
    using Pslrk::Core::Validator;
    using Pslrk::Core::Calculator;
    using Pslrk::Core::Representer;
    using Pslrk::Core::XmlManager;


    std::vector <std::string> codes;
    XmlManager * xmlManager {nullptr};
    Finally xmlManagerFinally ([&](){delete xmlManager;});


    auto actionHelp = []() {
        std::cout << "[Command]         [Parameters]    [Description]" << std::endl;
        std::cout << "help                              Print this message." << std::endl;
        std::cout << "push code         <string>        Put specified code into local storage." << std::endl;
        std::cout << "push family       <string>        Put family of specified code into local storage." << std::endl;
        std::cout << "show codes                        Print local storage." << std::endl;
        std::cout << "show psl                          Print PSL for each of codes from local storage." << std::endl;
        std::cout << "show family                       Print family for each of codes from local storage." << std::endl;
        std::cout << "show id                           Print ID for each of codes from local storage." << std::endl;
        std::cout << "to string         <int>           Convert each of codes from local storage into string format." << std::endl;
        std::cout << "to hex                            Convert each of codes from local storage into hex format." << std::endl;
        std::cout << "erase code        <int>           Erase code with specified index from local storage." << std::endl;
        std::cout << "clear codes                       Clear local storage." << std::endl;
        std::cout << "open base         <string>        Open XML file (whith codes)." << std::endl;
        std::cout << "close base                        Close XML file." << std::endl;
        std::cout << "save base                         Save XML file." << std::endl;
        std::cout << "show base                         Print codes which contained in XML file." << std::endl;
        std::cout << "add base                          Add code to XML file." << std::endl;
        std::cout << "remove base       <string>        Remove code from XML file." << std::endl;
        std::cout << "search base       <string>        Search code in XML file." << std::endl;
        std::cout << "quit                              Exit the program." << std::endl;
    };

    auto actionPushCode = [&](const std::string & code) {
        codes.push_back (code);
    };

    auto actionPushFamily = [&](const std::string & code) {
        for (const auto & variant : Representer::GenerateCodeFamily (code) ) {
            codes.push_back (variant);
        }
    };

    auto actionShowCodes = [&]() {
        for (const auto & code : codes) {
            std::cout << code << std::endl;
        }
    };

    auto actionShowPsl = [&]() {
        for (const auto & code : codes) {
            std::cout << Calculator::CalculatePsl (code) << std::endl;
        }
    };

    auto actionShowFamily = [&]() {
        for (const auto & code : codes) {
            for (const auto & variant : Representer::GenerateCodeFamily (code) ) {
                std::cout << code << " - " << variant << std::endl;
            }
        }
    };

    auto actionShowId = [&]() {
        for (const auto & code : codes) {
            std::cout << code << " - " << Representer::DetectCodeId (code) << std::endl;
        }
    };

    auto actionToString = [&](const size_t length = 0) {
        for (auto & code : codes) {
            if (length) {
                code = Representer::HexViewToStringView (code, length);
            }
            else {
                code = Representer::HexViewToStringView (code);
            }
        }
    };

    auto actionToHex = [&]() {
        for (auto & code : codes) {
            code = Representer::StringViewToHexView (code);
        }
    };

    auto actionEraseCode = [&](const int position) {
        if (position < codes.size () ) {
            codes.erase (codes.begin () + position);
        }
    };

    auto actionClearCodes = [&]() {
        codes.clear ();
    };

    auto actionOpenBase = [&](const std::string & fileName) {
        try {
            xmlManager = new XmlManager (fileName);
        }
        catch (Exception & e) {
            std::cout << e.what () << std::endl;
        }
    };

    auto actionCloseBase = [&]() {
        delete xmlManager;
        xmlManager = nullptr;
    };

    auto actionSaveBase = [&]() {
        if (xmlManager) {
            try {
                xmlManager->Save ();
            }
            catch (Exception & e) {
                std::cout << e.what () << std::endl;
            }
        }
        else {
            std::cout << "Attempting to save file which was not opened." << std::endl;
        }
    };

    auto actionShowBase = [&]() {
        if (xmlManager) {
            const pugi::xml_node codes = xmlManager->Select ("/").node ();
            for (const auto & code : codes.child ("codes").children ("code") ) {
                std::cout << " Code: id       = " << code.attribute ("id").value     () << std::endl <<
                             "       length   = " << code.attribute ("length").value () << std::endl <<
                             "       PSL      = " << code.attribute ("psl").value    () << std::endl <<
                             "       sequence = " << code.child_value ("sequence")      << std::endl;
                std::cout << std::endl;
            }
        }
        else {
            std::cout << "Attempting to print file which was not opened." << std::endl;
        }
    };

    auto actionAddBase = [&]() {
        if (xmlManager) {
            std::string input {""};
            std::cout << "Input code: > ";
            std::getline (std::cin, input);
            std::string stringView;
            if      (Validator::ValidateStringView (input) == Pslrk::Core::viewIsValid) {
                stringView = input;
            }
            else if (Validator::ValidateHexView    (input) == Pslrk::Core::viewIsValid) {
                stringView = Representer::HexViewToStringView (input);
            }
            else {
                std::cout << "Invalid code, stop adding!" << std::endl;
                return;
            }

            const std::string codeId {Representer::DetectCodeId (stringView)};
            const int codeLength = stringView.length ();
            const int psl {Calculator::CalculatePsl (stringView)};

            std::cout << "Sequence: " << stringView << std::endl;
            std::cout << "ID:       " << codeId     << std::endl;
            std::cout << "Length:   " << codeLength << std::endl;
            std::cout << "PSL:      " << psl        << std::endl;

            std::cout << "Input reference article: > ";
            std::getline (std::cin, input);
            const std::string referenceArticle  {input};
            std::cout << "Input reference author: > ";
            std::getline (std::cin, input);
            const std::string referenceAuthor {input};
            std::cout << "Input reference link: > ";
            std::getline (std::cin, input);
            const std::string referenceLink   {input};

            xmlManager->InsertCode (codeId, codeLength, psl, {stringView}, { {referenceArticle, referenceAuthor, referenceLink} });
        }
        else {
            std::cout << "Attempting to process file which was not opened." << std::endl;
        }
    };

    auto actionRemoveBase = [&](const std::string & id) {
        if (xmlManager) {
            try {
                xmlManager->RemoveCode (id);
            }
            catch (Exception & e) {
                std::cout << e.what () << std::endl;
            }
        }
        else {
            std::cout << "Attempting to process file which was not opened." << std::endl;
        }
    };

    auto actionSearchBase = [&](const std::string & xPathQuery) {
        if (xmlManager) {
            try {
                pugi::xml_document result;
                result.append_child () = xmlManager->Select (xPathQuery).node ();
                result.print (std::cout);
            }
            catch (Exception & e) {
                std::cout << e.what () << std::endl;
            }
        }
        else {
            std::cout << "Attempting to process file which was not opened." << std::endl;
        }
    };


    while (true) {
        std::cout << "> ";
        {
            std::string command {""};
            std::getline (std::cin, command);

            if      (0 == command.find ("help") ) {
                actionHelp ();
            }
            else if (0 == command.find ("push code ") ) {
                actionPushCode (command.substr (std::string ("push code ").length () ) );
            }
            else if (0 == command.find ("push family ") ) {
                actionPushFamily (command.substr (std::string ("push family ").length () ) );
            }
            else if (0 == command.find ("show codes") ) {
                actionShowCodes ();
            }
            else if (0 == command.find ("show psl") ) {
                actionShowPsl ();
            }
            else if (0 == command.find ("show family") ) {
                actionShowFamily ();
            }
            else if (0 == command.find ("show id") ) {
                actionShowId ();
            }
            else if (0 == command.find ("to string") ) {
                if (command.length () > std::string ("to string ").length () ) {
                    actionToString (boost::lexical_cast <int> (command.substr (std::string ("to string ").length () ) ) );
                }
                else {
                    actionToString ();
                }
            }
            else if (0 == command.find ("to hex") ) {
                actionToHex ();
            }
            else if (0 == command.find ("quit") ) {
                return EXIT_SUCCESS;
            }
            else if (0 == command.find ("erase code ") ) {
                actionEraseCode (boost::lexical_cast <int> (command.substr (std::string ("erase code ").length () ) ) );
            }
            else if (0 == command.find ("clear codes") ) {
                actionClearCodes ();
            }
            else if (0 == command.find ("open base") ) {
                actionOpenBase (command.substr (std::string ("open base ").length () ) );
            }
            else if (0 == command.find ("close base") ) {
                actionCloseBase ();
            }
            else if (0 == command.find ("save base") ) {
                actionSaveBase ();
            }
            else if (0 == command.find ("show base") ) {
                actionShowBase ();
            }
            else if (0 == command.find ("add base") ) {
                actionAddBase ();
            }
            else if (0 == command.find ("remove base") ) {
                actionRemoveBase (command.substr (std::string ("remove base ").length () ) );
            }
            else if (0 == command.find ("search base") ) {
                actionSearchBase (command.substr (std::string ("search base ").length () ) );
            }
            else {
                std::cout << "Unrecognized command: " << command << std::endl;
            }
        }
    }


    return EXIT_SUCCESS;
}
Exemplo n.º 15
0
int
main(int argc, char *const* argv)
{
	const char *progname = "dbxml_dump";
	DB_ENV *dbenv;
	XmlManager *xmlDb;
	u_int32_t cache;
	int ch, exitval, is_private, keyflag, nflag, ret, Rflag, rflag;
	char *home, *passwd;

	if ((ret = version_check(progname)) != 0)
		return (ret);

	dbenv = NULL;
	xmlDb = NULL;
	exitval = nflag = rflag = Rflag = 0;
	keyflag = 0;
	cache = MEGABYTE;
	is_private = 0;
	home = passwd = NULL;

	while ((ch = getopt(argc, argv, "f:h:NP:rRV")) != EOF)
		switch (ch) {
		case 'f':
			if (freopen(optarg, "wb", stdout) == NULL) {
				fprintf(stderr, "%s: %s: reopen: %s\n",
					progname, optarg, strerror(errno));
				return (EXIT_FAILURE);
			}
			break;
		case 'h':
			home = optarg;
			break;
		case 'N':
			nflag = 1;
			break;
		case 'P':
			passwd = strdup(optarg);
			memset(optarg, 0, strlen(optarg));
			if (passwd == NULL) {
				fprintf(stderr, "%s: strdup: %s\n",
					progname, strerror(errno));
				return (EXIT_FAILURE);
			}
			break;
		case 'R':
			Rflag = 1;
			/* DB_AGGRESSIVE requires DB_SALVAGE */
			/* FALLTHROUGH */
		case 'r':
			rflag = 1;
			break;
		case 'V':
			printf("%s\n", DbXml::dbxml_version(NULL, NULL, NULL));
			printf("%s\n", db_version(NULL, NULL, NULL));
			return (EXIT_SUCCESS);
		case '?':
		default:
			return (usage());
		}
	argc -= optind;
	argv += optind;

	if (argc != 1)
		return (usage());

	/* Handle possible interruptions. */
	SigBlock sb;

	/*
	 * Create an environment object and initialize it for error
	 * reporting.
	 */
	if ((ret = db_env_create(&dbenv, 0)) != 0) {
		fprintf(stderr,
			"%s: db_env_create: %s\n", progname, db_strerror(ret));
		goto err;
	}

	dbenv->set_errfile(dbenv, stderr);
	dbenv->set_errpfx(dbenv, progname);
	if (nflag) {
		if ((ret = dbenv->set_flags(dbenv, DB_NOLOCKING, 1)) != 0) {
			dbenv->err(dbenv, ret, "set_flags: DB_NOLOCKING");
			goto err;
		}
		if ((ret = dbenv->set_flags(dbenv, DB_NOPANIC, 1)) != 0) {
			dbenv->err(dbenv, ret, "set_flags: DB_NOPANIC");
			goto err;
		}
	}
	if (passwd != NULL && (ret = dbenv->set_encrypt(dbenv,
				     passwd, DB_ENCRYPT_AES)) != 0) {
		dbenv->err(dbenv, ret, "set_passwd");
		goto err;
	}

	/* Initialize the environment. */
	if ((ret = db_init(dbenv, home, rflag, cache, &is_private)) != 0) {
		dbenv->err(dbenv, ret, "db_init");
		goto err;
	}

	xmlDb = new XmlManager(dbenv);
	
	if (rflag) {
		try {
			xmlDb->verifyContainer(argv[0], &cout, DB_SALVAGE | (Rflag ? DB_AGGRESSIVE : 0));
		} catch (XmlException &e) {
			dbenv->errx(dbenv, "verify %s: %s", argv[0], e.what());
			goto err;
		}
		goto done;
	}
	
	try {
		xmlDb->dumpContainer(argv[0], &cout);
	} catch (XmlException &e) {
		dbenv->errx(dbenv, "dump %s: %s", argv[0], e.what());
		goto err;
	}
	
	if (0) {
	err:
		exitval = 1;
	}
done:
	if (xmlDb)
		delete xmlDb;
		
	if ((ret = dbenv->close(dbenv, 0)) != 0) {
		exitval = 1;
		fprintf(stderr,
			"%s: dbenv->close: %s\n", progname, db_strerror(ret));
	}
	
	return (exitval == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
Exemplo n.º 16
0
int main(int argc, char **argv)
{
	string containerName1 = "compressionContainer1.dbxml";
	string containerName2 = "compressionContainer2.dbxml";
	string containerName3 = "compressionContainer3.dbxml";
	string docName = "doc1.xml";
	string content = "<root><a></a></root>";
	try{

	// Create manager and update context. It's good to reuse update context.
	XmlManager mgr;
	XmlUpdateContext uc = mgr.createUpdateContext();

	// Remove the existing container if any
	if( mgr.existsContainer(containerName1) )
		mgr.removeContainer(containerName1);
	if( mgr.existsContainer(containerName2) )
		mgr.removeContainer(containerName2);
	if( mgr.existsContainer(containerName3) )
		mgr.removeContainer(containerName3);

	// Create document and put it into the container without compression.
	XmlDocument xdoc1 = mgr.createDocument();
	xdoc1.setName(docName);
	xdoc1.setContent(content);
	putDocWithoutDefaultCompression(mgr, containerName1, xdoc1, uc);

	// Verify Content
	cout << "Content of the document: "
	     << getContent(mgr, containerName1, xdoc1.getName())
	     << endl;

	// Create document and put it into the container with default compression.
	XmlDocument xdoc2 = mgr.createDocument();
	xdoc2.setName(docName);
	xdoc2.setContent(content);
	putDocWithDefaultCompression(mgr, containerName2, xdoc2, uc);

	// Verify Content
	cout << "Content of the document: "
	     << getContent(mgr, containerName2, xdoc2.getName())
	     << endl;

	// Create an instance of custom compression
	MyCompression myCompression;

	// Create document and put it into the container with custom compression.
	XmlDocument xdoc3 = mgr.createDocument();
	xdoc3.setName(docName);
	xdoc3.setContent(content);
	putDocWithMyCompression(mgr, containerName3, xdoc3, uc, myCompression);

	// Verify Content
	cout << "Content of the document: "
	     << getContent(mgr, containerName3, xdoc3.getName())
	     << endl;

	} catch (XmlException &xe) {
		cout << "XmlException: " << xe.what() << endl;
		return 1;
	}
	return 0;
}