}
SessionProviderService sessionProviderService =
(SessionProviderService)container.getComponentInstanceOfType(SessionProviderService.class);
RepositoryService repositoryService =
(RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
try
{
if (ConversationState.getCurrent() != null)
{
if (jcrBrowser != null && jcrBrowser.getNode() != null)
{
// navigate through JCR Repository
String repositoryName = (String)httpRequest.getParameter("repositoryName");
String workspaceName = (String)httpRequest.getParameter("workspaceName");
// check if browser related to repository/workspace given in attrs
if (repositoryName != null
&& !jcrBrowser.getRepository().getConfiguration().getName().equals(repositoryName))
{
// ask repositoryService and if not found lookup JNDI by given name
try
{
jcrBrowser.setRepository(repositoryService.getRepository(repositoryName));
}
catch (RepositoryException e)
{
if (e.getMessage().indexOf("not found") > 0)
{
// check in JNDI
LOG.warn("Repository '" + repositoryName + "' is not local. Trying JNDI lookup with the name.");
ManageableRepository jndiRepo;
try
{
InitialContext ctx = new InitialContext();
Object obj = ctx.lookup(repositoryName);
if (obj instanceof ManageableRepository)
{
jndiRepo = (ManageableRepository)obj;
}
else
{
obj = ctx.lookup("java:comp/env/" + repositoryName);
if (obj instanceof ManageableRepository)
{
jndiRepo = (ManageableRepository)obj;
}
else
{
LOG.warn("Can't cast object " + obj + " as ManageableRepository class object");
jndiRepo = null;
}
}
if (jndiRepo == null)
jcrBrowser.addError(e);
else
jcrBrowser.setRepository(jndiRepo);
}
catch (NamingException jndie)
{
LOG.warn("Repository not bound in JNDI with one of names '" + repositoryName
+ "', 'java:comp/env/" + repositoryName + "' or can't be connected.", jndie);
try
{
InitialContext ctx = new InitialContext();
Object obj = ctx.lookup("java:comp/env/jcr/" + repositoryName);
if (obj instanceof ManageableRepository)
{
jndiRepo = (ManageableRepository)obj;
}
else
{
LOG.warn("Can't cast object " + obj + " as ManageableRepository class object");
jndiRepo = null;
}
if (jndiRepo == null)
{
jcrBrowser.addError(e);
jcrBrowser.addError(jndie);
}
else
jcrBrowser.setRepository(jndiRepo);
}
catch (NamingException jndie1)
{
LOG.warn("Repository not bound in JNDI with name 'java:comp/env/jcr/" + repositoryName
+ "' or can't be connected.", jndie1);
jcrBrowser.addError(e);
jcrBrowser.addError(jndie);
jcrBrowser.addError(jndie1);
}
}
}
}
}
if (jcrBrowser.getRepository() != null)
{
if (workspaceName != null && !jcrBrowser.getSession().getWorkspace().getName().equals(workspaceName))
{
jcrBrowser.setSession(sessionProviderService.getSessionProvider(null).getSession(workspaceName,
jcrBrowser.getRepository()));
}
// Navigation
String path = (String)httpRequest.getParameter("goParent");
if (path != null)
{
jcrBrowser.setNode(jcrBrowser.getNode().getNode(path));
}
else
{
path = (String)httpRequest.getParameter("goNodePath");
if (path != null)
jcrBrowser.setNode((Node)jcrBrowser.getSession().getItem(path));
// else seems nothing changed in JCR navigation
}
// Synchronization
String doSynchronize = (String)httpRequest.getParameter("synchronize");
if (doSynchronize != null && doSynchronize.equals("run"))
{
jcrBrowser.runSynchronization();
}
}
}
else
{
// start from root node
ManageableRepository repository = repositoryService.getDefaultRepository();
Session jcrSession =
sessionProviderService.getSessionProvider(null).getSession(
repository.getConfiguration().getDefaultWorkspaceName(), repository);