/**
  * Cleans the metadata (triggers, poll time) associated with a given behavior id
  *
  * @param application the application in which the metadata are stored
  * @param id the id of the behavior
  */
 private static void cleanMetadata(final Application application, String id) {
   id = getPageId(application, id);
   ConcurrentMap<String, List<DelayedMethodCallList>> triggersById = null;
   ConcurrentMap<String, Time> eventsTimeById = null;
   ConcurrentMap<String, String> pageIdsById = null;
   synchronized (application) {
     triggersById = application.getMetaData(TRIGGERS_KEY);
     eventsTimeById = application.getMetaData(EVENTS_KEY);
     pageIdsById = application.getMetaData(PAGE_ID_KEY);
   }
   if (triggersById != null) {
     final List<DelayedMethodCallList> triggers = triggersById.remove(id);
     if (triggers != null) {
       synchronized (triggers) {
         triggers.clear();
       }
     }
   }
   if (eventsTimeById != null) {
     eventsTimeById.remove(id);
   }
   if (pageIdsById != null) {
     pageIdsById.remove(id);
   }
 }
Esempio n. 2
0
 @Override
 public void init(final Application application) {
   AnnotationEventDispatcherConfig config = new AnnotationEventDispatcherConfig();
   application.setMetaData(ANNOTATION_EVENT_DISPATCHER_CONFIG_CONTEXT_KEY, config);
   AnnotationEventDispatcher dispatcher = new AnnotationEventDispatcher();
   application.getComponentInstantiationListeners().add(dispatcher);
   application.getFrameworkSettings().add(dispatcher);
 }
  /**
   * Gets the {@link JQueryLibrarySettings}
   *
   * @return The {@link JQueryLibrarySettings} or {@code null} if {@link Application}'s {@link
   *     JavaScriptLibrarySettings} is not an instance of {@link JQueryLibrarySettings}
   */
  public static JQueryLibrarySettings getJQueryLibrarySettings() {
    if (Application.exists()
        && (Application.get().getJavaScriptLibrarySettings() instanceof JQueryLibrarySettings)) {
      return (JQueryLibrarySettings) Application.get().getJavaScriptLibrarySettings();
    }

    return null;
  }
Esempio n. 4
0
 public static RepeaterUtil get() {
   Application app = Application.get();
   RepeaterUtil util = app.getMetaData(REPEATER_UTIL_KEY);
   if (util != null) {
     return util;
   }
   util = new RepeaterUtil(app); // this registers too
   return util;
 }
