コード例 #1
0
ファイル: ClassGetter.java プロジェクト: rsf/PonderUtilCore
 // TODO: replace with ReflectiveCache implementation.
 public static Object construct(Class clazz) {
   try {
     return clazz.newInstance();
   } catch (Throwable t) {
     throw UniversalRuntimeException.accumulate(
         t, "Could not create instance of " + clazz + " using default constructor");
   }
 }
コード例 #2
0
  private boolean handleHelperDone() {
    Logger.log.info("Done handling helper in view: " + viewParameters.viewID);

    // Removing hack
    tsh.clearTokenState(IN_HELPER_INDICATOR);

    ELReference elref =
        (ELReference)
            tsh.getTokenState(
                TOKEN_STATE_PREFIX
                    + viewParameters.viewID
                    + HelperViewParameters.POST_HELPER_BINDING);
    ParameterList paramlist =
        (ParameterList)
            tsh.getTokenState(
                TOKEN_STATE_PREFIX + viewParameters.viewID + POST_HELPER_BINDING_PARAMLIST);
    statePreservationManager.scopeRestore();
    if (paramlist != null) {
      for (int i = 0; i < paramlist.size(); i++) {
        UIParameter param = (UIParameter) paramlist.get(i);
        if (param instanceof UIELBinding) {
          bma.setBeanValue(
              ((UIELBinding) param).valuebinding.value,
              beanLocator,
              ((UIELBinding) param).rvalue,
              null,
              false);
        }
      }
    }
    String methodBinding = elref == null ? null : elref.value;
    Object beanReturn = null;
    if (methodBinding != null) {
      ShellInfo shells = bma.fetchShells(methodBinding, beanLocator, true);
      beanReturn = bma.invokeBeanMethod(shells, null);
    }

    ViewParameters originParams =
        (ViewParameters)
            tsh.getTokenState(
                TOKEN_STATE_PREFIX + viewParameters.viewID + POST_HELPER_ARI2_VIEWPARAMS);

    ARIResult ariresult = ari.interpretActionResult(viewParameters, beanReturn);
    ariprocessor.interceptActionResult(ariresult, originParams, ariresult);
    String urlToRedirectTo = ViewParamUtil.getAnyFullURL(ariresult.resultingView, vsh);
    try {
      response.sendRedirect(urlToRedirectTo);
    } catch (IOException e) {
      throw UniversalRuntimeException.accumulate(e, "Error redirecting to url: " + urlToRedirectTo);
    }
    return true;
  }
コード例 #3
0
  private boolean handleHelperStart() {
    Logger.log.info("Handling helper start in view: " + viewParameters.viewID);
    View view = new View();
    List producersList = viewResolver.getProducers(viewParameters.viewID);
    if (producersList.size() != 1) {
      throw new IllegalArgumentException(
          "There is not exactly one view producer for the view: " + viewParameters.viewID);
    }
    ViewComponentProducer vp = (ViewComponentProducer) producersList.get(0);

    statePreservationManager.scopeRestore();
    vp.fillComponents(view.viewroot, viewParameters, null);
    statePreservationManager.scopePreserve();
    UIOutput helperId = (UIOutput) view.viewroot.getComponent(HelperViewParameters.HELPER_ID);
    UICommand helperBinding =
        (UICommand) view.viewroot.getComponent(HelperViewParameters.POST_HELPER_BINDING);
    tsh.putTokenState(
        TOKEN_STATE_PREFIX + viewParameters.viewID + HelperViewParameters.HELPER_ID,
        helperId.getValue());
    if (helperBinding != null) {
      tsh.putTokenState(
          TOKEN_STATE_PREFIX + viewParameters.viewID + HelperViewParameters.POST_HELPER_BINDING,
          helperBinding.methodbinding);
      // Support for a ParameterList on the UICommand
      if (helperBinding.parameters != null) {
        tsh.putTokenState(
            TOKEN_STATE_PREFIX + viewParameters.viewID + POST_HELPER_BINDING_PARAMLIST,
            helperBinding.parameters);
      }
    }
    // We need to save these ViewParameters for ActionResultInterceptors
    tsh.putTokenState(
        TOKEN_STATE_PREFIX + viewParameters.viewID + POST_HELPER_ARI2_VIEWPARAMS, viewParameters);

    // Hack to know if we're in the helper
    tsh.putTokenState(IN_HELPER_INDICATOR, IN_HELPER_INDICATOR);

    String helperToolPath = bup.getBaseURL() + viewParameters.viewID + IN_HELPER_PATH;
    tsh.putTokenState(
        helperId.getValue() + Tool.HELPER_DONE_URL,
        bup.getBaseURL() + viewParameters.viewID + HELPER_FINISHED_PATH);

    try {
      response.sendRedirect(helperToolPath);
    } catch (IOException e) {
      throw UniversalRuntimeException.accumulate(
          e, "IOException when trying to redirect to helper tool");
    }

    return true;
  }
