+ private class CmsEntryPointFactory implements EntryPointFactory {
+ private final String page;
+
+ public CmsEntryPointFactory(String page) {
+ this.page = page;
+ }
+
+ @Override
+ public EntryPoint create() {
+ CmsEntryPoint entryPoint = new CmsEntryPoint(repository, workspace,
+ pages.get(page));
+ entryPoint.setState("");
+ CmsSession.current.set(entryPoint);
+ return entryPoint;
+ }
+
+ }
+
+ private class CmsEntryPoint extends AbstractCmsEntryPoint {
+ private Composite headerArea;
+ private Composite bodyArea;
+ private final CmsUiProvider uiProvider;
+
+ public CmsEntryPoint(Repository repository, String workspace,
+ CmsUiProvider uiProvider) {
+ super(repository, workspace);
+ this.uiProvider = uiProvider;
+ }
+
+ @Override
+ protected void createContents(Composite parent) {
+ try {
+ getShell().getDisplay().setData(CmsSession.KEY, this);
+
+ parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
+ true));
+ parent.setLayout(CmsUtils.noSpaceGridLayout());
+
+ headerArea = new Composite(parent, SWT.NONE);
+ headerArea.setLayout(new FillLayout());
+ GridData headerData = new GridData(SWT.FILL, SWT.FILL, false,
+ false);
+ headerData.heightHint = headerHeight;
+ headerArea.setLayoutData(headerData);
+ refreshHeader();
+
+ bodyArea = new Composite(parent, SWT.NONE);
+ bodyArea.setData(RWT.CUSTOM_VARIANT, CmsStyles.CMS_BODY);
+ bodyArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
+ true));
+ bodyArea.setBackgroundMode(SWT.INHERIT_DEFAULT);
+ bodyArea.setLayout(CmsUtils.noSpaceGridLayout());
+ refreshBody();
+ } catch (Exception e) {
+ throw new CmsException("Cannot create entrypoint contents", e);
+ }
+ }
+
+ @Override
+ protected void refreshHeader() {
+ if (headerArea == null)
+ return;
+ for (Control child : headerArea.getChildren())
+ child.dispose();
+ try {
+ header.createUi(headerArea, getNode());
+ } catch (RepositoryException e) {
+ throw new CmsException("Cannot refresh header", e);
+ }
+ headerArea.layout(true, true);
+ }
+
+ @Override
+ protected void refreshBody() {
+ if (bodyArea == null)
+ return;
+ // clear
+ for (Control child : bodyArea.getChildren())
+ child.dispose();
+ bodyArea.setLayout(CmsUtils.noSpaceGridLayout());
+
+ // Exception
+ Throwable exception = getException();
+ if (exception != null) {
+ new Label(bodyArea, SWT.NONE).setText("Unreachable state : "
+ + getState());
+ if (getNode() != null)
+ new Label(bodyArea, SWT.NONE).setText("Context : "
+ + getNode());
+
+ Text errorText = new Text(bodyArea, SWT.MULTI | SWT.H_SCROLL
+ | SWT.V_SCROLL);
+ errorText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
+ true));
+ StringWriter sw = new StringWriter();
+ exception.printStackTrace(new PrintWriter(sw));
+ errorText.setText(sw.toString());
+ IOUtils.closeQuietly(sw);
+ resetException();
+ // TODO report
+ } else {
+ String state = getState();
+ try {
+ if (state == null)
+ throw new CmsException("State cannot be null");
+ uiProvider.createUi(bodyArea, getNode());
+ // if (page == null)
+ // throw new CmsException("Page cannot be null");
+ // // else if (state.length() == 0)
+ // // log.debug("empty state");
+ // else if (pages.containsKey(page))
+ // pages.get(page).createUi(bodyArea, getNode());
+ // else {
+ // // try {
+ // // RWT.getResponse().sendError(404);
+ // // } catch (IOException e) {
+ // // log.error("Cannot send 404 code", e);
+ // // }
+ // throw new CmsException("Unsupported state " + state);
+ // }
+ } catch (RepositoryException e) {
+ throw new CmsException("Cannot refresh body", e);
+ }
+ }
+ bodyArea.layout(true, true);
+ }
+
+ @Override
+ protected void logAsAnonymous() {
+ cmsLogin.logInAsAnonymous();
+ }
+
+ @Override
+ protected Node getDefaultNode(Session session)
+ throws RepositoryException {
+ if (!session.hasPermission(basePath, "read")) {
+ if (session.getUserID().equals("anonymous"))
+ throw new CmsLoginRequiredException();
+ else
+ throw new CmsException("Unauthorized");
+ }
+ return session.getNode(basePath);
+ }
+
+ @Override
+ public CmsImageManager getImageManager() {
+ return imageManager;
+ }
+
+ }
+
+ private static ResourceLoader createResourceLoader(final String resourceName) {
+ return new ResourceLoader() {
+ public InputStream getResourceAsStream(String resourceName)
+ throws IOException {
+ return getClass().getClassLoader().getResourceAsStream(
+ resourceName);
+ }
+ };
+ }