Examples of MediaResource


Examples of org.olat.core.gui.media.MediaResource

  /**
   * TODO: firefox 2.0 has an strange error when the iframe is loaded the browser requests the first file always twice
   * @param isPopUp
   */
  protected MediaResource deliverFile(String path, boolean isPopUp) {
    MediaResource mr;
    VFSLeaf vfsLeaf = null;
    VFSItem vfsItem = null;
    //if directory gets renamed root becomes null
    if (rootDir == null) {
      return new NotFoundMediaResource("directory not found"+path);
View Full Code Here

Examples of org.olat.core.gui.media.MediaResource

  public MediaResource getAsyncMediaResource(UserRequest ureq) {
    // is the path to the desired resource (put together by the webbrowser by
    // combining latesturl and relative link)
    String moduleURI = ureq.getModuleURI();

    MediaResource mr = null;

    //FIXME:fg: FIXED:fj:  HtmlBodyParser now also skips the <link rel="next" etc. links
    //put together under "known issues" etc. --- not here in this
    // code, but make sure that the html generated by docbook for the help
    // course does not contain the following link tags:
View Full Code Here

Examples of org.olat.core.gui.media.MediaResource

      if (event instanceof TableEvent) {
        TableEvent tEvent = (TableEvent) event;
        int row = tEvent.getRowId();
        if (CMD_DOWNLOAD.equals(tEvent.getActionId())) {
         
          MediaResource resource;
          if(row < versionedFile.getVersions().getRevisions().size()) {
            //restore current, do nothing
            VFSRevision version = versionedFile.getVersions().getRevisions().get(row);
            resource = new VFSRevisionMediaResource(version, true);
          } else {
View Full Code Here

Examples of org.olat.core.gui.media.MediaResource

   
    // increase the timestamp, but not if we are in loadperformancemode: then all url's have
    // to work independant of previous ones -> when no increase: timestamp is always the same here
    boolean incTimestamp = !GUIInterna.isLoadPerformanceMode();
   
    MediaResource mr = null;
    final boolean isDebugLog = Tracing.isDebugEnabled(Window.class);
    StringBuilder debugMsg = null;
    long debug_start = 0;
    if (isDebugLog) {
      debug_start = System.currentTimeMillis();
      debugMsg = new StringBuilder("::winst:");
    }
    synchronized (this) { //o_clusterOK by:fj
      // sync dispatching per window to avoid rendering problems
      // when user repeateadly presses reload, and also to distribute bandwidth more
      // evenly.
      // postcondition: each controller's events are called by one gui-thread at a time only.
     
      GlobalSettings gsettings = wbackofficeImpl.getGlobalSettings();
      boolean bgEnab = gsettings.getAjaxFlags().isIframePostEnabled();
      //System.out.println("in window:");
      // -------------------------
      // ----- ajax mode ---------
      // -------------------------
      if (bgEnab && (ureq.getMode() & 1) == 1) {
        // first check on "ajax-command-was-not-in-hidden-iframe hint" -> if so, rerender the current window
        if (ureq.getParameter("o_win_jsontop") != null) {       
          renderOnly = true;
        } else {
          try {
           
            // if target in background (m = mode , 0.bit set)
            // 1.) do dispatch to component if component timestamp ok
           
            //REVIEW:PB: this will be the code allowing back forward navigation
            //--> boolean inlineAfterBackForward = false;
            // FIXME:fj:b avoid double traversal to find component again below         
            String s_compID = ureq.getComponentID();
            if (s_compID == null) throw new AssertException("no component id found in req:" + ureq.toString());
            // throws NumberFormatException if not a number
            long compID = Long.parseLong(s_compID);
            List foundPath = new ArrayList(10);
            Component target = ComponentHelper.findDescendantOrSelfByID(getContentPane(), compID, foundPath);
            boolean validForDispatching;
            if (target != null) { // the target was found
              int tst = target.getTimestamp();
              String cTimest = Integer.toString(tst, 10);
              String urlCTimest = ureq.getComponentTimestamp();
              validForDispatching = cTimest.equals(urlCTimest);
              if (!validForDispatching && Tracing.isDebugEnabled(this.getClass()) ) {
                Tracing.logDebug("Invalid timestamp: ureq.compid:"+ureq.getComponentID()+" ureq.win-ts:"+ureq.getTimestampID()+" ureq.comp-ts:"+ureq.getComponentTimestamp() + " target.timestamp:" + cTimest + " target=" + target, this.getClass());
              }
            } else {
              // the component was not found in the rendertree anymore.
              // this can happen e.g. on quick double-clicks, so that the dom-replacement-command never reaches the client.
              if (Tracing.isDebugEnabled(this.getClass())) Tracing.logDebug("no ajax dispatch: component not found (target=null)",this.getClass());
              validForDispatching = false;
            }
           
            /*
             * REVIEW:PB: this will be the code allowing back forward navigation
             * so far it is disabled
             * window fires OLDTIMESTAMPCALL event
             * --->
            if (!validForDispatching) {
              // user clicked back or forward after an ajax request which causes the history of the hidden iframe to go back one and post
              // an old request which has an old timestamp.
              int diff = findInHistory(ureq);
              // if not found in history: probably the case that a link got opened in a new window by the user by using the right-mouse-button.
              // in this case, we later send a full page reload
              //System.out.println("ajax back: diff "+diff);
              if (diff != 0) {
                wbackofficeImpl.browserBackOrForward(ureq, diff);
                inline = true;
                inlineAfterBackForward = true;
              }
            }
            <-------- */               
           
            // 2.) collect dirty components (top-down, return from sub-path when first dirty node met)
            // 3.) return to sender...
            boolean didDispatch = false;
            if (validForDispatching) {
              didDispatch = doDispatchToComponent(ureq, null)// FIXME:fj:c enable time stats for ajax-mode
           
             
            MediaResource mmr = null;
            //REVIEW:PB: this will be the code allowing back forward navigation
            //-----> if (didDispatch || inlineAfterBackForward) {
            if (didDispatch || !validForDispatching) {
              if (validForDispatching) {
                Window ww = ureq.getDispatchResult().getResultingWindow();
                if (ww != null) {
                  // a link which causes a new window to be openend should always
                  // a) have the normal mode set (not the ajax mode)
                  // b) have the target="_blank" attribute
                  // reason: in non-ajax-mode, a link has to know beforehand whether it opens in a new window or not.
                  // FIXME:fj:c think about bodyOnLoad -> win.open(new window url)
                  throw new AssertException("a link in ajax mode should never result in a new window");
                }
                mmr = ureq.getDispatchResult().getResultingMediaResource();
                if (mmr == null) {
                  inline = true;
                } else {
                  inline = false;
                }
              } //else {
                // not valid: fire oldtimestamp event and later rerender
                // fire OLDTIMESTAMPCALL after validating the components
                // because in the validating phase the voting for the
                // GUIMessage place is done.
                //}
             
             
              //REVIEW:PB: this will be the code allowing back forward navigation
              //-----> if (inline) {
              if (inline || !validForDispatching) {
                Container top = getContentPane();
                // always validate here, since we are never in the case of just rerendering (we are in the bg iframe)
                ValidatingVisitor vv = new ValidatingVisitor(gsettings, jsAndCssAdder);
                ComponentTraverser ct = new ComponentTraverser(vv, top, false);
                ct.visitAll(ureq);
                wbackofficeImpl.fireCycleEvent(Window.AFTER_VALIDATING);
                //fire possible OLDTIMESTAMPCALL after validation
                //validation does a voting about where the GUIMsg is rendered
                if(!validForDispatching){
                  // not valid: fire oldtimestamp event and later rerender
                  fireEvent(ureq, OLDTIMESTAMPCALL);
                }
                ValidationResult vr = vv.getValidationResult();
   
                boolean newJsCssAdded= vr.getJsAndCSSAdder().finishAndCheckChange();
                String newModUri = vr.getNewModuleURI();
                // !validForDispatching ||
                if (newJsCssAdded || newModUri != null) {
                  // send 302 redirect so the ajax-iframe's parent window gets reloaded to either include new js/css or to prepare the address bar
                  // url for asynchronous requests when delivering inline-contentpackaging.
                  // set window id to cur id, timestamp to current timestamp,
                  // component id to -1 -> indicates rerender
                  String uri = buildURIForRedirect(newModUri); // newModUri == null in case "just" new css or js libs have been added
                  // set this only for the first request (the .html request), but clear it afterwards for asyncmedia
                  validatingCausedRerendering = true;
                  Command rmrcom = CommandFactory.createParentRedirectTo(uri);
                  wbackofficeImpl.sendCommandTo(rmrcom);
                  //OLAT-4563: so the timestamp is not incremented, we do only a redirect
                  setDirty(false);
                } else {
                  // inline rendering by selectively replacing the dirty components in the dom tree of the browser
                  wbackofficeImpl.fireCycleEvent(Window.BEFORE_INLINE_RENDERING);
         
                  // Start by preparing the client: must be called prior to the
                  // other commands to not overwrite the form o2c dirty flag
                  // wich might be set by later commands
                  if (!this.isDirty()) {
                    wbackofficeImpl.sendCommandTo(CommandFactory.createPrepareClientCommand(wbackofficeImpl.getBusinessControlPath()));
                  }
                 
                  // Add the js and css files and related pre init commands
                  Command jscsscom = jsAndCssAdder.extractJSCSSCommand();
                  wbackofficeImpl.sendCommandTo(jscsscom);
                 
                  // Add the DOM replacement commands. Must be called after the
                  // js and css commands. Inline JS scripts might have
                  // dependencies to previously loaded js libs
                  if (this.isDirty()) {
                    // special case: when the window itself is dirty we require
                    // a full page refresh in any case
                    String reRenderUri = buildURIFor(this, timestampID, null);
                    Command rmrcom = CommandFactory.createParentRedirectTo(reRenderUri);
                    wbackofficeImpl.sendCommandTo(rmrcom);
                    this.setDirty(false);
                  } else {
                    // check for dirty child components in the component tree
                    Command co = handleDirties();
                   
                    //DUMP FOR EACH CLICK THE CURRENT JumpInPath -> for later usage and debugging.
                    //System.err.println("V^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^V");
                    WindowControl current = (WindowControl)wbackofficeImpl.getWindow().getAttribute("BUSPATH");
                    //System.err.println(current != null ? JumpInManager.getRestJumpInUri(current.getBusinessControl()) : "NONE");
                    //System.err.println("T^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^T");
                    wbackofficeImpl.fireCycleEvent(AFTER_INLINE_RENDERING);
                    if (co != null) { // see method handleDirties for the rare case of co == null even if there are dirty components;
                      wbackofficeImpl.sendCommandTo(co);
                    }
                  }
                }
              } else { // not inline
                if(!validForDispatching){
                  // not valid: fire oldtimestamp event
                  fireEvent(ureq, OLDTIMESTAMPCALL);
                }
                // not inline, new mediaresource
                // send it to the parent window (e.g. an excel download, but could also be a 302 redirect)
                // if the browser has e.g. pdf configured to be displayed inline, we want it to fill the whole area (self window), not the hidden iframe.
                // the same for 302.
                // -> send a command which offers a new location for the main window.
                // create a mapper which maps this mediaresource, and serves it once only
                MediaResourceMapper extMRM = new MediaResourceMapper();
                extMRM.setMediaResource(mmr);
                //FIXME:fj:b deregister old mapper, or reuse current one
                String res = MapperRegistry.getInstanceFor(ureq.getUserSession()).register(extMRM)+"/";
                // e.g. res = /olat/m/10001/
                Command rmrcom = CommandFactory.createParentRedirectForExternalResource(res);
                wbackofficeImpl.sendCommandTo(rmrcom);
              }
            } else { // not dispatched
              Tracing.logDebug("Found a valid timestamp but could not dispatch to component: ureq.compid:"+ureq.getComponentID()+" ureq.win-ts:"+ureq.getTimestampID()+" ureq.comp-ts:"+ureq.getComponentTimestamp() + " target.timestamp:" + target.getTimestamp() + " target=" + target, this.getClass());
              String reRenderUri = buildURIFor(this, timestampID, null);
              Command rmrcom = CommandFactory.createParentRedirectTo(reRenderUri);
              wbackofficeImpl.sendCommandTo(rmrcom);
            }
            MediaResource jsonmr = wbackofficeImpl.extractCommands(true);
            ServletUtil.serveResource(request, response, jsonmr);
          } catch (Throwable th) {
            // in any case, try to inform the user appropriately.
            // a) error while dispatching (e.g. db problem, npe, ...)
            // b) for inline: error while validating or json-rendering dirty components.
           
            // since an error has occured for a request which is targeted in the background iframe, we need to redirect to the error window.
            // create the error window
            try {
              Tracing.logDebug("Error in Window, rollback", getClass());
              DBFactory.getInstance().rollback();
           
              ChiefController msgcc = MsgFactory.createMessageChiefController(ureq, th);
              Window errWindow = msgcc.getWindow();
              // register window
              Windows.getWindows(ureq).registerWindow(errWindow);
              // redirect to the error window
              String newWinUri = buildRenderOnlyURIFor(errWindow);
              Command rmrcom = CommandFactory.createParentRedirectTo(newWinUri);
              wbackofficeImpl.sendCommandTo(rmrcom);
              MediaResource jsonmr = wbackofficeImpl.extractCommands(true);
              ServletUtil.serveResource(request, response, jsonmr);
            } catch (Throwable anotherTh) {
              Tracing.logError("Exception while handling exception!!!!", anotherTh, this.getClass());
            }
          }
          return;
        }
      }
     
      // -------------------------
      // ----- standard mode -----
      // -------------------------
      if (renderOnly || timestampID == null) {
        inline = true;
        validate = true;
      } else if (validatingCausedRerendering && timestampID.equals("-1")) {
        // the first request after the 302 redirect cause by a component validation
        // -> just rerender, but clear the flag for further async media requests
        validatingCausedRerendering = false;
        inline = true;
        validate = false; // no need to revalidate right now
        checkNewWindow = false;
        dispatch = false;
      else {
        // [POST: !renderOnly && timestampID != null]
        // if we had a inline rendering at least once (latestTimestamp is
        // set), then check for an old timestamp
        //System.out.println("dispatch normal: compid:"+ureq.getComponentID()+" win-ts:"+ureq.getTimestampID()+" comp-ts:"+ureq.getComponentTimestamp());
        if (latestTimestamp != null && !timestampID.equals(latestTimestamp)) {
          // this is not a link from the latest rendering, but from a previous
          // one, since it has a wrong timestamp parameter -> check for
          // asynchronous media
          if (asyncMediaResponsible == null) { // no async resp.
            // assume it to be a link from an old window (using browser back or
            // "open in new
            // window/tab" in the browser).
            if ((componentID != null && componentID.equals("-1")) || (ureq.getParameter("o_winrndo") != null)) {
              // just rerender
            else {
              // not a valid timestamp -> most likely a browser back or forward event (or a copy/paste of a url) ->

              // fire event to listening chiefcontroller
              fireEvent(ureq, OLDTIMESTAMPCALL);
              /*
               *
               * REVIEW:PB: this will be the code allowing back forward navigation
               * ---->
              // look at the timestamps more thoroughly.
              if (!timestampID.equals("-1")) {
                int diff = findInHistory(ureq);
                // diff == 0 -> reload (->ignore, so it will cause a simple rerendering)
                // diff < 0  -> browser-back
                // diff > 0  -> browser-forward
                //System.out.println("!!!!(normal) back: diff "+diff);
                wbackofficeImpl.browserBackOrForward(ureq, diff);
              } // else a 302 redirect of the main window -> simply rerender
              if (ureq.getComponentID() != null) {
                //System.out.println("normal: compid:"+ureq.getComponentID()+" win-ts:"+ureq.getTimestampID()+" comp-ts:"+ureq.getComponentTimestamp());
              } else {
                //System.out.println("special url - no component part (e.g. 302 redirect because of new req. js / css) compid:"+ureq.getComponentID()+" win-ts:"+ureq.getTimestampID()+" comp-ts:"+ureq.getComponentTimestamp());
              }
              validate = true;
              <------------- */
            }
            // just rerender current window
            inline = true;
            // do not increment timestamp so that e.g. url in a iframe remain valid
            incTimestamp = false;
          } else {
            // some component will take care of it for the moment, so be it
            mr = asyncMediaResponsible.getAsyncMediaResource(ureq);
            if (mr == null) { // indicates inline rendering
              inline = true;
              checkNewWindow = true; // an inline rendered async link should be
              // able to produce a new window
              validate = true;
            } else { // serve the resource.
              // all flags remain at their default value
            }
          }
        } else {
          // latestTimestamp == null || timestampID.equals(latestTimestamp)
         
          dispatch = true;
          checkNewWindow = true;
          validate = true;       
        }
      }
      // end of simple flagging.
      long dstart = 0;
      if (isDebugLog) {
        dstart = System.currentTimeMillis();
        long syncIntroDiff = dstart - debug_start;
        debugMsg.append("sync_bdisp:").append(syncIntroDiff).append(LOG_SEPARATOR);
      }
     
      if (dispatch) {
        boolean didDispatch = doDispatchToComponent(ureq, debugMsg);
        if (isDebugLog) {
          long dstop = System.currentTimeMillis();
          long diff = dstop - dstart;
          debugMsg.append("disp_comp:").append(diff).append(LOG_SEPARATOR);
          //Tracing.logDebug("componentdispatchtime: " + (dstop - dstart), Window.class);
        }
        if (didDispatch) { // the component with the given id was found
          mr = ureq.getDispatchResult().getResultingMediaResource();
          if (mr == null) {
            inline = true;
          } else {
            inline = false;
          }
        } else {
          // component with id was not found -> probably asynchronous thread changed flow ->
          // just rerender
          inline = true;
          dispatch = false;
          checkNewWindow = false;
          validate = true;
        }

      }

      if (checkNewWindow) {
        Window resWindow = ureq.getDispatchResult().getResultingWindow();
        if (resWindow != null) {
          // register it first, if not done before
          Windows ws = Windows.getWindows(ureq);
          if (!ws.isRegistered(resWindow)) {
            resWindow.setUriPrefix(uriPrefix);
            ws.registerWindow(resWindow);
          }
          // render initial state of new window by redirecting (302) to the new
          // window id. needed for asyncronous data like images loaded
         
          // todo maybe better delegate window registry to the windowbackoffice?
          URLBuilder ubu = new URLBuilder(uriPrefix, resWindow.getInstanceId(), String.valueOf(resWindow.timestamp), resWindow.wbackofficeImpl);
          StringOutput sout = new StringOutput(30);
          ubu.buildURI(sout, null, null);
          mr = new RedirectMediaResource(sout.toString());
          ServletUtil.serveResource(request, response, mr);
          if (isDebugLog) {
            long diff = System.currentTimeMillis() - debug_start;
            debugMsg.append("rdirnw:").append(diff).append(LOG_SEPARATOR);
            Tracing.logDebug(debugMsg.toString(), Window.class);
          }
          return;
        }
      }

      if (inline) {
          // do inline rendering.
         
          Container top = getContentPane();
          // validate prior to rendering, but only if the timestamp was not null
          // /
          // the component just got dispatched
          if (validate) { // do not validate if a previous validate lead to a
            // redirect; validating makes no sense here
            //long t1 = System.currentTimeMillis();
            ValidatingVisitor vv = new ValidatingVisitor(gsettings, jsAndCssAdder);
            ComponentTraverser ct = new ComponentTraverser(vv, top, false);
            ct.visitAll(ureq);
            wbackofficeImpl.fireCycleEvent(Window.AFTER_VALIDATING);
            ValidationResult vr = vv.getValidationResult();
            String newModUri = vr.getNewModuleURI();

            vr.getJsAndCSSAdder().finishAndCheckChange(); // ignore the return value since we are just about rendering anyway
         
            if (newModUri != null) {
              // send 302 redirect without dispatching, but just rerender
              // inline.
              // set window id to cur id, timestamp to current timestamp,
              // component id to -1 -> indicates rerender
              String uri = buildURIForRedirect(newModUri);
              MediaResource mrr = new RedirectMediaResource(uri);
              // set this only for the first request (the .html request), but clear it afterwards for asyncmedia
              validatingCausedRerendering = true;
              ServletUtil.serveResource(request, response, mrr);
              if (isDebugLog) {
                long diff = System.currentTimeMillis() - debug_start;
View Full Code Here

Examples of org.olat.core.gui.media.MediaResource

      // after dispatching, commit (docu)
      DBFactory.getInstance().commit();
     
      // add the new URL to the browser history, but not if the klick resulted in a new browser window (a href .. target=...) or in a download (excel or such)
      DispatchResult dr = ureq.getDispatchResult();
      MediaResource tMr = dr.getResultingMediaResource();
      Window tWin = dr.getResultingWindow();
      if (tMr == null && tWin == null) {
        addToHistory(new HistoryEntry(ureq));
      }
      wbackofficeImpl.fireCycleEvent(END_OF_DISPATCH_CYCLE);
View Full Code Here

Examples of org.olat.core.gui.media.MediaResource

      if (event instanceof TableEvent) {
        TableEvent tEvent = (TableEvent) event;
        int row = tEvent.getRowId();
        if (CMD_DOWNLOAD.equals(tEvent.getActionId())) {
          VFSRevision version = getLastRevision(deletedFiles.get(row));
          MediaResource resource = new VFSRevisionMediaResource(version, true);
          ureq.getDispatchResult().setResultingMediaResource(resource);
        } else if (CMD_RESTORE.equals(tEvent.getActionId())) {
          VFSRevision version = getLastRevision(deletedFiles.get(row));
          if (VersionsManager.getInstance().restore(container, version)) {
            status = FolderCommandStatus.STATUS_SUCCESS;
View Full Code Here

Examples of org.olat.core.gui.media.MediaResource

   *
   * @param identity
   * @return imageResource portrait
   */
  public MediaResource getPortrait(Identity identity, String portraitName){
    MediaResource imageResource = null;
    File imgFile = new File(getPortraitDir(identity), portraitName);
    if (imgFile.exists()){
      imageResource = new FileMediaResource(imgFile)
    }
    return imageResource;
View Full Code Here

Examples of org.olat.core.gui.media.MediaResource

   *
   * @param identity
   * @return imageResource portrait
   */
  public MediaResource getPortrait(File uploadDir, String portraitName){
    MediaResource imageResource = null;
    File imgFile = new File(uploadDir, portraitName);
    if (imgFile.exists()){
      imageResource = new FileMediaResource(imgFile)
    }
    return imageResource;
View Full Code Here

Examples of org.olat.core.gui.media.MediaResource

    // OLAT-5243 related: deliverFile can last arbitrary long, which can cause the open db connection to timeout and cause errors,
    // hence we need to do an intermediateCommit here
    DBFactory.getInstance().intermediateCommit();

    // Create the resource to be delivered
    MediaResource resource = null;
    FeedManager manager = FeedManager.getInstance();

    if (path.isFeedType()) {
      // Only create feed if modified. Send not modified response else.
      Identity identity = getIdentity(path.getIdentityKey());
View Full Code Here

Examples of org.olat.core.gui.media.MediaResource

    // get a usersession-local mapper for images in this wiki
    Mapper contentMapper = new Mapper() {

      public MediaResource handle(String relPath, HttpServletRequest request) {
        VFSItem vfsItem = wikiContainer.resolve(relPath);
        MediaResource mr;
        if (vfsItem == null || !(vfsItem instanceof VFSLeaf)) mr = new NotFoundMediaResource(relPath);
        else mr = new VFSMediaResource((VFSLeaf) vfsItem);
        return mr;
      }
    };
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.