You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Randy Watler <wa...@wispertel.net> on 2009/09/01 08:29:17 UTC

Re: How to programmatically define fragments/portlets / prefrences for a new page

David,

I have tested your code below in a slightly modified junit test and 
everything works as expected. Given that we are having a 
ClassCastException in a constructor within dom4j, I have to wonder if we 
have incompatible or multiple versions of that library loaded.

See this issue: http://issues.apache.org/jira/browse/JS2-1040

Please verify that you dont have a copy of dom4j in a common or shared 
classloader in addition to the one in jetspeed/WEB-INF/lib.

HTH,

Randy

---------------------------------------------------------------------------------------------------------------

package org.apache.jetspeed.page;

import java.util.List;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.apache.jetspeed.om.common.SecurityConstraints;
import org.apache.jetspeed.om.folder.Folder;
import org.apache.jetspeed.om.page.Fragment;
import org.apache.jetspeed.om.page.Page;
import org.apache.jetspeed.page.psml.CastorXmlPageManager;
import org.apache.jetspeed.test.JetspeedTestCase;

public class TestAddInstance extends JetspeedTestCase implements 
PageManagerTestShared
{
    protected CastorXmlPageManager pageManager;
   
    protected void setUp() throws Exception
    {
        super.setUp();
        pageManager = Shared.makeCastorXMLPageManager(getBaseDir(), 
"pages", false, false);
    }

    protected void tearDown() throws Exception
    {
        super.tearDown();
        Shared.shutdownCastorXMLPageManager(pageManager);
    }

    public static Test suite()
    {
        return new TestSuite(TestAddInstance.class);
    }
   
    public void testAddInstance()
    {
        for (int i = 0; (i < 1000); i++)
        {
            try
            {
                String userName = "user"+(int)(Math.random()*100.0);
                String instanceName = "instance"+(int)(Math.random()*100.0);
                Folder newUserFolder;
                if (pageManager.userFolderExists(userName))
                {
                    newUserFolder = pageManager.getUserFolder(userName);
                }
                else
                {
                    newUserFolder = 
pageManager.newFolder(Folder.USER_FOLDER + userName);
                    SecurityConstraints constraints = 
pageManager.newSecurityConstraints();
                    newUserFolder.setSecurityConstraints(constraints);
                    
newUserFolder.getSecurityConstraints().setOwner(userName);
                    pageManager.updateFolder(newUserFolder);
                }
                String folderPath = newUserFolder.getPath() + "/" + 
instanceName;
                if (!pageManager.folderExists(folderPath))
                {
                    Folder folder = pageManager.newFolder(folderPath);
                    folder.setTitle(instanceName);
                    folder.setShortTitle(instanceName);

                    Page page = pageManager.newPage(folder.getPath() + 
"/default-page.psml");
                    page.setTitle("first page");
                    Fragment fragment = pageManager.newFragment();
                    fragment.setType(Fragment.PORTLET);
                    fragment.setName("ui-pa::myportlet");
                    List<Fragment> fragments = 
page.getRootFragment().getFragments();
                    fragments.add(fragment);
                    folder.setDefaultPage("default-page");
                    pageManager.updateFolder(folder, true);
                    pageManager.updatePage(page);

                    System.out.println(">>>>> added "+folderPath);
                }
                else
                {
                    System.out.println(">>>>> duplicate 
"+folderPath);                   
                }
            }
            catch (Exception e)
            {
                throw new RuntimeException("Unexpected exception: "+e, e);
            }
        }
    }   
}

---------------------------------------------------------------------------------------------------------

David Just wrote:
> I've tried both and they both fail.  It randomly worked once while I was
> debugging, and traced the problem down to line 235 in
> CastorFileSystemDocumentHandler.java. The line 
> XMLWriter xmlWriter = new XMLWriter(writer, this.format);
>
> Is throwing an XML not ended properly exception.
>
>
>
> David Just l Software Engineer l Vision Solutions l +1 (507) 529-5939 l david.just@visionsolutions.com
> The contents of this e-mail (and any attachments) are privileged and confidential. Unauthorized use is strictly prohibited.
> -----Original Message-----
> From: Randy Watler [mailto:watler@wispertel.net] 
> Sent: Tuesday, August 25, 2009 5:52 PM
> To: Jetspeed Users List
> Subject: Re: How to programmatically define fragments/portlets /
> prefrences for a new page
>
> David,
>
> Which invocation here is failing?
>
> jsPageManager.updateFolder(newUserFolder);
>
> or
>
> jsPageManager.updateFolder(folder, true);
>
> Randy
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org