Package com.webobjects.appserver

Examples of com.webobjects.appserver.WOContext


   */
  public String fetchSavedQueryResultsLink() {
      StringBuffer url = new StringBuffer();
      // make a dummy context and nullify the appNumber.
      // there is no other easy way to generate a url with no appNumber and sessionID
      WOContext newContext = new WOContext(context().request());
      newContext._url().setApplicationNumber("-1");
     
      // 1) get protocol + servername + port
      newContext.request()._completeURLPrefix(url, false, 0);
     
      // 2) prepare request params
      NSMutableDictionary requestParams = new NSMutableDictionary();
      requestParams.setObjectForKey(pageConfiguration(), RequestParams.PageConfiguration);
      requestParams.setObjectForKey(d2wContext().entity().name(), RequestParams.EntityName);
      try {
          requestParams.setObjectForKey(URLEncoder.encode(selectedSavedQuery.name(), CharEncoding.UTF_8), RequestParams.SavedQueryName);
      } catch(UnsupportedEncodingException e) {
          log.warn("error generating bookmarkable url", e);
      }
     
      // 3) generate the rest of the url directActionName + request params
      String directActionName = (String) d2wContext().valueForKey("directActionNameToFetchSavedQueryResults");
      url.append(newContext.directActionURLForActionNamed(directActionName, requestParams));
     
      return url.toString();
  }
View Full Code Here


     * @param event logging event
     */
    public NSMutableDictionary composeExceptionPageDictionary(LoggingEvent event) {
        NSMutableDictionary result = new NSMutableDictionary();

        WOContext currentContext = ERXWOContext.currentContext();
        NSDictionary extraInformation = null;
        if (currentContext != null) {
            extraInformation = ERXApplication.erxApplication().extraInformationForExceptionInContext(null, currentContext);
            result.setObjectForKey(extraInformation, "extraInfo");
        }
View Full Code Here

  public ERAttachment attachment() {
    return (ERAttachment) valueForBinding("attachment");
  }

  public String attachmentUrl() {
    WOContext context = context();
    ERAttachment attachment = attachment();
    return ERAttachmentProcessor.processorForType(attachment).attachmentUrl(attachment, context.request(), context);
  }
View Full Code Here

    int bufferSize = 16384;

    WOApplication application = WOApplication.application();
    application.awake();
    try {
      WOContext context = application.createContextForRequest(request);
      WOResponse response = application.createResponseInContext(context);

      String sessionIdKey = application.sessionIdKey();
      String sessionId = (String) request.formValueForKey(sessionIdKey);
      if (sessionId == null) {
        sessionId = request.cookieValueForKey(sessionIdKey);
      }
      context._setRequestSessionID(sessionId);
      if (context._requestSessionID() != null) {
        application.restoreSessionWithID(sessionId, context);
      }

      try {
      final WODynamicURL url = request._uriDecomposed();
        final String requestPath = url.requestHandlerPath();
        final Matcher idMatcher = Pattern.compile("^id/(\\d+)/").matcher(requestPath);

        final Integer requestedAttachmentID;
        String requestedWebPath;

        final boolean requestedPathContainsAnAttachmentID = idMatcher.find();
    if (requestedPathContainsAnAttachmentID) {
          requestedAttachmentID = Integer.valueOf(idMatcher.group(1));
          requestedWebPath = idMatcher.replaceFirst("/");
        } else {
          // MS: This is kind of goofy because we lookup by path, your web path needs to
          // have a leading slash on it.
          requestedWebPath = "/" + requestPath;
          requestedAttachmentID = null;
        }


        try {
          InputStream attachmentInputStream;
          String mimeType;
          String fileName;
          long length;
          String queryString = url.queryString();
          boolean proxyAsAttachment = (queryString != null && queryString.contains("attachment=true"));

          EOEditingContext editingContext = ERXEC.newEditingContext();
          editingContext.lock();

          try {
            ERAttachment attachment = fetchAttachmentFor(editingContext, requestedAttachmentID, requestedWebPath);
           
            if (_delegate != null && !_delegate.attachmentVisible(attachment, request, context)) {
              throw new SecurityException("You are not allowed to view the requested attachment.");
            }
            mimeType = attachment.mimeType();
            length = attachment.size().longValue();
            fileName = attachment.originalFileName();
            ERAttachmentProcessor<ERAttachment> attachmentProcessor = ERAttachmentProcessor.processorForType(attachment);
            if (!proxyAsAttachment) {
              proxyAsAttachment = attachmentProcessor.proxyAsAttachment(attachment);
            }
            InputStream rawAttachmentInputStream = attachmentProcessor.attachmentInputStream(attachment);
            attachmentInputStream = new BufferedInputStream(rawAttachmentInputStream, bufferSize);
          } finally {
            editingContext.unlock();
          }
         
          response.setHeader(mimeType, "Content-Type");
          response.setHeader(String.valueOf(length), "Content-Length");

          if (proxyAsAttachment) {
            response.setHeader("attachment; filename=\"" + fileName + "\"", "Content-Disposition");
          }

          response.setStatus(200);
          response.setContentStream(attachmentInputStream, bufferSize, length);
        }
        catch (SecurityException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(403);
        }
        catch (NoSuchElementException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(404);
        }
        catch (FileNotFoundException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(404);
        }
        catch (IOException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(500);
        }

        return response;
      }
      finally {
        if (context._requestSessionID() != null) {
          WOApplication.application().saveSessionForContext(context);
        }
      }
    }
    finally {
View Full Code Here

  public ERAttachment attachment() {
    return (ERAttachment) valueForBinding("attachment");
  }

  public String attachmentUrl() {
    WOContext context = context();
    ERAttachment attachment = attachment();
    return ERAttachmentProcessor.processorForType(attachment).attachmentUrl(attachment, context.request(), context);
  }
View Full Code Here

        String message = null;
        if (component == null) {
            throw new IllegalStateException("Attempting to send a component email with a null component! From: "
                                            + title + " title: " + title);
        } else {
            WOContext context = component.context();
            // Emails should generate complete urls
            context.generateCompleteURLs();
            message = component.generateResponse().contentString();
        }
        return composeEmail(from, to, cc, bcc, title, message, ec);
    }
View Full Code Here

        }catch(WOPageNotFoundException exc){
            //Do nothing here since it is not mandatory to have a plain text version component
        }
        if(plainTextComponent!=null){
            EOKeyValueCodingAdditions.DefaultImplementation.takeValuesFromDictionary(plainTextComponent, bindings);
            WOContext context = plainTextComponent.context();
            context.generateCompleteURLs();
            result.setPlainText(plainTextComponent.generateResponse().contentString());
        }
        return result;
    }
