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));
  }
  public ILink getLink(boolean post, Object parameter) {
    Object[] params = (Object[]) parameter;
    ModeleDocument doc = (ModeleDocument) params[0];
    Persistent source = (Persistent) params[1];

    Map<String, Object> map = new TreeMap<String, Object>();
    map.put(
        ServiceConstants.PARAMETER, //
        new Object[] {doc.getObjectId(), source.getObjectId()});
    return _linkFactory.constructLink(this, post, map, true);
  }
示例#3
0
  private void updateDocument() throws IOException {
    if (getFile() == null) return;

    String data = ResourceUtils.readStream(getFile().getStream(), ENCODING);
    data = cleanData(data);
    ModeleDocument document = getDocument();
    if (document == null) // Seul cas possible normalement, mais on blinde
    document = newObject(ModeleDocument.class);

    document.setData(data);
    setDocument(document);
  }