I am doing something very similar. I'm still tinkering, but here's my solution 
so far. In a nutshell, I wrote a custom XML export function in an existing 
Struts/Hibernate/EJB-based application and import the result into Magnolia.

Disclaimer: I'm new to Magnolia development so I was more comfortable adding a 
couple classes to the legacy app rather than modifying Magnolia directly. Also, 
I do both front end/JSP and server/Java development.


First, you need an XML marshalling utility. There are lots of them out there, 
but I found Xstream lightweight and easy to use. Check it out at: 
http://xstream.codehaus.org.

Next, I modified an existing Struts action in our existing app that iterated 
over our product catalog. I updated it so it would go through ALL products, not 
just those matching certain criteria. The key concept here is you have a data 
structure (e.g. a List) that contains all of your data represented as Java 
objects.

In the middle of looping over all those Java objects (e.g. "Products"), you 
would call Xstream to generate the XML and then write it out to a file. 

For example, here's how I write out a single product:

try {
                                                
XStream xstream = new XStream();

xstream.alias("Product", com.leapfrog.dto.catalog.Product.class);
xstream.alias("Award", com.leapfrog.dto.catalog.Award.class);
xstream.alias("Platform", com.leapfrog.dto.catalog.CatalogEntry.class);

xstream.aliasAttribute("ageRange", "mAgeRange");
xstream.aliasAttribute("altText", "mAltText");
xstream.aliasAttribute("ageRange", "mAgeRange");
                                                                                
    
xstream.useAttributeFor(Product.class);
xstream.useAttributeFor(String.class);
xstream.useAttributeFor(boolean.class);
xstream.useAttributeFor(ArrayList.class);                                       
        
xstream.useAttributeFor(double.class);
xstream.useAttributeFor(int.class);
xstream.useAttributeFor(com.leapfrog.dto.catalog.Award.class);  
                                                            
String xml = xstream.toXML(product);                                        
BufferedWriter out = new BufferedWriter(new FileWriter("./products/" + id + 
".xml"));
out.write(xml);
out.close();
                                        
logDebug("XML was written for products.");
} catch (Exception e) {
        logDebug(e.toString());
}                               
                                                

To write out an entire List of products (part of the export function I'm still 
working on) I believe you can just keep appending product after product to a 
single XML file and Magnolia will import then all at once instead of one at a 
time like in the example above. 

The trick is that I had to use Xstream's aliasAttribute(), useAttributeFor(), 
and alias() methods to control how the XML output was formatted. Magnolia's XML 
import feature is picky about the structure of the import file, hence the 
xstream.useAttributeFor method calls that basically instruct Xstream to write 
out EVERYTHING as an attribute. The alias and alias.Attribute method calls were 
more for readability, converting somewhat cryptic Java object names into more 
human-friendly descriptors. The details on these methods are documented at 
http://xstream.codehaus.org/manual-tweaking-output.html.

Once the exported .xml file is generated, you can use Magnolia's authoring 
instance to import it into the Website repository.

The next logical step (for me at least) is to set up a seperate Products 
repository and custom JCR browser tree for it so that product-specific content 
can be logically seperate from what is more purely display-oriented content. 
This isn't strictly necessary, of course.

I know you aren't a fan of the XML import/export approach, but this is working 
for me so far. Hope this helps.


Michael Beaty
Sr. Software Engineer
LeapFrog IT
(510) 596-6710



-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED]
Sent: March 12, 2007 9:41 AM
To: [email protected]
Subject: [magnolia-user] importing content from previous sites


Hi all,
we are going to strat a project in wich will migrate a site to magnolia. 
We'll need to import old contents from existing db to magnolia jcr 
repository.
Does anybody know about a smart approach to do this task(generate xml to 
import(I don't like it) or developing custom services(it seems a bit 
complex) ).
Thank in advance for any best practice or known issue related to this 
problem
Filippo

-- 

Filippo Fratoni

e-mail:[EMAIL PROTECTED]
office:+39.02320626320 
mobile:+39.3929095585
Fax: +39.0293650552

OpenMind S.r.l.
V. Gorizia, 6 20052 MONZA MI


----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/developer.html
----------------------------------------------------------------

----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/developer.html
----------------------------------------------------------------

Reply via email to