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));
  }
Esempio n. 2
0
 private IEngineService workflowService(IRequestCycle cycle) {
   return cycle.getInfrastructure().getServiceMap().getService(WorkflowService.NAME);
 }