コード例 #4
0
ファイル: TextToHTMLRenderer.java プロジェクト: clhedrick/rsf
  /**
   * Copies text from input to output, converting newlines into XHTML &lt;br/&gt; elements. The
   * supplied streams WILL be closed!
   */
  public void copyReader(Reader r, PrintOutputStream pos) {
    BufferedReader br = new BufferedReader(r);
    XMLWriter xmlw = new XMLWriter(pos);
    try {
      while (true) {
        String line = br.readLine();

        if (line == null) break;
        xmlw.write(line);
        // TODO: make some kind of "XMLFilterWriter" architecture if necessary
        //        writeEncodeLinks(xmlw, line);
        xmlw.writeRaw("<br/>");
      }
    } catch (Throwable t) {
      throw UniversalRuntimeException.accumulate(t, "Error rendering text as HTML");
    } finally {
      StreamCloseUtil.closeReader(r);
      pos.close();
    }
  }
コード例 #5
0
  public boolean handle() {
    ZipViewParams zvp;
    if (viewparams instanceof ZipViewParams) {
      zvp = (ZipViewParams) viewparams;
    } else {
      return false;
    }
    log.debug("Handling zip");
    OutputStream resultsOutputStream = null;
    try {
      resultsOutputStream = response.getOutputStream();
    } catch (IOException ioe) {
      throw UniversalRuntimeException.accumulate(
          ioe, "Unable to get response stream for Download All Zip");
    }

    Assignment2 assignment = assignmentLogic.getAssignmentById(zvp.assignmentId);
    String siteTitle = externalLogic.getSiteTitle(assignment.getContextId());
    String zipFolderName = assignment.getTitle() + "-" + siteTitle;
    zipFolderName = zipExporter.escapeZipEntry(zipFolderName, "_");

    response.setHeader("Content-disposition", "inline; filename=" + zipFolderName + ".zip");
    response.setContentType("application/zip");

    zipExporter.getSubmissionsZip(resultsOutputStream, zvp.assignmentId);

    if (resultsOutputStream != null) {
      try {
        resultsOutputStream.close();
      } catch (IOException e) {
        log.warn("IOException attempting to close resultsOutputStream while downloading zip file");
      }
    }

    return true;
  }
コード例 #6
0
 public AnyViewParameters handleException(Exception e, ViewParameters viewparams) {
   if (viewParametersPredicate.accept(viewparams)) {
     try {
       if (e instanceof SecurityException || e instanceof PermissionException) {
         Logger.log.info("Sending HTTP status 401 for exception ", e);
         httpServletResponse.sendError(401, e.getLocalizedMessage());
       } else {
         Logger.log.info("Sending HTTP status 500 for exception ", e);
         httpServletResponse.sendError(500, e.getLocalizedMessage());
       }
       try { // Jetty will refuse to allow access to Writer after sendError
         e.printStackTrace(httpServletResponse.getWriter());
       } catch (IllegalStateException e3) {
         e.printStackTrace(new PrintStream(httpServletResponse.getOutputStream()));
       }
     } catch (Exception e2) {
       throw UniversalRuntimeException.accumulate(e2, "Error setting HTTP response code");
     }
     NoViewParameters togo = new NoViewParameters();
     togo.errorredirect = "1";
     return togo;
   }
   return null;
 }
