You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Michael Neale <mi...@gmail.com> on 2006/11/28 11:04:47 UTC

exportDocumentView and importXML ?

I am using the JCR exportDocumentView and importXML and having troubles even
with the basics (I am sure I am missing something).

To export (from the root):
session.exportDocumentView( "/", out, false, false );

To import, I tried:
session.getWorkspace().importXML( "/", in,
ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);

In which case I get:

Exception Caused by: javax.jcr.InvalidSerializedDataException: failed to
parse XML stream: Invalid name: : Invalid name:
    at org.apache.jackrabbit.core.WorkspaceImpl.importXML(WorkspaceImpl.java
:740)
    at org.drools.repository.RulesRepository.importXML(RulesRepository.java
:244)
    ... 19 more
Caused by: org.apache.jackrabbit.name.IllegalNameException: empty name
    at org.apache.jackrabbit.core.xml.DocViewImportHandler.parseNames(
DocViewImportHandler.java:255)
    ...

If I use the SESSION version of the importXML (which reads to me like it is
equivalent, but does more in memory work):
session.importXML( "/", in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);

In which case I get:

Caused by: javax.jcr.nodetype.ConstraintViolationException:
/jcr:root/jcr:system/jcr:versionStorage: cannot add a child to a protected
node
    at org.apache.jackrabbit.core.NodeImpl.internalAddChildNode(
NodeImpl.java:803)
    at org.apache.jackrabbit.core.NodeImpl.addNode(NodeImpl.java:1548)

Any tips ? I must be completely mis understanding it.

I am interested in import/export for migrating content to an empty
repository (also interested in what importXML does when the node types in
the new empty repository are changed from what it was exported as).

Re: exportDocumentView and importXML ?

Posted by Nicolas <nt...@gmail.com>.
Hi Michael,

You are exporting /jcr:system/ which is read only and then reimporting them.
Besides there are issues also with UUID and importation of the root node
with this uuidBehaviour. If you need, I can explain in more depth.

Here is how it is done on the backup tool to avoid exporting the jcr:system
subtree. (in the backup tool case, the versioning history is backuped by
another class.)

 /* (non-Javadoc)
     * @see org.apache.jackrabbijcr:root/t.backup.Backup#backup(org.apache.jackrabbit.backup.BackupIOHandler)
     */
    public void backup(BackupIOHandler h) throws RepositoryException,

    IOException {
        SessionImpl s = (SessionImpl)
this.getRepo().login(this.getCredentials(), this.wspName);

        SAXTransformerFactory stf = (SAXTransformerFactory)
SAXTransformerFactory.newInstance
();
        File temp = new File(this.getConf().getWorkFolder() + "wsp.xml");
        try {
            TransformerHandler th = stf.newTransformerHandler();
            th.setResult(new StreamResult(new FileOutputStream(temp)));

            th.getTransformer().setParameter(OutputKeys.METHOD, "xml");
            th.getTransformer().setParameter(OutputKeys.ENCODING, "UTF-8");
            th.getTransformer().setParameter(
OutputKeys.INDENT, "no");

            new SysViewSAXEventGenerator(
                    s.getRootNode(), false, false, th) {
                protected void process(Node node, int level)

                throws RepositoryException, SAXException {
                    if (!"/jcr:system".equals(node.getPath())) {
                        super.process(node, level);
                    }
                }

            }.serialize();
            h.write("export_"+ this.wspName +".xml", temp);
        } catch (TransformerException te) {
            throw new RepositoryException(te);
        } catch (SAXException se) {

            throw new RepositoryException(se);
        } finally {
            temp.delete();
        }

    }


On a sidenote, for your use case I would use system view instead of the
document view.

BR,
Nicolas