Example #1
0
BdRetVal bdbXMLInterface::delete_doc(container_index container_type, const string &doc_name)
{
	XmlContainer* container = NULL;
	if (m_manager == NULL)
	{
		throw XmlException(XmlException::NULL_POINTER, "n_manager NULL", __FILE__, __LINE__);
	}

	container = &m_containers[container_type];

	if (container == NULL)
	{
		throw XmlException(XmlException::NULL_POINTER, "container NULL", __FILE__, __LINE__);
	}

	XmlUpdateContext the_context = m_manager->createUpdateContext();
	try{
		XmlDocument the_doc = container->getDocument(doc_name);

		container->deleteDocument(the_doc, the_context);
	}
	catch (XmlException &xe)
	{
		throw xe;
	}

	return no_error;
}
Example #2
0
BdRetVal bdbXMLInterface::create_doc(container_index container_type, 
		const string &doc_name, 
		const string &root,
		vector<string>* attr_list,
		int flag)
{
	if (m_manager == NULL)
	{
		throw XmlException(XmlException::NULL_POINTER, "m_manager", __FILE__, __LINE__);
	}

	XmlContainer* container = NULL;
	container = &m_containers[container_type];
	XmlUpdateContext the_context = m_manager->createUpdateContext();

	try
	{
		XmlDocument the_doc = container->getDocument(doc_name);
		if ((flag & DELET_EXIST) != DELET_EXIST)
		{
			throw XmlException(XmlException::NULL_POINTER, "xml document exists", __FILE__, __LINE__);
			return xml_exception;
		}
		else
		{
			container->deleteDocument(the_doc, the_context);
		}
	}
	catch (XmlException &e)
	{
		if (e.getExceptionCode() != XmlException::DOCUMENT_NOT_FOUND)
		{
			debugOut() << "xml excepiton" << e.what() << endl;
			throw XmlException(XmlException::NULL_POINTER, "xml document get error", __FILE__, __LINE__);
		}
	}

	//创建一个新的document
	string content = "<?xml version=\"1.0\"?>";
	content += "\n<" + root + ">"; 
	if (attr_list != NULL)
	{
		for (int i=0; i < attr_list->size(); i++)
		{
			content += "\n";
			content += (*attr_list)[i];
		}
	}

	content += "\n</" + root + ">";
	try
	{
		container->putDocument(doc_name, content, the_context, 0);
	}
	catch (XmlException &e)
	{
		debugOut() << "xml exception: " << e.what() << endl;
		throw XmlException(XmlException::NULL_POINTER, "xml document put content error", __FILE__, __LINE__);
	}
}
Example #3
0
BdRetVal bdbXMLInterface::put_stringtodoc(container_index container_type, const char* content, const string& doc_name)
{
	if (m_manager == NULL)
	{
		throw XmlException(XmlException::NULL_POINTER, "m_manager", __FILE__, __LINE__);
	}

	XmlContainer* container = NULL;
	container = &m_containers[container_type];
	XmlUpdateContext the_context = m_manager->createUpdateContext();

	try
	{
		XmlDocument the_doc = container->getDocument(doc_name);
		container->deleteDocument(the_doc, the_context);
	}
	catch (XmlException &e)
	{
		if (e.getExceptionCode() != XmlException::DOCUMENT_NOT_FOUND)
		{
			debugOut() << "xml excepiton" << e.what() << endl;
			throw XmlException(XmlException::NULL_POINTER, "xml document get error", __FILE__, __LINE__);
		}
	}

	try
	{
		container->putDocument(doc_name, content, the_context, 0);
	}
	catch (XmlException &e)
	{
		debugOut() << "xml exception: " << e.what() << endl;
		throw XmlException(XmlException::NULL_POINTER, "xml document put content error", __FILE__, __LINE__);
	}
}
Example #4
0
/** 
 * @breif  
 * 		Put a file to dbxml database, if there already
 * 		had the file in db, check the time stamp to decide if
 * 		update needed.
 * 
 * @Param pathname
 * 		the path of the file
 * @Param docname
 * 		The doc name in the dbxml database
 * 
 * @Returns   
 * 	return no_error for success
 * 	otherwise an XmlException was throwed
 */
BdRetVal bdbXMLInterface::add_files(const string& pathname, const string& docname)
{
	XmlContainer* container = NULL;
	if (m_manager == NULL)
	{
		throw XmlException(XmlException::NULL_POINTER, "n_manager NULL", __FILE__, __LINE__);
	}

	debugOut() << "try file: " << pathname << endl;

	QString q_pathname(pathname.c_str());
	for (int i = 0; i < CONT_IDX_NUM; i ++)
	{
		QString q_cont_name("database/");
		q_cont_name += (container_names[i].c_str());
		q_cont_name += "/";
		if (q_pathname.contains(q_cont_name, Qt::CaseInsensitive))
		{
			container = &m_containers[i];
		}
	}

	if (container == NULL)
	{
		throw XmlException(XmlException::NULL_POINTER, "container NULL", __FILE__, __LINE__);
	}

	XmlUpdateContext the_context = m_manager->createUpdateContext();
	try{
		XmlDocument the_doc = container->getDocument(docname);

		//
		container->deleteDocument(the_doc, the_context);

	}
	catch (XmlException &e)
	{
//                debugOut() << "open document xml exception: " << e.what() << " file name: " << docname << endl;
		if (e.getExceptionCode() != XmlException::DOCUMENT_NOT_FOUND)
		{
				throw e;
		}
	}

	debugOut() << "putting file: " << pathname << " to container " << container->getName() <<
			" as doc " << docname << endl;
	try
	{
			XmlInputStream *the_stream =
					m_manager->createLocalFileInputStream(pathname);
			container->putDocument(docname,
							the_stream,
							the_context,
							0);
	}
	catch (XmlException &e)
	{
			debugOut() << "xml exception: " << e.what() << endl;
			throw e;
	}

	return no_error;
}