AnsweredAssumed Answered

Existing document, but not viewable

Question asked by kalidor on Jan 30, 2009
Hello, I have a problem.
I wrote a class to create a new document.
The document is created, but in the Alfresco platform does not appear.
If using a class of research papers, do a search for the document itself, it is found …
Any advice? the class is as follows:

package org.alfresco.sample.jcr;

import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

public class CreazioneDocumento {

public static void main(String[] args) throws Exception {

    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:org/alfresco/sample/jcr/wiki-context.xml");
    Repository repository = (Repository)context.getBean("JCR.Repository");
Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

    try
    {
        System.out.println("Creazione di Prova…");

        Node rootNode = session.getRootNode();
        System.out.println("Root node: path=" + rootNode.getPath() + ", type=" + rootNode.getPrimaryNodeType().getName());
        Node companyHome = rootNode.getNode("app:company_home");
        System.out.println("Company home node: path=" + companyHome.getPath() + ", type=" + companyHome.getPrimaryNodeType().getName());
        
        // Nel caso in cui il documento esistesse, non va' avanti
        
        try
        {
            Node encyclopedia = companyHome.getNode("wiki:encyclopedia");
            encyclopedia.remove();
            System.out.println("Prova è stato trovato ed è stato rimosso");
        }
        catch(PathNotFoundException e)
        {
        }

        // Creazione di Prova
        Node encyclopedia = companyHome.addNode("wiki:encyclopedia", "cm:folder");
        encyclopedia.setProperty("cm:name", "Prova");
        encyclopedia.setProperty("cm:description", "");

        // Creazione della pagina
        Node page = encyclopedia.addNode("wiki:entry", "wiki:page");
        page.setProperty("cm:name", "TitoloProva");
        page.setProperty("cm:description", "");
        page.setProperty("cm:title", "Prova Prova");
        page.setProperty("cm:content", "Questo è un testo di prova");
        page.setProperty("wiki:category", new String[] {"Prova"});
               
        session.save();
        System.out.println("Prova creato");
    }
    finally
    {
        session.logout();
        System.exit(0);
    }
}
}

Thank you all.

Outcomes