/**
   * 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;
  }
Ejemplo n.º 2
0
  @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);
  }
Ejemplo n.º 3
0
  @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);
  }
Ejemplo n.º 4
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));
 }
Ejemplo n.º 5
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();
   }
 }
 @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"));
   }
 }
Ejemplo n.º 7
0
 @Override
 protected void onAfterRender() {
   if (app().isDebugMode()) {
     // restore Wicket debug tags
     Application.get().getMarkupSettings().setStripWicketTags(false);
   }
   super.onAfterRender();
 }
Ejemplo n.º 8
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();
 }
Ejemplo n.º 9
0
 @Override
 protected void onConfigure() {
   super.onConfigure();
   AuthenticatedWebApplication app = (AuthenticatedWebApplication) Application.get();
   if (!AuthenticatedWebSession.get().isSignedIn()) {
     app.restartResponseAtSignInPage();
   }
 }
Ejemplo n.º 10
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()));
 }
Ejemplo n.º 11
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;
 }
Ejemplo n.º 12
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;
 }
Ejemplo n.º 13
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;
   }
 }
Ejemplo n.º 14
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;
 }
 /**
  * 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;
 }
Ejemplo n.º 16
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();
  }
 /**
  * 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);
   }
 }
Ejemplo n.º 18
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;
 }
Ejemplo n.º 19
0
  private void onInternalDetach() {
    if (Session.exists()) {
      Session.get().internalDetach();
    }

    if (Application.exists()) {
      IRequestLogger requestLogger = Application.get().getRequestLogger();
      if (requestLogger != null) requestLogger.performLogging();
    }
  }
 @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;
 }
Ejemplo n.º 21
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;
  }
Ejemplo n.º 22
0
  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));
 }
 @Override
 public List<HeaderItem> getDependencies() {
   List<HeaderItem> dependencies = new ArrayList<>();
   Iterable<? extends HeaderItem> superDeps = super.getDependencies();
   for (HeaderItem dep : superDeps) {
     dependencies.add(dep);
   }
   dependencies.add(
       JavaScriptHeaderItem.forReference(
           Application.get().getJavaScriptLibrarySettings().getWicketAjaxReference()));
   return dependencies;
 }
 @Override
 public List<HeaderItem> getDependencies() {
   List<HeaderItem> dependencies = new ArrayList<>();
   for (Iterator<? extends HeaderItem> iterator = super.getDependencies().iterator();
       iterator.hasNext(); ) {
     HeaderItem headerItem = iterator.next();
     dependencies.add(headerItem);
   }
   dependencies.add(
       JavaScriptHeaderItem.forReference(
           Application.get().getJavaScriptLibrarySettings().getJQueryReference()));
   return dependencies;
 }
Ejemplo n.º 26
0
  /**
   * Runs the configured {@link IResponseFilter}s over the constructed Ajax response
   *
   * @param contentResponse the Ajax {@link Response} body
   * @return filtered response
   */
  private AppendingStringBuffer invokeResponseFilters(final StringResponse contentResponse) {
    AppendingStringBuffer responseBuffer = new AppendingStringBuffer(contentResponse.getBuffer());

    List<IResponseFilter> responseFilters =
        Application.get().getRequestCycleSettings().getResponseFilters();

    if (responseFilters != null) {
      for (IResponseFilter filter : responseFilters) {
        responseBuffer = filter.filter(responseBuffer);
      }
    }
    return responseBuffer;
  }
 /**
  * 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;
 }
Ejemplo n.º 28
0
 @Override
 protected String load() {
   Locale theLocale = locale;
   if (theLocale == null) {
     theLocale = Session.get().getLocale();
   }
   List<IStringResourceLoader> loaders =
       Application.get().getResourceSettings().getStringResourceLoaders();
   for (IStringResourceLoader loader : loaders) {
     String string =
         loader.loadStringResource(klass, key, theLocale, Session.get().getStyle(), null);
     if (StringUtils.isNotBlank(string)) {
       return string;
     }
   }
   return null;
 }
Ejemplo n.º 29
0
 private static String readResourceNoCache(Class scope, String file) {
   InputStream inputStream = null;
   try {
     final String path = Packages.absolutePath(scope, file);
     final IResourceStream resourceStream =
         Application.get().getResourceSettings().getResourceStreamLocator().locate(scope, path);
     inputStream = resourceStream.getInputStream();
     return Streams.readString(inputStream, "utf-8");
   } catch (ResourceStreamNotFoundException e) {
     throw new RuntimeException(
         String.format("Can't find resource \"%s.%s\"", scope.getName(), file), e);
   } catch (IOException e) {
     throw new RuntimeException(
         String.format("Can't read resource \"%s.%s\"", scope.getName(), file), e);
   } finally {
     Closeables.closeQuietly(inputStream);
   }
 }
Ejemplo n.º 30
0
 public String getObjectDeltaXml() {
   ObjectDeltaType objectDeltaType =
       taskDto.getExtensionPropertyRealValue(
           SchemaConstants.MODEL_EXTENSION_OBJECT_DELTA, ObjectDeltaType.class);
   if (objectDeltaType == null) {
     return null;
   }
   PrismContext prismContext = ((MidPointApplication) Application.get()).getPrismContext();
   try {
     return WebXmlUtil.stripNamespaceDeclarations(
         prismContext.serializeAnyData(
             objectDeltaType,
             SchemaConstants.MODEL_EXTENSION_OBJECT_DELTA,
             PrismContext.LANG_XML));
   } catch (SchemaException e) {
     throw new SystemException("Couldn't serialize object delta: " + e.getMessage(), e);
   }
 }