Esempio n. 5
0
  private void onInternalDetach() {
    if (Session.exists()) {
      Session.get().internalDetach();
    }

    if (Application.exists()) {
      IRequestLogger requestLogger = Application.get().getRequestLogger();
      if (requestLogger != null) requestLogger.performLogging();
    }
  }
 /**
  * Returns a localized message string, if there is a localization; otherwise the given default
  * value.
  *
  * @param key message key for the message
  * @param defaultValue to use if no localization for the message can be found
  * @return the possibly localized message
  */
 private String getMsg(String key, String defaultValue) {
   if (Application.exists()) {
     Localizer localizer = Application.get().getResourceSettings().getLocalizer();
     if (localizer != null) {
       // Use getStringIgnoreSettings because we don't want exceptions here if the key is missing!
       return localizer.getStringIgnoreSettings(key, null, null, defaultValue);
     }
   }
   return defaultValue;
 }
  private RequestCycle newRequestCycle(final RuntimeException exception) {
    final Response originalResponse = newResponse();
    Request request = new MockWebRequest(Url.parse("http://wicket.apache.org"));
    handler =
        new IRequestHandler() {
          @Override
          public void respond(IRequestCycle requestCycle) {
            if (exception != null) {
              throw exception;
            }
            responses++;
          }

          @Override
          public void detach(IRequestCycle requestCycle) {
            detaches++;
          }
        };
    IRequestMapper requestMapper =
        new IRequestMapper() {
          @Override
          public IRequestHandler mapRequest(Request request) {
            return handler;
          }

          @Override
          public Url mapHandler(IRequestHandler requestHandler) {
            throw new UnsupportedOperationException();
          }

          @Override
          public int getCompatibilityScore(Request request) {
            throw new UnsupportedOperationException();
          }
        };
    IExceptionMapper exceptionMapper =
        new IExceptionMapper() {
          @Override
          public IRequestHandler map(Exception e) {
            exceptionsMapped++;
            return null;
          }
        };
    RequestCycleContext context =
        new RequestCycleContext(request, originalResponse, requestMapper, exceptionMapper);

    RequestCycle cycle = new RequestCycle(context);

    if (Application.exists()) {
      cycle.getListeners().add(Application.get().getRequestCycleListeners());
    }

    return cycle;
  }
 @Override
 public Iterable<? extends HeaderItem> getDependencies() {
   final ResourceReference backingLibraryReference;
   if (Application.exists()) {
     backingLibraryReference =
         Application.get().getJavaScriptLibrarySettings().getJQueryReference();
   } else {
     backingLibraryReference = JQueryResourceReference.get();
   }
   return Dependencies.combine(
       super.getDependencies(), JavaScriptHeaderItem.forReference(backingLibraryReference));
 }
 private static void touch(final Application application, String id) {
   id = getPageId(application, id);
   ConcurrentMap<String, Time> eventsTimeById;
   synchronized (application) {
     eventsTimeById = application.getMetaData(EVENTS_KEY);
     if (eventsTimeById == null) {
       eventsTimeById = new ConcurrentHashMap<String, Time>();
       application.setMetaData(EVENTS_KEY, eventsTimeById);
     }
   }
   eventsTimeById.put(id, Time.now());
 }
  @Test
  public void exceptionIsHandledByFirstAvailableHandler() {
    // when two listeners return a handler
    Application.get().getRequestCycleListeners().add(new ErrorCodeListener(401));
    Application.get().getRequestCycleListeners().add(new ErrorCodeListener(402));

    RequestCycle cycle = newRequestCycle(new RuntimeException("testing purposes only"));
    cycle.processRequestAndDetach();

    // the first handler returned is used to handle the exception
    assertEquals(401, errorCode);
  }
 /**
  * Determines a limit to use for HTML diff output.
  *
  * @param key to use to read the value from the GitBlit settings, if available.
  * @param minimum minimum value to enforce
  * @param maximum maximum (and default) value to enforce
  * @return the limit
  */
 private int getLimit(String key, int minimum, int maximum) {
   if (Application.exists()) {
     Application application = Application.get();
     if (application instanceof GitBlitWebApp) {
       GitBlitWebApp webApp = (GitBlitWebApp) application;
       int configValue = webApp.settings().getInteger(key, maximum);
       if (configValue < minimum) {
         return minimum;
       } else if (configValue < maximum) {
         return configValue;
       }
     }
   }
   return maximum;
 }
  @Test
  public void exceptionIsHandledByRegisteredHandler() {
    IncrementingListener incrementingListener = new IncrementingListener();
    Application.get().getRequestCycleListeners().add(incrementingListener);
    Application.get().getRequestCycleListeners().add(new ErrorCodeListener(401));

    RequestCycle cycle = newRequestCycle(new RuntimeException("testing purposes only"));
    cycle.processRequestAndDetach();

    assertEquals(401, errorCode);
    assertEquals(2, incrementingListener.resolved);
    assertEquals(1, incrementingListener.executed);
    assertEquals(1, incrementingListener.exceptionResolutions);
    assertEquals(0, incrementingListener.schedules);
  }
 @Override
 public void renderHead(final IHeaderResponse response) {
   super.renderHead(response);
   response.render(
       JavaScriptReferenceHeaderItem.forReference(
           Application.get().getJavaScriptLibrarySettings().getJQueryReference()));
   response.render(
       StringHeaderItem.forString(WicketUtils.getCssForFavicon(getUrl("/favicon.ico"))));
   if (WebConfiguration.isDevelopmentMode() == true) {
     response.render(
         CssReferenceHeaderItem.forUrl(
             "mobile/jquery.mobile/jquery.mobile-" + JQUERY_MOBILE_VERSION + ".css"));
   } else {
     response.render(
         CssReferenceHeaderItem.forUrl(
             "mobile/jquery.mobile/jquery.mobile-" + JQUERY_MOBILE_VERSION + ".min.css"));
   }
   response.render(CssReferenceHeaderItem.forUrl("mobile/projectforge.css"));
   response.render(JavaScriptReferenceHeaderItem.forUrl("mobile/jquery.mobile/myconfig.js"));
   if (WebConfiguration.isDevelopmentMode() == true) {
     // response.renderJavaScriptReference("mobile/jquery.mobile/myconfig.js");
     response.render(
         JavaScriptReferenceHeaderItem.forUrl(
             "mobile/jquery.mobile/jquery.mobile-" + JQUERY_MOBILE_VERSION + ".js"));
   } else {
     // response.renderJavaScriptReference("mobile/jquery.mobile/myconfig.js");
     response.render(
         JavaScriptReferenceHeaderItem.forUrl(
             "mobile/jquery.mobile/jquery.mobile-" + JQUERY_MOBILE_VERSION + ".min.js"));
   }
 }
