Exemplo n.º 1
0
  @Override
  public void renderHead(IHeaderResponse response) {

    // includes jquery, required by the placeholder plugin (wicket only include jquery if he need
    // it)
    response.render(
        new PriorityHeaderItem(
            JavaScriptHeaderItem.forReference(
                getApplication().getJavaScriptLibrarySettings().getJQueryReference())));

    List<HeaderContribution> cssContribs =
        getGeoServerApplication().getBeansOfType(HeaderContribution.class);
    for (HeaderContribution csscontrib : cssContribs) {
      try {
        if (csscontrib.appliesTo(this)) {
          PackageResourceReference ref = csscontrib.getCSS();
          if (ref != null) {
            response.render(CssReferenceHeaderItem.forReference(ref));
          }

          ref = csscontrib.getJavaScript();
          if (ref != null) {
            response.render(JavaScriptHeaderItem.forReference(ref));
          }

          ref = csscontrib.getFavicon();
        }
      } catch (Throwable t) {
        LOGGER.log(Level.WARNING, "Problem adding header contribution", t);
      }
    }
  }
Exemplo n.º 2
0
  @SuppressWarnings("serial")
  public GeoServerBasePage() {
    // lookup for a pluggable favicon
    PackageResourceReference faviconReference = null;
    List<HeaderContribution> cssContribs =
        getGeoServerApplication().getBeansOfType(HeaderContribution.class);
    for (HeaderContribution csscontrib : cssContribs) {
      try {
        if (csscontrib.appliesTo(this)) {
          PackageResourceReference ref = csscontrib.getFavicon();
          if (ref != null) {
            faviconReference = ref;
          }
        }
      } catch (Throwable t) {
        LOGGER.log(Level.WARNING, "Problem adding header contribution", t);
      }
    }

    // favicon
    if (faviconReference == null) {
      faviconReference = new PackageResourceReference(GeoServerBasePage.class, "favicon.ico");
    }
    String faviconUrl = RequestCycle.get().urlFor(faviconReference, null).toString();
    add(new ExternalLink("faviconLink", faviconUrl, null));

    // page title
    add(
        new Label(
            "pageTitle",
            new LoadableDetachableModel<String>() {

              @Override
              protected String load() {
                return getPageTitle();
              }
            }));

    // login form
    WebMarkupContainer loginForm =
        new WebMarkupContainer("loginform") {
          protected void onComponentTag(org.apache.wicket.markup.ComponentTag tag) {
            String path = getRequest().getUrl().getPath();
            StringBuilder loginPath = new StringBuilder();
            if (path.isEmpty()) {
              // home page
              loginPath.append("../j_spring_security_check");
            } else {
              // boomarkable page of sorts
              String[] pathElements = path.split("/");
              for (String pathElement : pathElements) {
                if (!pathElement.isEmpty()) {
                  loginPath.append("../");
                }
              }
              loginPath.append("j_spring_security_check");
            }
            tag.put("action", loginPath);
          };
        };
    add(loginForm);
    final Authentication user = GeoServerSession.get().getAuthentication();
    final boolean anonymous = user == null || user instanceof AnonymousAuthenticationToken;
    loginForm.setVisible(anonymous);

    WebMarkupContainer logoutForm = new WebMarkupContainer("logoutform");
    logoutForm.setVisible(!anonymous);

    add(logoutForm);
    logoutForm.add(new Label("username", anonymous ? "Nobody" : user.getName()));

    // home page link
    add(
        new BookmarkablePageLink("home", GeoServerHomePage.class)
            .add(new Label("label", new StringResourceModel("home", (Component) null, null))));

    // dev buttons
    DeveloperToolbar devToolbar = new DeveloperToolbar("devButtons");
    add(devToolbar);
    devToolbar.setVisible(
        RuntimeConfigurationType.DEVELOPMENT.equals(getApplication().getConfigurationType()));

    final Map<Category, List<MenuPageInfo>> links =
        splitByCategory(filterByAuth(getGeoServerApplication().getBeansOfType(MenuPageInfo.class)));

    List<MenuPageInfo> standalone =
        links.containsKey(null) ? links.get(null) : new ArrayList<MenuPageInfo>();
    links.remove(null);

    List<Category> categories = new ArrayList<>(links.keySet());
    Collections.sort(categories);

    add(
        new ListView<Category>("category", categories) {
          public void populateItem(ListItem<Category> item) {
            Category category = item.getModelObject();
            item.add(
                new Label(
                    "category.header",
                    new StringResourceModel(category.getNameKey(), (Component) null, null)));
            item.add(
                new ListView<MenuPageInfo>("category.links", links.get(category)) {
                  public void populateItem(ListItem<MenuPageInfo> item) {
                    MenuPageInfo info = item.getModelObject();
                    BookmarkablePageLink<Page> link =
                        new BookmarkablePageLink<>("link", info.getComponentClass());
                    link.add(
                        AttributeModifier.replace(
                            "title",
                            new StringResourceModel(
                                info.getDescriptionKey(), (Component) null, null)));
                    link.add(
                        new Label(
                            "link.label",
                            new StringResourceModel(info.getTitleKey(), (Component) null, null)));
                    Image image;
                    if (info.getIcon() != null) {
                      image =
                          new Image(
                              "link.icon",
                              new PackageResourceReference(
                                  info.getComponentClass(), info.getIcon()));
                    } else {
                      image =
                          new Image(
                              "link.icon",
                              new PackageResourceReference(
                                  GeoServerBasePage.class, "img/icons/silk/wrench.png"));
                    }
                    image.add(
                        AttributeModifier.replace(
                            "alt", new ParamResourceModel(info.getTitleKey(), null)));
                    link.add(image);
                    item.add(link);
                  }
                });
          }
        });

    add(
        new ListView<MenuPageInfo>("standalone", standalone) {
          public void populateItem(ListItem<MenuPageInfo> item) {
            MenuPageInfo info = item.getModelObject();
            BookmarkablePageLink<Page> link =
                new BookmarkablePageLink<>("link", info.getComponentClass());
            link.add(
                AttributeModifier.replace(
                    "title",
                    new StringResourceModel(info.getDescriptionKey(), (Component) null, null)));
            link.add(
                new Label(
                    "link.label",
                    new StringResourceModel(info.getTitleKey(), (Component) null, null)));
            item.add(link);
          }
        });

    add(feedbackPanel = new FeedbackPanel("feedback"));
    feedbackPanel.setOutputMarkupId(true);

    // ajax feedback image
    add(
        new Image(
            "ajaxFeedbackImage",
            new PackageResourceReference(GeoServerBasePage.class, "img/ajax-loader.gif")));

    add(new WebMarkupContainer(HEADER_PANEL));

    // allow the subclasses to initialize before getTitle/getDescription are called
    add(
        new Label(
            "gbpTitle",
            new LoadableDetachableModel<String>() {

              @Override
              protected String load() {
                return getTitle();
              }
            }));
    add(
        new Label(
            "gbpDescription",
            new LoadableDetachableModel<String>() {

              @Override
              protected String load() {
                return getDescription();
              }
            }));

    // node id handling
    WebMarkupContainer container = new WebMarkupContainer("nodeIdContainer");
    add(container);
    String id = getNodeInfo().getId();
    Label label = new Label("nodeId", id);
    container.add(label);
    NODE_INFO.customize(container);
    if (id == null) {
      container.setVisible(false);
    }
  }