public void savePaintingAction(IRequestCycle cycle) {
    Painting painting = getPainting();
    Artist artist = getArtist();

    if (!assertNotNull(painting.getPaintingTitle())) {
      appendHtmlToErrorMessage("You must provide a painting title.");
      return;
    }

    DataContext ctxt = getVisitDataContext();

    // painting was created earlier, but before we can
    // start working with its relationships, and ultimately
    // save it to DB, it must be regsitered with DataContext
    ctxt.registerNewObject(painting);

    // establish relationship with artist via a simple method call
    // an equivalent of the line below would be "
    artist.addToPaintingArray(painting);

    // commit to the database
    ctxt.commitChanges();

    BrowseArtistsPage nextPage = (BrowseArtistsPage) cycle.getPage("BrowseArtistsPage");

    cycle.activate(nextPage);
  }
  public void service(IRequestCycle cycle) throws IOException {
    String[] params = cycle.getParameters(ServiceConstants.PARAMETER);
    ObjectId docId = (ObjectId) _squeezer.unsqueeze(params[0]);
    ObjectId sourceId = (ObjectId) _squeezer.unsqueeze(params[1]);

    DataContext context = CayenneUtils.createDataContext();
    ModeleDocument modele = (ModeleDocument) objectForPK(context, docId);
    Persistent source = (Persistent) objectForPK(context, sourceId);

    ParamsProvider<?> provider = providers.get(source.getClass());
    if (provider == null) throw new RuntimeException("No provider for " + source.getClass());

    // Finalement, on transforme le document avant d'altérer la réponse...
    String result =
        new XmlDocChanger(modele.getData()) //
            .subst(provider.toParams(source)) //
            .result();

    // Sortie
    WebResponse response = cycle.getInfrastructure().getResponse();
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Content-Disposition", "attachment; filename=\"document.doc.xml\"");
    OutputStream out = response.getOutputStream(CONTENT_TYPE);
    out.write(result.getBytes(Document.ENCODING));
  }
Beispiel #3
0
  public ILink getLink(IRequestCycle cycle) {
    String actionId = cycle.getNextActionId();

    if (cycle.isRewound(this)) {
      getListener().actionTriggered(this, cycle);

      throw new RenderRewoundException(this);
    }

    return getLink(cycle, Tapestry.ACTION_SERVICE, new Object[] {actionId});
  }
Beispiel #4
0
  /** @see org.apache.tapestry.engine.IEngineService#service(org.apache.tapestry.IRequestCycle) */
  public void service(IRequestCycle cycle) throws IOException {
    String activePageName = cycle.getParameter(ServiceConstants.PAGE);
    IPage page = cycle.getPage(activePageName);
    cycle.activate(page);

    Object[] parameters = linkFactory.extractListenerParameters(cycle);

    String downloadFileName = (String) parameters[0];
    String taskType = (String) parameters[1];
    String templatePath = (String) parameters[2];
    Object reportEntity = parameters[6];

    IBlobModel templateEntity = null;

    boolean isUsetemplatePath = true;

    if (templatePath == null) {
      templateEntity = (IBlobModel) parameters[3];
      isUsetemplatePath = false;
    }

    // 设置reportEntity到page的rootedObject.
    if (reportEntity != null && page instanceof IPageRooted) {
      ((IPageRooted<Object, Object>) page).setRootedObject(reportEntity);
    }

    // 设置监听方法的参数.并调用trigger方法.
    cycle.setListenerParameters(JasperEntityLink.constructServiceParameters(parameters[7]));
    String idPath = (String) parameters[8];
    if (idPath != null) {
      IDirect direct = (IDirect) page.getNestedComponent(idPath);
      direct.trigger(cycle);
    }

    String detailEntity = (String) parameters[4];
    String detailCollection = (String) parameters[5];

    service(
        cycle,
        page,
        isUsetemplatePath,
        templatePath,
        templateEntity,
        downloadFileName,
        taskType,
        detailEntity,
        detailCollection);
  }
  /**
   * Returns true if the connector should update the property value from the binding. For {@link
   * org.apache.tapestry.spec.Direction#IN}, this always returns true. For {@link
   * org.apache.tapestry.spec.Direction#FORM}, this returns true only if the request cycle and the
   * active form are rewinding.
   *
   * @since 2.2
   */
  protected boolean shouldSetPropertyValue(IRequestCycle cycle) {
    if (_direction == Direction.IN) return true;

    // Must be FORM

    return !cycle.isRewinding();
  }
