protected void onEvent(AjaxRequestTarget target) {
    Request request = RequestCycle.get().getRequest();

    Overlay overlay = null;

    String markerParameter = request.getRequestParameters().getParameterValue("marker").toString();
    if (markerParameter != null) {
      OpenLayersMap map = getOpenLayerMap();
      for (Overlay ovl : map.getOverlays()) {
        if (ovl.getId().equals(markerParameter)) {
          overlay = ovl;
          break;
        }
      }
    }
    String markerEvent = request.getRequestParameters().getParameterValue("event").toString();

    if (wantEvents) {
      // Translate from string to type!
      EventType eventType = EventType.valueOf(markerEvent);
      onEvent(target, overlay, eventType);
    } else {
      onClick(target, overlay);
    }
  }
Beispiel #2
0
 @Override
 protected final void respond(AjaxRequestTarget target) {
   Request request = RequestCycle.get().getRequest();
   String newContent = request.getRequestParameters().getParameterValue(PARAM_HTMLCONT).toString();
   newContent = onSave(target, newContent);
   Component component = getComponent();
   IModel defaultModel = component.getDefaultModel();
   defaultModel.setObject(newContent);
   target.add(component);
 }
Beispiel #3
0
  public final void onRequest() {
    RequestCycle requestCycle = getComponent().getRequestCycle();
    Request request = requestCycle.getRequest();
    IRequestParameters parameters = request.getRequestParameters();
    StringValue input = parameters.getParameterValue("term");

    final Iterable<T> choices = getChoices(input.toString(""));

    String jsonArray = createJson(choices);

    requestCycle.scheduleRequestHandlerAfterCurrent(
        new TextRequestHandler("application/json", "UTF-8", jsonArray));
  }
  @Override
  public void onResourceRequested() {

    // this is the callback that retrieves matching choices used to populate the dropdown

    Request request = getRequestCycle().getRequest();
    IRequestParameters params = request.getRequestParameters();

    // retrieve choices matching the search term

    String term = params.getParameterValue("term").toOptionalString();

    int page = params.getParameterValue("page").toInt(1);
    // select2 uses 1-based paging, but in wicket world we are used to
    // 0-based
    page -= 1;

    Response<T> response = new Response<T>();
    provider.query(term, page, response);

    // jsonize and write out the choices to the response

    WebResponse webResponse = (WebResponse) getRequestCycle().getResponse();
    webResponse.setContentType("application/json");

    OutputStreamWriter out =
        new OutputStreamWriter(webResponse.getOutputStream(), getRequest().getCharset());
    JSONWriter json = new JSONWriter(out);

    try {
      json.object();
      json.key("results").array();
      for (T item : response) {
        json.object();
        provider.toJson(item, json);
        json.endObject();
      }
      json.endArray();
      json.key("more").value(response.getHasMore()).endObject();
    } catch (JSONException e) {
      throw new RuntimeException("Could not write Json response", e);
    }

    try {
      out.flush();
    } catch (IOException e) {
      throw new RuntimeException("Could not write Json to servlet response", e);
    }
  }
  @Override
  public Session newSession(final Request request, final Response response) {
    if (!DEMO_MODE_USING_CREDENTIALS_AS_QUERYARGS) {
      return super.newSession(request, response);
    }

    // else demo mode
    final AuthenticatedWebSessionForIsis s =
        (AuthenticatedWebSessionForIsis) super.newSession(request, response);
    IRequestParameters requestParameters = request.getRequestParameters();
    final org.apache.wicket.util.string.StringValue user =
        requestParameters.getParameterValue("user");
    final org.apache.wicket.util.string.StringValue password =
        requestParameters.getParameterValue("pass");
    s.signIn(user.toString(), password.toString());
    return s;
  }
  @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;
  }