Package org.apache.wicket

Examples of org.apache.wicket.Resource


   * when initializing this component, extract all the relevant metadata from the ResponseMetadata object
   * and push it into the class's specific fields.
   */
  @Override
  protected void onInitialize() {
    Resource xmlFile = null;
    if (loc != null) {
      this.setPageName(loc.getLocation());
      xmlFile = loc.getSection().getXmlDocument().getXmlFile()
    }
    IResponseType thisType = getModelObject().getType();
View Full Code Here


    }
    return metadata;
  }
 
  public ResourceReference getRelativeRef (String src) {
    Resource xmlFile = ((XmlSection)getModel().getObject()).getXmlDocument().getXmlFile();
    if (xmlFile instanceof IRelativeLinkSource)
      return ((IRelativeLinkSource)xmlFile).getRelativeReference(src);
    throw new IllegalStateException("Can't find reference relative to file " + xmlFile);
  }
View Full Code Here

      hotSpotDetails.append("\"height\": " + component.height + ", ");
      hotSpotDetails.append("\"text\": " + "\"" + component.title + "\"" + ", ");
 
      if (component.imgSrc != null && !component.imgSrc.trim().equals("")) {
        // find the url of the image
        Resource xmlFile = xmlSectionModel.getObject().getXmlDocument().getXmlFile()
        ResourceReference imageResourceRef = ((IRelativeLinkSource)xmlFile).getRelativeReference(component.imgSrc);
        String imageUrl = RequestCycle.get().urlFor(imageResourceRef).toString();
        if (imageUrl.equals(null))
            log.warn("The URL for the hotspot image {} is not found", imageUrl);
       
View Full Code Here

    if (glossaryOn == false) {
      log.debug("Glossary is turned off");
    } else if (Strings.isEmpty(glossaryFileName)) {
      log.debug("No glossary file");
    } else { // when the glossary is on
      Resource glossaryResource;
      if (davServer != null) {
        glossaryResource = new DavResource(davServer, getContentDir() + "/" + glossaryFileName);
      } else {
        glossaryResource = new FileResource(new File(getContentDir(), glossaryFileName));
      }
      final XmlDocument glossaryDoc = xmlService.loadXmlDocument("glossary", glossaryResource, new DtbookParser(), null);
     
      // Set up Glossary
      Databinder.ensureSession(new SessionUnit() {
        public Object run(Session sess) {
          glossary = GlossaryService.get().parseXmlGlossaryDocument(glossaryDoc);
          return null;
        }
      });
    }
       
    // Load student content files
    String fileList = appProperties.getProperty("isi.studentContentFiles", DEFAULT_STUDENT_CONTENT_FILE_NAMES).trim();
    studentContentFiles = fileList.split("\\s*,\\s*");   
    documentObservers.add(new XmlDocumentObserver(getSectionElement(), getPageElement())); // Use set so sub-classed applications can add to it as well
    for (String file : studentContentFiles) {
      Resource resource;
      if (davServer != null) {
        log.debug("attempting to load DavResource file = {}", getContentDir() + "/" + file);
        log.debug("loading the DavResource on the Server = {}", davServer);
        resource = new DavResource(davServer, getContentDir() + "/" + file);
      } else {
        log.debug("attempting to load Resource file = {}", getContentDir() + "/" + file);
        resource = new FileResource(new File(getContentDir(), file));
      }
      XmlDocument doc = xmlService.loadXmlDocument(file, resource, new DtbookParser(), documentObservers);
      studentContent.add(doc);
    }
   
    // Load email content files
    if (emailOn) {
      String emailFileName = EMAIL_FILE_NAME;         
      Resource emailResource;
      if (davServer != null) {
        emailResource = new DavResource(davServer, getContentDir() + "/" + emailFileName);
      } else {
        emailResource = new FileResource(new File(getContentDir(), emailFileName));
      }
View Full Code Here

    if (pathInfo.startsWith(WebRequestCodingStrategy.RESOURCES_PATH_PREFIX))
    {

      final String resourceReferenceKey = pathInfo.substring(WebRequestCodingStrategy.RESOURCES_PATH_PREFIX.length());

      Resource resource = null;
      WebRequestCycle requestCycle = null;

      boolean externalCall = !Application.exists();
      try
      {
        // if called externally (i.e. WicketServlet) we need to set the thread local here
        // AND clean it up at the end of the request
        if (externalCall)
        {
          Application.set(webApplication);
        }

        // Try to find shared resource
        resource = webApplication.getSharedResources().get(resourceReferenceKey);

        // If resource found and it is cacheable
        if ((resource != null) && resource.isCacheable())
        {
          // first check the char encoding for getting the parameters
          checkCharacterEncoding(servletRequest);

          final WebRequest request = webApplication.newWebRequest(servletRequest);
          WebResponse response = new WebResponse();
          // create a request cycle if not already there.
          if (RequestCycle.get() == null)
          {
            requestCycle = (WebRequestCycle)webApplication.newRequestCycle(request,
              response);
          }
          // make the session available.
          Session.findOrCreate(request, response);


          // decode the parameters so that shared resource params are also decoded
          // a request cycle is then needed. (see above)
          RequestParameters rp = RequestCycle.get()
            .getProcessor()
            .getRequestCodingStrategy()
            .decode(request);
          // Set parameters from servlet request
          resource.setParameters(rp.getParameters());

          // Get resource stream
          IResourceStream stream = resource.getResourceStream();

          // Get last modified time from stream
          Time time = stream.lastModifiedTime();

          try
          {
            stream.close();
          }
          catch (IOException e)
          {
            // ignore
          }

          return time != null ? time.getMilliseconds() : -1;
        }
      }
      catch (AbortException e)
      {
        return -1;
      }
      finally
      {
        if (resource != null)
        {
          resource.setParameters(null);
        }
        if (externalCall)
        {
          // Clean up thread local application if this was an external call
          // (if not, doFilter will clean it up)
View Full Code Here

          private static final long serialVersionUID = 1L;

          @Override
          protected Resource newResource() {
            Resource r = ref.getResource();
            if (r == null) {
              throw new WicketRuntimeException("ResourceReference wasn't bound to application yet");
            }
            return r;
          }
View Full Code Here

  public void respond(RequestCycle requestCycle)
  {
    Application application = requestCycle.getApplication();
    SharedResources sharedResources = application.getSharedResources();
    final String resourceKey = getRequestParameters().getResourceKey();
    Resource resource = sharedResources.get(resourceKey);

    // try to lazily register
    if (resource == null)
    {
      int ix = resourceKey.indexOf('/');
      if (ix != -1)
      {
        String className = resourceKey.substring(0, ix);
        IClassResolver resolver = application.getApplicationSettings().getClassResolver();
        Class scope = null;
        try
        {
          // First try to match mounted resources.
          scope = Application.get().getSharedResources().getAliasClass(className);

          // If that fails, resolve it as a fully qualified class
          // name.
          if (scope == null)
          {
            scope = resolver.resolveClass(className);
          }
          final CharSequence escapeString = application.getResourceSettings()
            .getParentFolderPlaceholder();
          // get path component of resource key, replace' ..' with escape sequence to
          // prevent crippled urls in browser
          String path = resourceKey.substring(ix + 1);
          path = Strings.replaceAll(path, escapeString, "..").toString();

          if (PackageResource.exists(scope, path, null, null))
          {
            PackageResource packageResource = PackageResource.get(scope, path);
            if (sharedResources.get(resourceKey) == null)
            {
              sharedResources.add(scope, path, null, null, packageResource);
            }
            resource = packageResource;
          }
        }
        catch (Exception e)
        {
          // besides logging, ignore exception; after this an error
          // will be returned that the resource could not be retrieved
          log.error("unable to lazily register shared resource " + resourceKey, e);
        }
      }
    }

    // if resource is still null, it doesn't exist
    if (resource == null)
    {
      Response response = requestCycle.getResponse();
      if (response instanceof WebResponse)
      {
        ((WebResponse)response).getHttpServletResponse().setStatus(
          HttpServletResponse.SC_NOT_FOUND);
        log.error("shared resource " + resourceKey + " not found");
        return;
      }
      else
      {
        throw new WicketRuntimeException("shared resource " + resourceKey + " not found");
      }
    }

    // set request parameters if there are any
    if (requestParameters != null)
    {
      resource.setParameters(requestParameters.getParameters());
    }

    // let the resource handle the request
    resource.onResourceRequested();
  }
View Full Code Here

  public ResourceReference resourceReference(final Map variables)
  {
    final String uniqueName = sharedResourceName(variables);
    final String templateValue = template.asString(variables);
    final SharedResources sharedResources = Application.get().getSharedResources();
    final Resource resource = sharedResources.get(uniqueName);
    if (resource == null)
    {
      final Resource newResource = new Resource()
      {
        private static final long serialVersionUID = 1L;

        /**
         * @see org.apache.wicket.Resource#getResourceStream()
View Full Code Here

    if (pathInfo.startsWith(WebRequestCodingStrategy.RESOURCES_PATH_PREFIX))
    {

      final String resourceReferenceKey = pathInfo.substring(WebRequestCodingStrategy.RESOURCES_PATH_PREFIX.length());

      Resource resource = null;
      WebRequestCycle requestCycle = null;

      boolean externalCall = !Application.exists();
      try
      {
        // if called externally (i.e. WicketServlet) we need to set the thread local here
        // AND clean it up at the end of the request
        if (externalCall)
        {
          Application.set(webApplication);
        }

        // Try to find shared resource
        resource = webApplication.getSharedResources().get(resourceReferenceKey);

        // If resource found and it is cacheable
        if ((resource != null) && resource.isCacheable())
        {
          // first check the char encoding for getting the parameters
          checkCharacterEncoding(servletRequest);

          final WebRequest request = webApplication.newWebRequest(servletRequest);
          WebResponse response = new WebResponse();
          // create a request cycle if not already there.
          if (RequestCycle.get() == null)
          {
            requestCycle = (WebRequestCycle)webApplication.newRequestCycle(request,
              response);
          }
          // make the session available.
          Session.findOrCreate(request, response);


          // decode the parameters so that shared resource params are also decoded
          // a request cycle is then needed. (see above)
          RequestParameters rp = RequestCycle.get()
            .getProcessor()
            .getRequestCodingStrategy()
            .decode(request);
          // Set parameters from servlet request
          resource.setParameters(rp.getParameters());

          // Get resource stream
          IResourceStream stream = resource.getResourceStream();

          // Get last modified time from stream
          Time time = stream.lastModifiedTime();

          try
          {
            stream.close();
          }
          catch (IOException e)
          {
            // ignore
          }

          return time != null ? time.getMilliseconds() : -1;
        }
      }
      catch (AbortException e)
      {
        return -1;
      }
      finally
      {
        if (resource != null)
        {
          resource.setParameters(null);
        }
        if (externalCall)
        {
          // Clean up thread local application if this was an external call
          // (if not, doFilter will clean it up)
View Full Code Here

   * @throws Exception
   */
  public void testLenientPackageResourceMatching() throws Exception
  {
    final SharedResources sharedResources = Application.get().getSharedResources();
    Resource invalidResource = new PackageResource(PackageResourceTest.class, "packaged3.txt",
      Locale.ENGLISH, null);
    assertNotNull(
      "resource packaged3.txt SHOULD be available as a packaged resource even if it doesn't exist",
      invalidResource);

    assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1.txt", null, null));
    assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1.txt", Locale.CHINA,
      null));
    assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1.txt", Locale.CHINA,
      "foo"));
    assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1.txt", null, "foo"));
    assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_en.txt", null, null));
    assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_en_US.txt", null,
      null));
    assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_en_US.txt", null,
      "foo"));
    assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_en_US.txt",
      Locale.US, null));
    assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_en_US.txt",
      Locale.CANADA, null));
    assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_en_US.txt",
      Locale.CHINA, null));
    assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_foo_bar_en.txt",
      null, null));
    assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_foo_bar_en_US.txt",
      null, null));
    assertTrue(PackageResource.exists(PackageResourceTest.class,
      "packaged1_foo_bar_en_US_MAC.txt", null, null));

    try
    {
      invalidResource.getResourceStream();
      fail("Should have raised an AbortException");
    }
    catch (AbortException e)
    {
    }
View Full Code Here

TOP

Related Classes of org.apache.wicket.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.