Beispiel #6
0
 public IPage addQueue(IRequestCycle cycle) {
   EditAcdQueue editPage = (EditAcdQueue) cycle.getPage(EditAcdQueue.PAGE);
   editPage.setAcdQueueId(null);
   editPage.setAcdServerId(getAcdServerId());
   editPage.setReturnPage(this);
   return editPage;
 }
 @SuppressWarnings("unchecked")
 public void doActivate(IRequestCycle cycle, List images, Set zipEntries, Set xmlEntries) {
   setImages(images);
   setZipEntriesNoXML(zipEntries);
   setXmlEntriesNoZip(xmlEntries);
   cycle.activate(this);
 }
Beispiel #8
0
  public IPage commit(IRequestCycle cycle) {
    if (!TapestryUtils.isValid(this)) {
      return null;
    }
    // Save the user
    CoreContext core = getCoreContext();
    User user = getUser();
    user.setImId(user.getUserName());
    EditUser.saveGroups(getSettingDao(), user.getGroups());

    // Execute the automatic assignments for the user.
    GroupAutoAssign groupAutoAssign =
        new GroupAutoAssign(
            getConferenceBridgeContext(), getCoreContext(),
            getForwardingContext(), getMailboxManager());
    groupAutoAssign.assignUserData(user);

    // On saving the user, transfer control to edituser page.
    if (FormActions.APPLY.equals(getButtonPressed())) {
      EditUser edit = (EditUser) cycle.getPage(EditUser.PAGE);
      edit.setUserId(user.getId());
      return edit;
    }

    return null;
  }
Beispiel #9
0
 public IPage addSchedule(IRequestCycle cycle) {
   EditSchedule page = (EditSchedule) cycle.getPage(EditSchedule.PAGE);
   page.setUserId(null);
   page.setUserGroup(getSettingDao().getGroup(getGroupId()));
   page.newSchedule("usrGroup_sch", PAGE);
   return page;
 }
Beispiel #10
0
 private void conditionallySetLoginCallback(LoginPage login, IPage page, IRequestCycle cycle) {
   // If page service is calling page, you're probably logged out and user could be
   // looking at a very different page then what gets interpretted from this callback
   // because all session data is lost.
   //
   // If your page can safely handle this, consider refactoring border component to accept a
   // component parameter to circumvent this constraint. Warning: this means your page
   // either doesn't use session variabled OR can safely recover when session is lost
   //
   String serviceName = cycle.getService().getName();
   if (Tapestry.EXTERNAL_SERVICE.equals(serviceName)) {
     ICallback callback =
         new ExternalCallback((IExternalPage) page, cycle.getListenerParameters());
     login.setCallback(callback);
   }
 }
 /*	public IPage cancelPage(IRequestCycle cycle) {
 	getShowEbookPage().setResourceType(ResourceType.TYPE_NEWSPAPERS);
 	return getShowEbookPage();
 }*/
 public void cancelPage(IRequestCycle cycle) {
   try {
     ICallback callback = (ICallback) getCallbackStack().popPreviousCallback();
     callback.performCallback(cycle);
   } catch (Exception e) {
     cycle.activate("resource/ShowEbookPage");
   }
 }
Beispiel #12
0
  public void login(IRequestCycle cycle) {
    if (isValidLogin(getUserName(), getPassword())) {
      cycle.activate("Main");
      return;
    }

    setMessage("Invalid user name or password.");
  }
 @SuppressWarnings("unchecked")
 public void deleteAll(IRequestCycle cycle) {
   ImageDAO dao = getImageDAO();
   for (Iterator iter = getImages().iterator(); iter.hasNext(); ) {
     NodeImage image = (NodeImage) iter.next();
     dao.deleteImage(image);
   }
   cycle.activate("ImagesManager");
 }