Esempio n. 14
0
 @Override
 protected void setValue(OClass entity, String critery, V value) {
   ODatabaseDocument db = OrientDbWebSession.get().getDatabase();
   db.commit();
   try {
     CustomAttributes custom;
     if (OClassPrototyper.CLUSTER_SELECTION.equals(critery)) {
       if (value != null) entity.setClusterSelection(value.toString());
     } else if ((CustomAttributes.ON_CREATE_FIELDS.getName().equals(critery))
         && (custom = CustomAttributes.fromString(critery)) != null) {
       custom.setValue(entity, value != null ? Joiner.on(",").join((List<String>) value) : null);
     } else if ((custom = CustomAttributes.fromString(critery)) != null) {
       custom.setValue(entity, value);
     } else if (OClassPrototyper.SUPER_CLASSES.equals(critery)) {
       if (value != null) entity.setSuperClasses((List<OClass>) value);
     } else {
       PropertyResolver.setValue(
           critery,
           entity,
           value,
           new PropertyResolverConverter(
               Application.get().getConverterLocator(), Session.get().getLocale()));
     }
   } finally {
     db.begin();
   }
 }
Esempio n. 15
0
 /**
  * Tests binding a single absolute package resource.
  *
  * @throws Exception
  */
 @Test
 public void bindAbsolutePackageResource() throws Exception {
   final SharedResources sharedResources = Application.get().getSharedResources();
   assertNotNull(
       "resource packaged1.txt should be available as a packaged resource",
       sharedResources.get(PackageResourceTest.class, "packaged1.txt", null, null, null, true));
 }
Esempio n. 16
0
 @Override
 protected void onConfigure() {
   super.onConfigure();
   AuthenticatedWebApplication app = (AuthenticatedWebApplication) Application.get();
   if (!AuthenticatedWebSession.get().isSignedIn()) {
     app.restartResponseAtSignInPage();
   }
 }
Esempio n. 17
0
 @Override
 protected void onBeforeRender() {
   if (app().isDebugMode()) {
     // strip Wicket tags in debug mode for jQuery DOM traversal
     Application.get().getMarkupSettings().setStripWicketTags(true);
   }
   super.onBeforeRender();
 }
Esempio n. 18
0
 @Override
 protected void renderHead(IHeaderResponse response, Class<?> cls) {
   super.renderHead(response, IsisBlobOrClobPanelAbstract.class); // don't use the subclass
   // also include JQuery
   response.render(
       JavaScriptHeaderItem.forReference(
           Application.get().getJavaScriptLibrarySettings().getJQueryReference()));
 }
Esempio n. 19
0
 public static ResourceReference getCKEditorJsReference() {
   if (Application.get().getConfigurationType().equals(RuntimeConfigurationType.DEVELOPMENT)) {
     log.info("Using non-optimized CKEditor sources.");
     return CKEditorConstants.CKEDITOR_SRC_JS;
   }
   log.info("Using optimized CKEditor sources");
   return CKEditorConstants.CKEDITOR_OPTIMIZED_JS;
 }
Esempio n. 20
0
 @Override
 protected void onAfterRender() {
   if (app().isDebugMode()) {
     // restore Wicket debug tags
     Application.get().getMarkupSettings().setStripWicketTags(false);
   }
   super.onAfterRender();
 }
 /**
  * Methods used to access the triggers queued for the behavior
  *
  * <p>The implementation uses a Map stored in the application, where the behavior id is the key,
  * because these triggers cannot be stored in component instance or the behavior itself, since
  * they may be serialized and deserialized.
  *
  * @param application the application in which the triggers are stored
  * @param id the id of the behavior
  * @return a List of triggers queued for the component
  */
 private static List<DelayedMethodCallList> getTriggers(final Application application, String id) {
   id = getPageId(application, id);
   ConcurrentMap<String, List<DelayedMethodCallList>> triggersById;
   synchronized (application) {
     triggersById = application.getMetaData(TRIGGERS_KEY);
     if (triggersById == null) {
       triggersById = new ConcurrentHashMap<String, List<DelayedMethodCallList>>();
       application.setMetaData(TRIGGERS_KEY, triggersById);
     }
   }
   List<DelayedMethodCallList> triggers = triggersById.get(id);
   if (triggers == null) {
     triggersById.putIfAbsent(id, new ArrayList<DelayedMethodCallList>());
     triggers = triggersById.get(id);
   }
   return triggers;
 }
