You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by Wouter de Vaal <wo...@hotmail.com> on 2004/08/27 15:45:46 UTC

Re: Renaming a collection

> Is it possible to rename a collection that already exists and is filled
> with data ?
>
No. The trick we used in our project is to put a presentable name of the
collection in MetaData
and then let the collection real name be a generated unique one.

Regards,
Wouter

Re: Renaming a collection

Posted by Wouter de Vaal <wo...@hotmail.com>.
----- Original Message ----- 
From: "Wouter de Vaal" <wo...@hotmail.com>
To: <xi...@xml.apache.org>
Sent: Monday, August 30, 2004 2:28 PM
Subject: Re: Renaming a collection


> > >>So according to what I understand, it would be possible to change the
> > >>presentable name of the collection by changing it in the metadata ?
> > >>Since the name used to access the collection is the one stored in the
> > >>metadata, I want to change this one.
> > >>If it is indeed possible, would you mind showing me a piece of code
that
> > >>does it ?
> > >>
> > >>Thanks, that would really help out here !!
> > >>
> > >>
> > >>
> > >>
> > >>
> > >this is basically all you need to do:
> > >
> > >            //get name:
> > >            CollectionImpl xindiceCol =
> > >(CollectionImpl)DatabaseManager.getCollection(collectionURI, username,
> > >password);
> > >
> > >            MetaData metaData = xindiceCol.getMetaData(resource);
> > >            String name = metaData.getAttribute("REALNAME");
> > >
> > >            //change name:
> > >            name = "foo";
> > >            metaData.setType(MetaData.COLLECTION);
> > >            metaData.setAttribute("REALNAME", name);
> > >
> > >
> > >            xindiceCol.setMetaData(resource, metaData);
> > >
> > >
> > >
> > >
> > I tried that but can't make it work, and here's why :
> >
> > The collection I want to change the name of, is right under the /db
> > collection (its name is HausseTarifaire2004).
> > When I try to perform a :
> >
> >
(CollectionImpl)DatabaseManager.getCollection("xmldb:xindice://myUrl/db",
> > username,password)
> >     MetaData metaData = xindiceCol.getMetaData('HausseTarifaire2004');
> >
> > I get the following exception :
> >
> >     org.xmldb.api.base.XMLDBException:
> > org.xmldb.api.base.XMLDBException: :This Collection 'db' cannot store
> > Documents
> >
> > When I use "HausseTarifaire2004" as current collection , I don't know
> > how to access its metadata (since you must put the resource name as
> > parameter of the getMetaData method call).
> >
> > It seems (according to the javadocs) that metadata are accessible for
> > resources (XML files) but not (or at least not easily) for collections.
> >
> > Any idea here ?
> >
> >
> Ok I pasted some generic code of us that gets and sets meta data on both
> resources and collections,
> so I guess that's not entirely clear.
>
> You should use:
> MetaData metaData = xindiceCol.getMetaData(null);
>
> instead of
>
> MetaData metaData = xindiceCol.getMetaData('HausseTarifaire2004');
>
> and vice versa for setting metadata.
>
> xindiceCol.setMetaData(null, metaData);
>
> Wouter
>
In addition set the collection in the collection url:

CollectionImpl xindiceCol =
(CollectionImpl)DatabaseManager.getCollection("xmldb:xindice://myUrl/db/Haus
seTarifaire2004",username,password)


Re: Renaming a collection

Posted by Wouter de Vaal <wo...@hotmail.com>.
> >>So according to what I understand, it would be possible to change the
> >>presentable name of the collection by changing it in the metadata ?
> >>Since the name used to access the collection is the one stored in the
> >>metadata, I want to change this one.
> >>If it is indeed possible, would you mind showing me a piece of code that
> >>does it ?
> >>
> >>Thanks, that would really help out here !!
> >>
> >>
> >>
> >>
> >>
> >this is basically all you need to do:
> >
> >            //get name:
> >            CollectionImpl xindiceCol =
> >(CollectionImpl)DatabaseManager.getCollection(collectionURI, username,
> >password);
> >
> >            MetaData metaData = xindiceCol.getMetaData(resource);
> >            String name = metaData.getAttribute("REALNAME");
> >
> >            //change name:
> >            name = "foo";
> >            metaData.setType(MetaData.COLLECTION);
> >            metaData.setAttribute("REALNAME", name);
> >
> >
> >            xindiceCol.setMetaData(resource, metaData);
> >
> >
> >
> >
> I tried that but can't make it work, and here's why :
>
> The collection I want to change the name of, is right under the /db
> collection (its name is HausseTarifaire2004).
> When I try to perform a :
>
> (CollectionImpl)DatabaseManager.getCollection("xmldb:xindice://myUrl/db",
> username,password)
>     MetaData metaData = xindiceCol.getMetaData('HausseTarifaire2004');
>
> I get the following exception :
>
>     org.xmldb.api.base.XMLDBException:
> org.xmldb.api.base.XMLDBException: :This Collection 'db' cannot store
> Documents
>
> When I use "HausseTarifaire2004" as current collection , I don't know
> how to access its metadata (since you must put the resource name as
> parameter of the getMetaData method call).
>
> It seems (according to the javadocs) that metadata are accessible for
> resources (XML files) but not (or at least not easily) for collections.
>
> Any idea here ?
>
>
Ok I pasted some generic code of us that gets and sets meta data on both
resources and collections,
so I guess that's not entirely clear.

You should use:
MetaData metaData = xindiceCol.getMetaData(null);

instead of

MetaData metaData = xindiceCol.getMetaData('HausseTarifaire2004');

and vice versa for setting metadata.

xindiceCol.setMetaData(null, metaData);

Wouter

Re: Renaming a collection

Posted by Alexander DEJANOVSKI <al...@laposte.net>.
Wouter de Vaal wrote:

>----- Original Message ----- 
>From: "Alexander DEJANOVSKI" <al...@laposte.net>
>To: <xi...@xml.apache.org>
>Sent: Friday, August 27, 2004 5:09 PM
>Subject: Re: Renaming a collection
>
>
>  
>
>>Wouter de Vaal wrote:
>>
>>    
>>
>>>>Is it possible to rename a collection that already exists and is filled
>>>>with data ?
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>No. The trick we used in our project is to put a presentable name of the
>>>collection in MetaData
>>>and then let the collection real name be a generated unique one.
>>>
>>>Regards,
>>>Wouter
>>>
>>>
>>>
>>>      
>>>
>>So according to what I understand, it would be possible to change the
>>presentable name of the collection by changing it in the metadata ?
>>Since the name used to access the collection is the one stored in the
>>metadata, I want to change this one.
>>If it is indeed possible, would you mind showing me a piece of code that
>>does it ?
>>
>>Thanks, that would really help out here !!
>>
>>
>>
>>    
>>
>this is basically all you need to do:
>
>            //get name:
>            CollectionImpl xindiceCol =
>(CollectionImpl)DatabaseManager.getCollection(collectionURI, username,
>password);
>
>            MetaData metaData = xindiceCol.getMetaData(resource);
>            String name = metaData.getAttribute("REALNAME");
>
>            //change name:
>            name = "foo";
>            metaData.setType(MetaData.COLLECTION);
>            metaData.setAttribute("REALNAME", name);
>
>
>            xindiceCol.setMetaData(resource, metaData);
>
>
>  
>
I tried that but can't make it work, and here's why :

The collection I want to change the name of, is right under the /db 
collection (its name is HausseTarifaire2004). 
When I try to perform a :    
    
(CollectionImpl)DatabaseManager.getCollection("xmldb:xindice://myUrl/db", 
username,password)   
    MetaData metaData = xindiceCol.getMetaData('HausseTarifaire2004');

I get the following exception :

    org.xmldb.api.base.XMLDBException: 
org.xmldb.api.base.XMLDBException: :This Collection 'db' cannot store 
Documents

When I use "HausseTarifaire2004" as current collection , I don't know 
how to access its metadata (since you must put the resource name as 
parameter of the getMetaData method call).

It seems (according to the javadocs) that metadata are accessible for 
resources (XML files) but not (or at least not easily) for collections.

Any idea here ?


Re: Renaming a collection

Posted by Alexander DEJANOVSKI <al...@laposte.net>.
>----- Original Message ----- 
>From: "Alexander DEJANOVSKI" <al...@laposte.net>
>To: <xi...@xml.apache.org>
>Sent: Friday, August 27, 2004 5:09 PM
>Subject: Re: Renaming a collection
>
>
>  
>
>>Wouter de Vaal wrote:
>>
>>    
>>
>>>>Is it possible to rename a collection that already exists and is filled
>>>>with data ?
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>No. The trick we used in our project is to put a presentable name of the
>>>collection in MetaData
>>>and then let the collection real name be a generated unique one.
>>>
>>>Regards,
>>>Wouter
>>>
>>>
>>>
>>>      
>>>
>>So according to what I understand, it would be possible to change the
>>presentable name of the collection by changing it in the metadata ?
>>Since the name used to access the collection is the one stored in the
>>metadata, I want to change this one.
>>If it is indeed possible, would you mind showing me a piece of code that
>>does it ?
>>
>>Thanks, that would really help out here !!
>>
>>
>>
>>    
>>
>this is basically all you need to do:
>
>            //get name:
>            CollectionImpl xindiceCol =
>(CollectionImpl)DatabaseManager.getCollection(collectionURI, username,
>password);
>
>            MetaData metaData = xindiceCol.getMetaData(resource);
>            String name = metaData.getAttribute("REALNAME");
>
>            //change name:
>            name = "foo";
>            metaData.setType(MetaData.COLLECTION);
>            metaData.setAttribute("REALNAME", name);
>
>
>            xindiceCol.setMetaData(resource, metaData);
>
>
>  
>
I'll try that, thanks a lot !!

Re: Renaming a collection

Posted by Wouter de Vaal <wo...@hotmail.com>.
----- Original Message ----- 
From: "Alexander DEJANOVSKI" <al...@laposte.net>
To: <xi...@xml.apache.org>
Sent: Friday, August 27, 2004 5:09 PM
Subject: Re: Renaming a collection


> Wouter de Vaal wrote:
>
> >>Is it possible to rename a collection that already exists and is filled
> >>with data ?
> >>
> >>
> >>
> >No. The trick we used in our project is to put a presentable name of the
> >collection in MetaData
> >and then let the collection real name be a generated unique one.
> >
> >Regards,
> >Wouter
> >
> >
> >
> So according to what I understand, it would be possible to change the
> presentable name of the collection by changing it in the metadata ?
> Since the name used to access the collection is the one stored in the
> metadata, I want to change this one.
> If it is indeed possible, would you mind showing me a piece of code that
> does it ?
>
> Thanks, that would really help out here !!
>
>
>
this is basically all you need to do:

            //get name:
            CollectionImpl xindiceCol =
(CollectionImpl)DatabaseManager.getCollection(collectionURI, username,
password);

            MetaData metaData = xindiceCol.getMetaData(resource);
            String name = metaData.getAttribute("REALNAME");

            //change name:
            name = "foo";
            metaData.setType(MetaData.COLLECTION);
            metaData.setAttribute("REALNAME", name);


            xindiceCol.setMetaData(resource, metaData);


Re: Renaming a collection

Posted by Murray Altheim <m....@open.ac.uk>.
Alexander DEJANOVSKI wrote:
> Wouter de Vaal wrote:
> 
> 
>>>Is it possible to rename a collection that already exists and is filled
>>>with data ?
>>
>>No. The trick we used in our project is to put a presentable name of the
>>collection in MetaData
>>and then let the collection real name be a generated unique one.
>>
>>Regards,
>>Wouter
>
> So according to what I understand, it would be possible to change the 
> presentable name of the collection by changing it in the metadata ?
> Since the name used to access the collection is the one stored in the 
> metadata, I want to change this one.
> If it is indeed possible, would you mind showing me a piece of code that 
> does it ?
> 
> Thanks, that would really help out here !!

I don't have any code handy, but the way I've done this is to
create a ListRenderer class that accepts Collection IDs, then
sets up a Thread to query the database for each Collection's
metadata, changing the displayed ID to a localized name taken
from the metadata as each Thread finishes.

This is just done by adding a renderer to the JList (or whatever
is displaying the collection name).

Murray

......................................................................
Murray Altheim                    http://kmi.open.ac.uk/people/murray/
Knowledge Media Institute
The Open University, Milton Keynes, Bucks, MK7 6AA, UK               .

   It may have been the provocative title of a book and then a movie
   adaptation, but Prozac Nation is no longer just a notion within
   the realm of entertainment, nor even a living reality only among
   those actually taking the drug. The 24 million prescriptions in
   the UK (in an adult population of 42.5 million) have now entered
   the nation's water supply in significant but undisclosed amounts.
   http://news.bbc.co.uk/1/hi/health/3545684.stm


Re: Renaming a collection

Posted by Alexander DEJANOVSKI <al...@laposte.net>.
Wouter de Vaal wrote:

>>Is it possible to rename a collection that already exists and is filled
>>with data ?
>>
>>    
>>
>No. The trick we used in our project is to put a presentable name of the
>collection in MetaData
>and then let the collection real name be a generated unique one.
>
>Regards,
>Wouter
>
>  
>
So according to what I understand, it would be possible to change the 
presentable name of the collection by changing it in the metadata ?
Since the name used to access the collection is the one stored in the 
metadata, I want to change this one.
If it is indeed possible, would you mind showing me a piece of code that 
does it ?

Thanks, that would really help out here !!