Beispiel #14
0
  public void service(IEngineServiceView engine, IRequestCycle cycle, ResponseOutputStream output)
      throws IOException {
    System.out.println(
        "===============================================================================================");
    RequestContext context = cycle.getRequestContext();
    String[] contextParams = getServiceContext(context);
    if (contextParams.length != 3)
      throw new ApplicationRuntimeException(
          "Incorrect number of service parameters for service "
              + getName()
              + ". Expected 2, but got "
              + contextParams.length);

    String componentPageName = contextParams[1];
    String componentId = contextParams[2];

    IPage componentPage = cycle.getPage(componentPageName);
    IComponent component = componentPage.getNestedComponent(componentId);

    if (!(component instanceof IXMLService))
      throw new ApplicationRuntimeException(
          "Incorrect component type: was "
              + component.getClass()
              + " but must be "
              + IXMLService.class,
          component,
          null,
          null);

    IXMLService xservice = (IXMLService) component;

    // do not squeeze on input
    String[] params = context.getParameters(Tapestry.PARAMETERS_QUERY_PARAMETER_NAME);
    cycle.setServiceParameters(params);
    xservice.trigger(cycle);

    // do not squeeze on output either
    Object[] args = cycle.getServiceParameters();
    String strArgs = generateOutputString(args);

    output.setContentType("text/xml");
    output.write(strArgs.getBytes("utf-8"));
  }
Beispiel #15
0
  /**
   * @see org.apache.tapestry.form.TextArea#renderFormComponent(org.apache.tapestry.IMarkupWriter,
   *     org.apache.tapestry.IRequestCycle)
   */
  @Override
  protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle) {
    super.renderFormComponent(writer, cycle);
    if (!cycle.isRewinding()) {
      Map<String, Object> parms = new HashMap<String, Object>();
      parms.put("component", this);

      getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms);
    }
  }
Beispiel #16
0
 public IPage editService(IRequestCycle cycle, String serviceBeanId, Integer locationId) {
   PageWithCallback page = (PageWithCallback) cycle.getPage(SERVICE_MAP.get(serviceBeanId));
   page.setReturnPage(EditLocationPage.PAGE);
   if (page instanceof AcdServerPage) {
     AcdServer acdServer = getAcdContext().getAcdServerForLocationId(locationId);
     if (acdServer != null) {
       ((AcdServerPage) page).setAcdServerId(acdServer.getId());
     }
   }
   return page;
 }
Beispiel #17
0
 public void performCallback(IRequestCycle cycle) {
   if (isStay() && FormActions.OK.equals(getButtonPressed())) {
     // Explicitly null out information that should not be used for multiple users,
     // otherwise keep form values as is theory that creating users in bulk will want
     // all the same settings by default
     setUser(null);
     cycle.activate(PAGE);
   } else if (m_delegate != null) {
     m_delegate.performCallback(cycle);
   }
 }
 /*	public IPage savePage(IRequestCycle cycle){
 	if(save()){
 		getShowEbookPage().setResourceType(ResourceType.TYPE_NEWSPAPERS);
 		return getShowEbookPage();
 	}else
 		return this;
 }*/
 public void savePage(IRequestCycle cycle) {
   if (save()) {
     /*getShowEbookPage().setResourceType(ResourceType.TYPE_MAGAZINE);
     return getShowEbookPage();*/
     try {
       ICallback callback = (ICallback) getCallbackStack().popPreviousCallback();
       callback.performCallback(cycle);
     } catch (Exception e) {
       cycle.activate("resource/ShowEbookPage");
     }
   }
 }