Esempio n. 22
0
 @Override
 public Resource getDocumentThumbnail() {
   DocumentType docType = getMimeType().getDocumentType();
   if (DocumentType.PDF.equals(docType)) {
     ImageManager.IMAGE_TC_PDF.bind(Application.get());
     return ImageManager.IMAGE_TC_PDF.getResource();
   } else if (DocumentType.ZIP.equals(docType)) {
     ImageManager.IMAGE_TC_ZIP.bind(Application.get());
     return ImageManager.IMAGE_TC_ZIP.getResource();
   } else if (DocumentType.MSEXCEL.equals(docType)) {
     ImageManager.IMAGE_TC_EXCEL.bind(Application.get());
     return ImageManager.IMAGE_TC_EXCEL.getResource();
   } else if (DocumentType.MSPOWERPOINT.equals(docType)) {
     ImageManager.IMAGE_TC_POWERPOINT.bind(Application.get());
     return ImageManager.IMAGE_TC_POWERPOINT.getResource();
   } else if (DocumentType.MSWORD.equals(docType)) {
     ImageManager.IMAGE_TC_WORD.bind(Application.get());
     return ImageManager.IMAGE_TC_WORD.getResource();
   } else if (DocumentType.TEXT.equals(docType)) {
     ImageManager.IMAGE_TC_TEXT.bind(Application.get());
     return ImageManager.IMAGE_TC_TEXT.getResource();
   } else if (DocumentType.CSV.equals(docType)) {
     ImageManager.IMAGE_TC_TEXT.bind(Application.get());
     return ImageManager.IMAGE_TC_TEXT.getResource();
   }
   return null;
 }
Esempio n. 23
0
 /**
  * Url encodes a string
  *
  * @param string string to be encoded
  * @return encoded string
  */
 public static String urlEncode(String string) {
   try {
     return URLEncoder.encode(
         string, Application.get().getRequestCycleSettings().getResponseRequestEncoding());
   } catch (UnsupportedEncodingException e) {
     log.error(e.getMessage(), e);
     return string;
   }
 }
Esempio n. 24
0
  /** Constructor. */
  protected MarkupCache() {
    application = Application.get();

    markupCache = newCacheImplementation();
    if (markupCache == null) {
      throw new WicketRuntimeException("The map used to cache markup must not be null");
    }

    markupKeyCache = newCacheImplementation();
  }
    public void doFilter(ServletRequest request, ServletResponse response)
        throws IOException, ServletException {
      if (Application.exists() == false) {
        throw new AssertionFailedError("The application is not available!");
      }

      if (Session.exists() == false) {
        throw new AssertionFailedError("The session is not available!");
      }
    }
 /**
  * Invokes the method with the parameters on the given object.
  *
  * @see java.lang.reflect.Method#invoke(Object, Object[])
  * @param o the object on which the method should be called
  * @throws IllegalArgumentException
  * @throws IllegalAccessException
  * @throws InvocationTargetException
  */
 public void invoke(final Object o)
     throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
   final Application originalApplication = Application.get();
   try {
     ThreadContext.setApplication(_application);
     methods[m].invoke(o, parameters);
   } finally {
     ThreadContext.setApplication(originalApplication);
   }
 }
Esempio n. 27
0
 private boolean isInternalWicket(Request request) {
   Url url = request.getUrl();
   if (url.getSegments().size() > 0) {
     if (url.getSegments().get(0).equals((Application.get().getMapperContext().getNamespace()))) {
       // starts with wicket namespace - is an internal wicket url
       return true;
     }
   }
   return false;
 }
 /**
  * Returns the page behavior id corresponding the given behavior id. Only one behavior is actually
  * rendered on a page for the same updateInterval, to optimize the number of requests. Therefore
  * all timer channel behaviors of the same page are redirected to the same id, using this method.
  *
  * @param application the wicket application to which the behavior belong
  * @param id the id of the behavior for which the page behavior id should be found
  * @return the page behavior id corresponding the given behavior id.
  */
 private static String getPageId(final Application application, final String id) {
   ConcurrentMap<String, String> pageIdsById;
   synchronized (application) {
     pageIdsById = application.getMetaData(PAGE_ID_KEY);
     if (pageIdsById == null) {
       return id;
     }
   }
   final String pageId = pageIdsById.get(id);
   return pageId == null ? id : pageId;
 }
 @Override
 public String substitutePropertyExpressions(Component component, String string, IModel<?> model) {
   if (string != null && model != null) {
     return PropertyConverterVariableInterpolator.interpolate(
         string,
         model.getObject(),
         Application.get().getConverterLocator(),
         Session.get().getLocale());
   }
   return string;
 }
Esempio n. 30
0
  public static BricketApplication get() {
    Application application = Application.get();

    if (!(application instanceof BricketApplication)) {
      throw new WicketRuntimeException(
          "The application attached to the current thread is not a "
              + BricketApplication.class.getSimpleName());
    }

    return (BricketApplication) application;
  }