コード例 #7
0
  private boolean handleHelperHelper(final String pathBeyondViewID) {
    Logger.log.info(
        "Handling helper in view: "
            + viewParameters.viewID
            + " pathBeyondViewID: "
            + pathBeyondViewID);

    String helperId =
        (String)
            tsh.getTokenState(
                TOKEN_STATE_PREFIX + viewParameters.viewID + HelperViewParameters.HELPER_ID);

    if (pathBeyondViewID.endsWith(".helper")) {
      int i = pathBeyondViewID.lastIndexOf('/');
      if (i >= 0) {
        String helperName = pathBeyondViewID.substring(i + 1);
        String toolName = pathBeyondViewID.substring(0, i);
        i = helperName.lastIndexOf('.');
        helperName = helperName.substring(0, i);
        Logger.log.debug("new helper name" + helperName);
        Logger.log.debug("tool name" + toolName);
        tsh.putTokenState(TOKEN_STATE_PREFIX + viewParameters.viewID + "orig-helper-id", helperId);
        tsh.putTokenState(
            TOKEN_STATE_PREFIX + viewParameters.viewID + "helper-tool-name", toolName);
        helperId = helperName;
        tsh.putTokenState(
            TOKEN_STATE_PREFIX + viewParameters.viewID + HelperViewParameters.HELPER_ID, helperId);
      }
    }

    String origToolName =
        (String) tsh.getTokenState(TOKEN_STATE_PREFIX + viewParameters.viewID + "helper-tool-name");
    if (origToolName != null && pathBeyondViewID.endsWith(origToolName)) {
      helperId =
          (String) tsh.getTokenState(TOKEN_STATE_PREFIX + viewParameters.viewID + "orig-helper-id");
      Logger.log.debug("returning to " + helperId);
      tsh.putTokenState(
          TOKEN_STATE_PREFIX + viewParameters.viewID + HelperViewParameters.HELPER_ID, helperId);
      tsh.clearTokenState(TOKEN_STATE_PREFIX + viewParameters.viewID + "helper-tool-name");
      tsh.clearTokenState(TOKEN_STATE_PREFIX + viewParameters.viewID + "orig-helper-id");
    }

    ActiveTool helperTool = activeToolManager.getActiveTool(helperId);

    String baseUrl = bup.getBaseURL();
    int hostStart = baseUrl.indexOf("://") + 3;
    int hostEnd = baseUrl.indexOf('/', hostStart);

    String contextPath = baseUrl.substring(hostEnd);
    contextPath += viewParameters.viewID;
    contextPath += IN_HELPER_PATH;
    String helperPathInfo = pathInfo[0] + "/" + pathInfo[1];

    request.removeAttribute(Tool.NATIVE_URL);

    // this is the forward call
    try {
      helperTool.help(request, response, contextPath, helperPathInfo);
    } catch (ToolException e) {
      throw UniversalRuntimeException.accumulate(
          e,
          "ToolException when trying to call help. HelperId: "
              + helperId
              + " contextPath: "
              + contextPath
              + " pathInfo: "
              + pathInfo);
    }

    return true;
  }
