Exemplo n.º 1
0
  /**
   * Creates a uri path for the specified <code>node</code> By default this method uses {@link
   * BrixConfig#getMapper()} to map node path to a uri path.
   *
   * @param node node to create uri path for
   * @return uri path that represents the node
   */
  public Path getUriPathForNode(final BrixNode node) {
    // allow site plugin to translate jcr path into node path
    final String jcrPath = SitePlugin.get().fromRealWebNodePath(node.getPath());
    final Path nodePath = new Path(jcrPath);

    // use urimapper to create the uri
    return brix.getConfig().getMapper().getUriPathForNode(nodePath, brix);
  }
Exemplo n.º 2
0
  /**
   * Resolves uri path to a {@link BrixNode}. By default this method uses {@link
   * BrixConfig#getMapper()} to map the uri to a node path.
   *
   * @param uriPath uri path
   * @return node that maps to the <code>uriPath</code> or <code>null</code> if none
   */
  public BrixNode getNodeForUriPath(final Path uriPath) {
    BrixNode node = null;

    // create desired nodepath
    final Path nodePath =
        brix.getConfig().getMapper().getNodePathForUriPath(uriPath.toAbsolute(), brix);

    if (nodePath != null) {
      // allow site plugin to translate the node path into an actual jcr
      // path
      final String jcrPath = SitePlugin.get().toRealWebNodePath(nodePath.toString());

      // retrieve jcr session
      final String workspace = getWorkspace();
      final JcrSession session = brix.getCurrentSession(workspace);

      if (session.itemExists(jcrPath)) {
        // node exists, return it
        node = (BrixNode) session.getItem(jcrPath);
      }
    }

    return node;
  }
Exemplo n.º 3
0
  @Override
  public IRequestHandler mapRequest(Request request) {
    final Url url = request.getClientUrl();

    if (isInternalWicket(request)) {
      return null;
    }

    // TODO: This is just a quick fix
    if (url.getSegments().size() > 0) {
      if (url.getSegments().get(0).equals("webdav")
          || url.getSegments().get(0).equals("jcrwebdav")) {
        return null;
      }
    }

    Path path = new Path("/" + url.getPath());

    // root path handling
    if (path.isRoot()) {
      if (handleHomePage) {
        final BrixNode node = getNodeForUriPath(path);
        return SitePlugin.get()
            .getNodePluginForNode(node)
            .respond(
                new BrixNodeModel(node), new BrixPageParameters(request.getRequestParameters()));
      } else {
        return null;
      }
    }

    IRequestHandler handler = null;
    try {
      while (handler == null) {
        final BrixNode node = getNodeForUriPath(path);
        if (node != null) {
          SiteNodePlugin plugin = SitePlugin.get().getNodePluginForNode(node);
          if (plugin instanceof AbstractSitePagePlugin) {
            handler =
                SitePlugin.get()
                    .getNodePluginForNode(node)
                    .respond(new BrixNodeModel(node), createBrixPageParams(request.getUrl(), path));
          } else {
            handler =
                SitePlugin.get()
                    .getNodePluginForNode(node)
                    .respond(
                        new BrixNodeModel(node),
                        new BrixPageParameters(request.getRequestParameters()));
          }
        }
        if (handler != null || path.toString().equals(".")) {
          break;
        }
        path = path.parent();
        if (path.isRoot()) {
          break;
        }
      }
    } catch (JcrException e) {
      logger.warn("JcrException caught due to incorrect url", e);
    }

    final PageComponentInfo info = getPageComponentInfo(request.getUrl());
    if (info != null && info.getPageInfo().getPageId() != null) {
      Integer renderCount =
          info.getComponentInfo() != null ? info.getComponentInfo().getRenderCount() : null;

      if (info.getComponentInfo() == null) {
        PageProvider provider;
        if (handler instanceof BrixNodePageRequestHandler) {
          provider =
              new PageProvider(info.getPageInfo().getPageId(), BrixNodeWebPage.class, renderCount);
          BrixNodePageRequestHandler brixNodePageRequestHandler =
              (BrixNodePageRequestHandler) handler;
          final IPageProvider pageProviderAdapter = brixNodePageRequestHandler.getPageProvider();
          provider.setPageSource(
              new IPageSource() {
                @Override
                public IRequestablePage getPageInstance(int pageId) {
                  IRequestablePage page = null;
                  Integer existingPageId = pageProviderAdapter.getPageId();
                  if (existingPageId != null && pageId == existingPageId) {
                    page = pageProviderAdapter.getPageInstance();
                  }
                  return page;
                }

                @Override
                public IRequestablePage newPageInstance(
                    Class<? extends IRequestablePage> pageClass, PageParameters pageParameters) {
                  IRequestablePage page = pageProviderAdapter.getPageInstance();
                  page.getPageParameters().set(info.toString(), "");
                  return page;
                }
              });
        } else {
          provider = new PageProvider(info.getPageInfo().getPageId(), renderCount);
          provider.setPageSource(getContext());
        }

        // render page
        return new RenderPageRequestHandler(provider);
      } else {
        ComponentInfo componentInfo = info.getComponentInfo();
        PageAndComponentProvider provider =
            new PageAndComponentProvider(
                info.getPageInfo().getPageId(), renderCount, componentInfo.getComponentPath());

        provider.setPageSource(getContext());
        // listener interface
        RequestListenerInterface listenerInterface =
            requestListenerInterfaceFromString(componentInfo.getListenerInterface());

        return new ListenerInterfaceRequestHandler(
            provider, listenerInterface, componentInfo.getBehaviorId());
      }
    }

    return handler;
  }