added title field in saved playlist

fixed (kind of; I still don't understand them) some problems arising from
    StorageException -> XmlRpcException change
This commit is contained in:
fgerlits 2005-01-10 10:36:56 +00:00
parent 9a185bb141
commit 67910f4fcf
4 changed files with 67 additions and 34 deletions

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.22 $ Version : $Revision: 1.23 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/Playlist.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/Playlist.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -61,6 +61,11 @@ static const std::string idAttrName = "id";
*/ */
static const std::string playlengthAttrName = "playlength"; static const std::string playlengthAttrName = "playlength";
/**
* The name of the attribute to get the title of the playlist.
*/
static const std::string titleAttrName = "title";
/** /**
* The name of playlist element child nodes. * The name of playlist element child nodes.
*/ */
@ -102,6 +107,13 @@ Playlist :: configure(const xmlpp::Element & element)
playlength.reset(new time_duration( playlength.reset(new time_duration(
duration_from_string(attribute->get_value()))); duration_from_string(attribute->get_value())));
if ((attribute = element.get_attribute(titleAttrName))) {
title.reset(new const Glib::ustring(attribute->get_value()));
}
else {
title.reset(new const Glib::ustring(""));
}
xmlpp::Node::NodeList childNodes xmlpp::Node::NodeList childNodes
= element.get_children(elementListAttrName); = element.get_children(elementListAttrName);
xmlpp::Node::NodeList::iterator it = childNodes.begin(); xmlpp::Node::NodeList::iterator it = childNodes.begin();
@ -365,7 +377,7 @@ Ptr<Glib::ustring>::Ref
Playlist :: getMetadata(const string &key, const string &ns) const Playlist :: getMetadata(const string &key, const string &ns) const
throw () throw ()
{ {
std::string completeKey = key + ns; std::string completeKey = ns + ":" + key;
metadataType::const_iterator it = metadata.find(completeKey); metadataType::const_iterator it = metadata.find(completeKey);
if (it != metadata.end()) { if (it != metadata.end()) {
@ -387,10 +399,19 @@ Playlist :: setMetadata(Ptr<const Glib::ustring>::Ref value,
const string &key, const string &ns) const string &key, const string &ns)
throw () throw ()
{ {
std::string completeKey = key + ns; std::string completeKey = ns + ":" + key;
metadata[completeKey] = value; metadata[completeKey] = value;
if (completeKey == "dcterms:extent") {
playlength.reset(new time_duration(duration_from_string(*value)));
}
if (completeKey == "dc:title") {
title = value;
}
} }
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Return a string containing the essential fields of this object, in XML. * Return a string containing the essential fields of this object, in XML.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
@ -402,11 +423,14 @@ Playlist :: getXmlString(void) throw ()
xmlString->append("<"); xmlString->append("<");
xmlString->append(configElementNameStr + " "); xmlString->append(configElementNameStr + " ");
xmlString->append(idAttrName + "=\"" xmlString->append(idAttrName + "=\""
+ std::string(*id) + std::string(*getId())
+ "\" "); + "\" ");
xmlString->append(playlengthAttrName + "=\"" xmlString->append(playlengthAttrName + "=\""
+ to_simple_string(*playlength) + to_simple_string(*getPlaylength())
+ "\">\n"); + "\" ");
xmlString->append(Glib::ustring(titleAttrName) + "=\""
+ *getTitle()
+ "\">\n");
PlaylistElementListType::const_iterator it = elementList->begin(); PlaylistElementListType::const_iterator it = elementList->begin();
while (it != elementList->end()) { while (it != elementList->end()) {

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.18 $ Version : $Revision: 1.19 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -114,9 +114,8 @@ PlaylistTest :: firstTest(void)
CPPUNIT_ASSERT(duration->total_seconds() == 34); CPPUNIT_ASSERT(duration->total_seconds() == 34);
CPPUNIT_ASSERT(playlist->valid()); CPPUNIT_ASSERT(playlist->valid());
CPPUNIT_ASSERT(*playlist->getXmlString() == CPPUNIT_ASSERT(*playlist->getXmlString() ==
"<playlist id=\"0000000000000001\" playlength=\"00:00:34\">\n" "<playlist id=\"0000000000000001\" playlength=\"00:00:34\" title=\"\">\n"
"<playlistElement id=\"0000000000000101\" relativeOffset=\"00:00:00\">\n" "<playlistElement id=\"0000000000000101\" relativeOffset=\"00:00:00\">\n"
"<audioClip id=\"0000000000010001\" playlength=\"00:00:11\" title=\"one\"/>\n" "<audioClip id=\"0000000000010001\" playlength=\"00:00:11\" title=\"one\"/>\n"
"</playlistElement>\n" "</playlistElement>\n"
@ -126,7 +125,7 @@ PlaylistTest :: firstTest(void)
"fadeOut=\"00:00:01.500000\"/>\n" "fadeOut=\"00:00:01.500000\"/>\n"
"</playlistElement>\n" "</playlistElement>\n"
"<playlistElement id=\"0000000000000103\" relativeOffset=\"00:00:23\">\n" "<playlistElement id=\"0000000000000103\" relativeOffset=\"00:00:23\">\n"
"<playlist id=\"0000000000000002\" playlength=\"00:00:11\">\n" "<playlist id=\"0000000000000002\" playlength=\"00:00:11\" title=\"\">\n"
"<playlistElement id=\"0000000000000111\" relativeOffset=\"00:00:00\">\n" "<playlistElement id=\"0000000000000111\" relativeOffset=\"00:00:00\">\n"
"<audioClip id=\"0000000000010003\" playlength=\"00:00:11\" title=\"three\"/>\n" "<audioClip id=\"0000000000010003\" playlength=\"00:00:11\" title=\"three\"/>\n"
"</playlistElement>\n" "</playlistElement>\n"

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $ Author : $Author: fgerlits $
Version : $Revision: 1.21 $ Version : $Revision: 1.22 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -650,7 +650,7 @@ WebStorageClient :: configure(const xmlpp::Element & element)
const bool const bool
WebStorageClient :: existsPlaylist(Ptr<SessionId>::Ref sessionId, WebStorageClient :: existsPlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id) const Ptr<UniqueId>::Ref id) const
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
XmlRpcValue parameters; XmlRpcValue parameters;
XmlRpcValue result; XmlRpcValue result;
@ -703,7 +703,7 @@ WebStorageClient :: existsPlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<Playlist>::Ref Ptr<Playlist>::Ref
WebStorageClient :: getPlaylist(Ptr<SessionId>::Ref sessionId, WebStorageClient :: getPlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id) const Ptr<UniqueId>::Ref id) const
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
XmlRpcValue parameters; XmlRpcValue parameters;
XmlRpcValue result; XmlRpcValue result;
@ -815,7 +815,7 @@ WebStorageClient :: getPlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<Playlist>::Ref Ptr<Playlist>::Ref
WebStorageClient :: editPlaylist(Ptr<SessionId>::Ref sessionId, WebStorageClient :: editPlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id) const Ptr<UniqueId>::Ref id) const
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
Ptr<Playlist>::Ref playlist(new Playlist(id)); Ptr<Playlist>::Ref playlist(new Playlist(id));
Ptr<const std::string>::Ref url, token; Ptr<const std::string>::Ref url, token;
@ -849,7 +849,7 @@ WebStorageClient :: editPlaylistGetUrl(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id, Ptr<UniqueId>::Ref id,
Ptr<const std::string>::Ref& url, Ptr<const std::string>::Ref& url,
Ptr<const std::string>::Ref& token) const Ptr<const std::string>::Ref& token) const
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
XmlRpcValue parameters; XmlRpcValue parameters;
XmlRpcValue result; XmlRpcValue result;
@ -906,7 +906,7 @@ WebStorageClient :: editPlaylistGetUrl(Ptr<SessionId>::Ref sessionId,
void void
WebStorageClient :: savePlaylist(Ptr<SessionId>::Ref sessionId, WebStorageClient :: savePlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<Playlist>::Ref playlist) const Ptr<Playlist>::Ref playlist) const
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
if (!playlist || !playlist->getToken()) { if (!playlist || !playlist->getToken()) {
throw XmlRpcInvalidArgumentException("playlist has no token field"); throw XmlRpcInvalidArgumentException("playlist has no token field");
@ -974,7 +974,7 @@ WebStorageClient :: savePlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<Playlist>::Ref Ptr<Playlist>::Ref
WebStorageClient :: acquirePlaylist(Ptr<SessionId>::Ref sessionId, WebStorageClient :: acquirePlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id) const Ptr<UniqueId>::Ref id) const
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
Ptr<Playlist>::Ref oldPlaylist = getPlaylist(sessionId, id); Ptr<Playlist>::Ref oldPlaylist = getPlaylist(sessionId, id);
@ -1058,7 +1058,7 @@ WebStorageClient :: acquirePlaylist(Ptr<SessionId>::Ref sessionId,
void void
WebStorageClient :: releasePlaylist(Ptr<SessionId>::Ref sessionId, WebStorageClient :: releasePlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<Playlist>::Ref playlist) const Ptr<Playlist>::Ref playlist) const
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
if (! playlist->getUri()) { if (! playlist->getUri()) {
throw XmlRpcInvalidArgumentException("playlist URI not found"); throw XmlRpcInvalidArgumentException("playlist URI not found");
@ -1118,7 +1118,7 @@ WebStorageClient :: releasePlaylist(Ptr<SessionId>::Ref sessionId,
void void
WebStorageClient :: deletePlaylist(Ptr<SessionId>::Ref sessionId, WebStorageClient :: deletePlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id) Ptr<UniqueId>::Ref id)
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
XmlRpcValue parameters; XmlRpcValue parameters;
XmlRpcValue result; XmlRpcValue result;
@ -1176,7 +1176,7 @@ WebStorageClient :: deletePlaylist(Ptr<SessionId>::Ref sessionId,
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
Ptr<std::vector<Ptr<Playlist>::Ref> >::Ref Ptr<std::vector<Ptr<Playlist>::Ref> >::Ref
WebStorageClient :: getAllPlaylists(Ptr<SessionId>::Ref sessionId) const WebStorageClient :: getAllPlaylists(Ptr<SessionId>::Ref sessionId) const
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
Ptr<std::vector<Ptr<Playlist>::Ref> >::Ref playlistVector( Ptr<std::vector<Ptr<Playlist>::Ref> >::Ref playlistVector(
new std::vector<Ptr<Playlist>::Ref>); new std::vector<Ptr<Playlist>::Ref>);
@ -1189,7 +1189,7 @@ WebStorageClient :: getAllPlaylists(Ptr<SessionId>::Ref sessionId) const
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
Ptr<Playlist>::Ref Ptr<Playlist>::Ref
WebStorageClient :: createPlaylist(Ptr<SessionId>::Ref sessionId) WebStorageClient :: createPlaylist(Ptr<SessionId>::Ref sessionId)
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
XmlRpcValue parameters; XmlRpcValue parameters;
XmlRpcValue result; XmlRpcValue result;
@ -1258,7 +1258,7 @@ WebStorageClient :: createPlaylist(Ptr<SessionId>::Ref sessionId)
const bool const bool
WebStorageClient :: existsAudioClip(Ptr<SessionId>::Ref sessionId, WebStorageClient :: existsAudioClip(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id) const Ptr<UniqueId>::Ref id) const
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
XmlRpcValue parameters; XmlRpcValue parameters;
XmlRpcValue result; XmlRpcValue result;
@ -1311,7 +1311,7 @@ WebStorageClient :: existsAudioClip(Ptr<SessionId>::Ref sessionId,
Ptr<AudioClip>::Ref Ptr<AudioClip>::Ref
WebStorageClient :: getAudioClip(Ptr<SessionId>::Ref sessionId, WebStorageClient :: getAudioClip(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id) const Ptr<UniqueId>::Ref id) const
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
XmlRpcValue parameters; XmlRpcValue parameters;
XmlRpcValue result; XmlRpcValue result;
@ -1425,7 +1425,7 @@ WebStorageClient :: getAudioClip(Ptr<SessionId>::Ref sessionId,
void void
WebStorageClient :: storeAudioClip(Ptr<SessionId>::Ref sessionId, WebStorageClient :: storeAudioClip(Ptr<SessionId>::Ref sessionId,
Ptr<AudioClip>::Ref audioClip) Ptr<AudioClip>::Ref audioClip)
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
if (!audioClip || !audioClip->getUri()) { if (!audioClip || !audioClip->getUri()) {
throw XmlRpcInvalidArgumentException( throw XmlRpcInvalidArgumentException(
@ -1586,7 +1586,7 @@ WebStorageClient :: storeAudioClip(Ptr<SessionId>::Ref sessionId,
Ptr<AudioClip>::Ref Ptr<AudioClip>::Ref
WebStorageClient :: acquireAudioClip(Ptr<SessionId>::Ref sessionId, WebStorageClient :: acquireAudioClip(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id) const Ptr<UniqueId>::Ref id) const
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
Ptr<AudioClip>::Ref audioClip = getAudioClip(sessionId, id); Ptr<AudioClip>::Ref audioClip = getAudioClip(sessionId, id);
@ -1652,7 +1652,7 @@ WebStorageClient :: acquireAudioClip(Ptr<SessionId>::Ref sessionId,
void void
WebStorageClient :: releaseAudioClip(Ptr<SessionId>::Ref sessionId, WebStorageClient :: releaseAudioClip(Ptr<SessionId>::Ref sessionId,
Ptr<AudioClip>::Ref audioClip) const Ptr<AudioClip>::Ref audioClip) const
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
XmlRpcValue parameters; XmlRpcValue parameters;
XmlRpcValue result; XmlRpcValue result;
@ -1715,7 +1715,7 @@ WebStorageClient :: releaseAudioClip(Ptr<SessionId>::Ref sessionId,
void void
WebStorageClient :: deleteAudioClip(Ptr<SessionId>::Ref sessionId, WebStorageClient :: deleteAudioClip(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id) Ptr<UniqueId>::Ref id)
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
XmlRpcValue parameters; XmlRpcValue parameters;
XmlRpcValue result; XmlRpcValue result;
@ -1774,7 +1774,7 @@ WebStorageClient :: deleteAudioClip(Ptr<SessionId>::Ref sessionId,
Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref
WebStorageClient :: getAllAudioClips(Ptr<SessionId>::Ref sessionId) WebStorageClient :: getAllAudioClips(Ptr<SessionId>::Ref sessionId)
const const
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref audioClipVector( Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref audioClipVector(
new std::vector<Ptr<AudioClip>::Ref>); new std::vector<Ptr<AudioClip>::Ref>);
@ -1787,7 +1787,7 @@ WebStorageClient :: getAllAudioClips(Ptr<SessionId>::Ref sessionId)
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
Ptr<std::vector<Ptr<UniqueId>::Ref> >::Ref Ptr<std::vector<Ptr<UniqueId>::Ref> >::Ref
WebStorageClient :: reset(void) WebStorageClient :: reset(void)
throw (XmlRpcException) throw (Core::XmlRpcException)
{ {
XmlRpcValue parameters; XmlRpcValue parameters;
XmlRpcValue result; XmlRpcValue result;

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $ Author : $Author: fgerlits $
Version : $Revision: 1.24 $ Version : $Revision: 1.25 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -47,6 +47,13 @@
#include "WebStorageClient.h" #include "WebStorageClient.h"
#include "LiveSupport/Core/SessionId.h" #include "LiveSupport/Core/SessionId.h"
#include "LiveSupport/Core/XmlRpcException.h"
#include "LiveSupport/Core/XmlRpcCommunicationException.h"
#include "LiveSupport/Core/XmlRpcMethodFaultException.h"
#include "LiveSupport/Core/XmlRpcMethodResponseException.h"
#include "LiveSupport/Core/XmlRpcInvalidArgumentException.h"
#include "LiveSupport/Core/XmlRpcIOException.h"
#include "WebStorageClientTest.h" #include "WebStorageClientTest.h"
using namespace std; using namespace std;
@ -243,7 +250,7 @@ WebStorageClientTest :: playlistTest(void)
playlist = wsc->editPlaylist(sessionId, playlistIdxx); playlist = wsc->editPlaylist(sessionId, playlistIdxx);
CPPUNIT_FAIL("allowed to open playlist for editing twice"); CPPUNIT_FAIL("allowed to open playlist for editing twice");
} }
catch (XmlRpcMethodFaultException &e) { catch (Core::XmlRpcMethodFaultException &e) {
} }
catch (XmlRpcException &e) { catch (XmlRpcException &e) {
std::string eMsg = "editPlaylist() threw unexpected exception:\n"; std::string eMsg = "editPlaylist() threw unexpected exception:\n";
@ -582,13 +589,16 @@ WebStorageClientTest :: simplePlaylistTest(void)
CPPUNIT_ASSERT(newPlaylist->getTitle().get()); CPPUNIT_ASSERT(newPlaylist->getTitle().get());
CPPUNIT_ASSERT(*newPlaylist->getTitle() == *title); CPPUNIT_ASSERT(*newPlaylist->getTitle() == *title);
/*
// this is not needed here
// releasePlaylist() is the closing pair of acquirePlaylist()
try { try {
wsc->releasePlaylist(sessionId, newPlaylist); wsc->releasePlaylist(sessionId, newPlaylist);
} catch (XmlRpcException &e) { } catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what()); CPPUNIT_FAIL(e.what());
} }
CPPUNIT_ASSERT(!newPlaylist->getUri()); CPPUNIT_ASSERT(!newPlaylist->getUri());
*/
} }