コード例 #8
0
  // This method is almost entirely dialect-invariant - awaiting final
  // factorisation of RenderSystem
  public int renderComponent(
      RenderSystemContext rsc, UIContainer context, UIComponent torendero, XMLLump lump) {
    int lumpindex = lump.lumpindex;
    XMLLump[] lumps = lump.parent.lumps;
    int nextpos = -1;
    XMLLump outerendopen = lump.open_end;
    XMLLump outerclose = lump.close_tag;

    nextpos = outerclose.lumpindex + 1;

    XMLLumpList payloadlist =
        lump.downmap == null ? null : lump.downmap.headsForID(XMLLump.PAYLOAD_COMPONENT);
    XMLLump payload = payloadlist == null ? null : payloadlist.lumpAt(0);

    boolean iselide = lump.rsfID.startsWith(XMLLump.ELISION_PREFIX);

    XMLLump endopen = outerendopen;
    XMLLump close = outerclose;
    XMLLump uselump = lump;

    HashMap attrcopy = new HashMap();
    attrcopy.putAll((payload == null ? uselump : payload).attributemap);
    attrcopy.remove(XMLLump.ID_ATTRIBUTE);

    TagRenderContext rendercontext =
        new TagRenderContext(
            attrcopy, uselump, endopen, close, rsc.pos, rsc.xmlw, nextpos, iselide);

    idRelationRewriter.rewrite(rsc.idrewritemap, rendercontext, context);

    // if there is no peer component, it might still be a static resource holder
    // that needs URLs rewriting.
    // we assume there is no payload component here, since there is no producer
    // ID that might govern selection. So we use "outer" indices.
    if (torendero == null) {
      if (lump.rsfID.indexOf(XMLLump.SCR_PREFIX) == (iselide ? 1 : 0)) {
        String scrname = lump.rsfID.substring(XMLLump.SCR_PREFIX.length() + (iselide ? 1 : 0));
        StaticComponentRenderer scr = scrc.getSCR(scrname);
        if (scr == null) {
          Logger.log.info(
              "Warning: unrecognised static component renderer reference with key "
                  + scrname
                  + " at lump "
                  + lump.toString());
          scr = NullRewriteSCR.instance;
        }
        int tagtype = RenderUtil.renderSCR(scr, rsc.collecteds, rendercontext);
        nextpos =
            tagtype == ComponentRenderer.LEAF_TAG
                ? outerclose.lumpindex + 1
                : outerendopen.lumpindex + 1;
      } else {
        if (rsc.debugrender) {
          renderDebugMessage(
              rsc,
              "Leaf component missing which was expected with template id "
                  + lump.rsfID
                  + " at "
                  + lump.toString());
        }
      }
    } else {
      // else there IS a component and we are going to render it. First make
      // sure we render any preamble.

      if (payload != null) {
        rendercontext.endopen = payload.open_end;
        rendercontext.close = payload.close_tag;
        rendercontext.uselump = payload;
        RenderUtil.dumpTillLump(lumps, lumpindex, payload.lumpindex, rsc.pos);
        lumpindex = payload.lumpindex;
      }

      rsc.IDassigner.adjustForID(attrcopy, torendero);
      decoratormanager.decorate(torendero.decorators, uselump.getTag(), attrcopy);

      // ALWAYS dump the tag name, this can never be rewritten. (probably?!)
      rendercontext.openTag();

      if (torendero instanceof UIBasicListMember) {
        torendero = RenderUtil.resolveListMember(rsc.view, (UIBasicListMember) torendero);
      }
      try {
        componentRenderer.renderComponent(torendero, rsc.view, rendercontext);
      } catch (Exception e) {
        throw UniversalRuntimeException.accumulate(
            e,
            "Error rendering component "
                + torendero.getClass()
                + " with full ID "
                + torendero.getFullID()
                + " at template location "
                + rendercontext.uselump);
      }
      // if there is a payload, dump the postamble.
      if (payload != null) {
        // the default case is initialised to tag close
        if (rendercontext.nextpos == nextpos) {
          RenderUtil.dumpTillLump(
              lumps, rendercontext.close.lumpindex + 1, outerclose.lumpindex + 1, rsc.pos);
        }
      }
      nextpos = rendercontext.nextpos;
    }

    return nextpos;
  }