View Full Code Here

                                                 WOComponent plainTextComponent,
                                                 EOEditingContext ec) {
        ERCMailMessage result = composeComponentEmail(from, to, cc, bcc, title, component, ec);
       
        if ( plainTextComponent != null ) {
            WOContext context = plainTextComponent.context();
           
            context.generateCompleteURLs();
            result.setPlainText(plainTextComponent.generateResponse().contentString());
        }
       
        return result;
    }
View Full Code Here

      String encoded = WOURLEncoder.encode(fileURL);
      String key = WOApplication.application().resourceRequestHandlerKey();
      if (WOApplication.application()._rapidTurnaroundActiveForAnyProject() && WOApplication.application().isDirectConnectEnabled()) {
        key = "_wr_";
      }
      WOContext context = (WOContext) request.valueForKey("context");
      String wodata = _NSStringUtilities.concat("wodata", "=", encoded);
      if (context != null) {
        completeURL = context.urlWithRequestHandlerKey(key, null, wodata);
      }
      else {
        StringBuilder sb = new StringBuilder(request.applicationURLPrefix());
        sb.append('/');
        sb.append(key);
View Full Code Here

   * 二つの状態を保存することでトランスアクション内の問題を防ぐことが可能になります。</p>
   * </span>
   */
  @Override
  public void savePage(WOComponent page) {
    WOContext context = context();
    if (ERXAjaxApplication.shouldNotStorePage(context)) {
      if (logger.isDebugEnabled()) logger.debug("Considering pageReplacementCache for " + context.request().uri() + " with contextID " + context.contextID());
      WORequest request = context.request();
      WOResponse response = context.response();
      String pageCacheKey = null;
      if (response != null) {
        pageCacheKey = response.headerForKey(ERXAjaxSession.PAGE_REPLACEMENT_CACHE_LOOKUP_KEY);
      }
      if (pageCacheKey == null && request != null) {
        pageCacheKey = request.headerForKey(ERXAjaxSession.PAGE_REPLACEMENT_CACHE_LOOKUP_KEY);
      }

      // A null pageCacheKey should mean an Ajax request that is not returning a content update or an expliclty not cached non-Ajax request
      if (pageCacheKey != null) {
        if (logger.isDebugEnabled()) logger.debug("Will use pageCacheKey " + pageCacheKey);
        String originalContextID = context.request().headerForKey(ERXAjaxSession.ORIGINAL_CONTEXT_ID_KEY);
        pageCacheKey = originalContextID + "_" + pageCacheKey;
        LinkedHashMap pageReplacementCache = (LinkedHashMap) objectForKey(ERXAjaxSession.PAGE_REPLACEMENT_CACHE_KEY);
        if (pageReplacementCache == null) {
          pageReplacementCache = new LinkedHashMap();
          setObjectForKey(pageReplacementCache, ERXAjaxSession.PAGE_REPLACEMENT_CACHE_KEY);
        }

        // Remove the oldest entry if we're about to add a new one and that would put us over the cache size ...
        // We do a CACHE_SIZE*2 here because for every page, we have to potentially store its previous contextid to prevent
        // race conditions, so there technically can be 2x cache size many pages in the cache.
        boolean removedCacheEntry = cleanPageReplacementCacheIfNecessary(pageCacheKey);
        if (!removedCacheEntry && pageReplacementCache.size() >= ERXAjaxSession.MAX_PAGE_REPLACEMENT_CACHE_SIZE * 2) {
          Iterator entryIterator = pageReplacementCache.entrySet().iterator();
          Map.Entry oldestEntry = (Map.Entry) entryIterator.next();
          entryIterator.remove();
          if (logger.isDebugEnabled()) logger.debug(pageCacheKey + "pageReplacementCache too large, removing oldest entry = " + ((TransactionRecord)oldestEntry.getValue()).key());
        }

        TransactionRecord pageRecord = new TransactionRecord(page, context, pageCacheKey);
        pageReplacementCache.put(context.contextID(), pageRecord);
        if (logger.isDebugEnabled()) logger.debug(pageCacheKey + " new context = " + context.contextID());
        if (logger.isDebugEnabled()) logger.debug(pageCacheKey + " = " + pageReplacementCache.keySet());

        ERXAjaxApplication.cleanUpHeaders(response);
      }
      else {
          // A null pageCacheKey should mean an Ajax request that is not returning a content update or an expliclty not cached non-Ajax request
        if (logger.isDebugEnabled()) logger.debug("Not caching as no pageCacheKey found");
      }
    }
    else {
      if (logger.isDebugEnabled()) logger.debug("Calling super.savePage for contextID " + context.contextID());
      super.savePage(page);
    }
  }
View Full Code Here

TOP

Related Classes of com.webobjects.appserver.WOContext

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.