Beispiel #19
0
  @Override
  protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
    super.renderComponent(writer, cycle);

    if (cycle.isRewinding()) {
      try {
        updateDocument();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
  }
  /**
   * Restores the property to its default value. For {@link Direction#FORM} parameters, extracts the
   * property value and sets the binding form it (when appropriate).
   */
  public void resetParameter(IRequestCycle cycle) {
    if (_direction == Direction.FORM && cycle.isRewinding()) {
      IFormComponent component = (IFormComponent) _component;

      if (!component.isDisabled()) {
        IForm form = Form.get(cycle);

        if (form != null && form.isRewinding()) {
          Object value = readCurrentPropertyValue();

          _binding.setObject(value);
        }
      }
    }

    // Either way, clear the value.

    setPropertyValue(_clearValue);
  }
Beispiel #21
0
 public IPage editSchedulesGroup(IRequestCycle cycle, Integer scheduleId) {
   EditSchedule page = (EditSchedule) cycle.getPage(EditSchedule.PAGE);
   page.editSchedule(scheduleId, PAGE);
   return page;
 }
Beispiel #22
0
 @Override
 public IPage editGroupName(IRequestCycle cycle) {
   EditGroup page = (EditGroup) cycle.getPage(EditGroup.PAGE);
   page.editGroup(getGroupId(), PAGE);
   return page;
 }
Beispiel #23
0
 /**
  * form 提交动作 weijian.zhang 2006-4-18
  *
  * @param cycle
  */
 public void formSubmit(IRequestCycle cycle) {
   if (ConstantPageName.SET_RTN.equals(getFunctionHidden())) { // 返回
     RoleList roleList = (RoleList) cycle.getPage("RoleList");
     cycle.activate(roleList);
   }
 }
 public void viewMissingEntries(IRequestCycle cycle) {
   IPage missingEntriesPage = cycle.getPage("ImageZipUploadMissingEntries");
   PropertyUtils.write(missingEntriesPage, "zipEntriesNoXML", getZipEntriesNoXML());
   PropertyUtils.write(missingEntriesPage, "xmlEntriesNoZip", getXmlEntriesNoZip());
   cycle.activate(missingEntriesPage);
 }
Beispiel #25
0
  /**
   * 得到JasperPrint的list.用于一个报表有多页的情况(非循环多页)
   *
   * <p>实现方法:通过读取zip包,将zip包里每一个报表文件进行填充并放入List返回.
   *
   * <p>注意:zip包里报表名命名规则:第一张应该为1.jasper,依次类推;若报表有detail,则在数字后边加上detail如2detail.jasper;
   * 若报表有子报表则命名时后缀为.zip有detail则加,无则不加.
   *
   * @param jasperInStream
   * @param page
   * @param parameters
   * @param detailEntity
   * @param detailCollection
   * @return
   * @throws JRException
   * @throws IOException
   * @throws ParseException
   */
  @SuppressWarnings("unchecked")
  protected List<JasperPrint> getJasperPrintList(
      IRequestCycle cycle,
      InputStream jasperInStream,
      IPage page,
      Map<Object, Object> parameters,
      String detailEntity,
      String detailCollection)
      throws JRException, IOException, ParseException {

    List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>();

    int pageNumber = 0;
    JasperPrint jasperPrint = null;
    Object[] jasperName = parameters.keySet().toArray();
    Arrays.sort(jasperName);

    for (int i = 0; i < jasperName.length; i++) {

      jasperInStream = (InputStream) parameters.get(jasperName[i]);
      getJasperParameters(jasperInStream, parameters);
      IPageRooted<Object, Object> activePage = (IPageRooted<Object, Object>) page;

      if (parameters.containsKey(TEMPLATE_PAGE)) {

        InputStream propStream = (InputStream) parameters.get(TEMPLATE_PAGE);
        String jsonParam = getLinkParameter(propStream);
        parameters.remove(TEMPLATE_PAGE);

        if (jsonParam != null) {
          JSONObject json = new JSONObject(jsonParam);

          String activePageName = null;
          if (json.has(PAGE)) {
            activePageName = (String) json.get(PAGE);
            activePage = (IPageRooted<Object, Object>) cycle.getPage(activePageName);
            ((IPageRooted<Object, Object>) activePage)
                .setRootedObject(((IPageRooted<Object, Object>) page).getRootedObject());
            cycle.activate(activePage);
          }
        }
      }

      if (((String) jasperName[i])
          .substring(0, ((String) jasperName[i]).indexOf("."))
          .endsWith(DETAIL)) {

        jasperPrint =
            this.getJasperPrint(
                jasperInStream, activePage, parameters, detailEntity, detailCollection, pageNumber);
      } else {

        jasperPrint =
            this.getJasperPrint(jasperInStream, activePage, parameters, null, null, pageNumber);
      }

      jasperPrintList.add(jasperPrint);

      int pageSize = jasperPrint.getPages().size();

      pageNumber += pageSize; // 将前边的JasperPrint的页数进行记录
    }

    return jasperPrintList;
  }
Beispiel #26
0
  protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
    IForm form = getForm(cycle);

    String name = form.getElementId(this);

    String format = getFormat();

    if (format == null) format = "dd MMM yyyy";

    SimpleDateFormat formatter = new SimpleDateFormat(format, getPage().getLocale());

    boolean disabled = isDisabled();

    if (!cycle.isRewinding()) {
      Body body = Body.get(cycle);

      if (body == null)
        throw new ApplicationRuntimeException(
            Tapestry.format("must-be-contained-by-body", "DatePicker"), this, null, null);

      Locale locale = getPage().getLocale();
      DateFormatSymbols dfs = new DateFormatSymbols(locale);
      Calendar cal = Calendar.getInstance(locale);

      Date value = getValue();

      Map symbols = new HashMap();

      symbols.put(SYM_NAME, name);
      symbols.put(SYM_FORMAT, format);
      symbols.put(SYM_INCL_WEEK, getIncludeWeek() ? Boolean.TRUE : Boolean.FALSE);

      symbols.put(SYM_MONTHNAMES, makeStringList(dfs.getMonths(), 0, 12));
      symbols.put(SYM_SHORT_MONTHNAMES, makeStringList(dfs.getShortMonths(), 0, 12));
      symbols.put(SYM_WEEKDAYNAMES, makeStringList(dfs.getWeekdays(), 1, 8));
      symbols.put(SYM_SHORT_WEEKDAYNAMES, makeStringList(dfs.getShortWeekdays(), 1, 8));
      symbols.put(SYM_FIRSTDAYINWEEK, new Integer(cal.getFirstDayOfWeek() - 1));
      symbols.put(SYM_MINDAYSINFIRSTWEEK, new Integer(cal.getMinimalDaysInFirstWeek()));
      symbols.put(SYM_FORMNAME, form.getName());
      symbols.put(SYM_VALUE, value);

      _script.execute(cycle, body, symbols);

      writer.beginEmpty("input");
      writer.attribute("type", "text");
      writer.attribute("name", name);
      writer.attribute("title", formatter.toLocalizedPattern());

      if (value != null) writer.attribute("value", formatter.format(value));

      if (disabled) writer.attribute("disabled", "disabled");

      renderInformalParameters(writer, cycle);

      writer.printRaw("&nbsp;");

      if (!disabled) {
        writer.begin("a");
        writer.attribute("href", (String) symbols.get(SYM_BUTTONONCLICKHANDLER));
      }

      IAsset icon = getIcon();

      writer.beginEmpty("img");
      writer.attribute("src", icon.buildURL(cycle));
      writer.attribute("border", 0);

      if (!disabled) writer.end(); // <a>
    }

    if (form.isRewinding()) {
      if (disabled) return;

      String textValue = cycle.getRequestContext().getParameter(name);

      if (Tapestry.isBlank(textValue)) return;

      try {
        Date value = formatter.parse(textValue);

        setValue(value);
      } catch (ParseException ex) {
      }
    }
  }
Beispiel #27
0
 public IPage editLine(IRequestCycle cycle, Integer id) {
   EditAcdLine editPage = (EditAcdLine) cycle.getPage(EditAcdLine.PAGE);
   editPage.setAcdLineId(id);
   editPage.setReturnPage(this);
   return editPage;
 }
 private IEngineService workflowService(IRequestCycle cycle) {
   return cycle.getInfrastructure().getServiceMap().getService(WorkflowService.NAME);
 }
 public void activate(IRequestCycle cycle) {
   workflow.setCurrentEntry(this);
   DataContext.bindThreadDataContext(dataContext);
   cycle.getPage(pageName).validate(cycle);
   cycle.activate(pageName);
 }
Beispiel #30
0
 public IPage extensionPools(IRequestCycle cycle) {
   ExtensionPoolsPage poolsPage = (ExtensionPoolsPage) cycle.getPage(ExtensionPoolsPage.PAGE);
   poolsPage.setReturnPage(this);
   return poolsPage;
 }