コード例 #1
0
  @Override
  protected void doInit() throws ResourceException {
    super.doInit();

    // Get the db handle from context (used both for POST & GET handling)
    dbReader =
        (EHRDatabaseReadInterface<Node, Node>)
            getContext().getAttributes().get(EEEConstants.KEY_TO_BASIC_DB_READER);
    // identifiedVersionsMaxage = (Integer)
    // getContext().getAttributes().get(EHRTestRestStarter.IDENTIFIED_VERSIONS_MAXAGE);
    identifiedVersionsMaxage =
        DemoStarter.getConfig()
            .getInteger(DemoStarter.IDENTIFIED_VERSIONS_MAXAGE, new Integer(60 * 60 * 24 * 7));
    // TODO: Inactivate trace printout:
    getContext()
        .getLogger()
        .fine(
            "VersionedObjectResource.doInit() called with http method: "
                + getRequest().getMethod().getName()
                + "\n"
                + "Entity available: "
                + getRequest().isEntityAvailable()
                + "\n"
                + "Attributes in call: "
                + getRequestAttributes());

    // Store request parameters in local variables usable e.g. for GET & POST handling
    this.ehrID = (String) getRequestAttributes().get(EHR_ID);
    this.objectID = (String) getRequestAttributes().get(OBJECT_ID);
    this.systemID = (String) getRequestAttributes().get(CREATING_SYSTEM_ID);
    this.treeID = (String) getRequestAttributes().get(VERSION_TREE_ID);
    this.lookupString = (String) getRequestAttributes().get(VERSION_LOOKUP);
    this.command = (String) getRequestAttributes().get(COMMAND);
  }
コード例 #2
0
  public String transformVersionToHTMLdiv(DomRepresentation dbResultAsXML) {
    String filename = DemoStarter.getWwwFileDir() + "xslt/openEHR_RMtoHTML-v6.xsl";
    filename = filename.substring(5);
    try {
      filename = java.net.URLDecoder.decode(filename, "UTF-8");
    } catch (UnsupportedEncodingException e) {
      throw new ResourceException(
          Status.SERVER_ERROR_INTERNAL,
          "Suspected configuration problem, couldn't access " + filename,
          e);
    }
    Representation xsltSheet =
        new FileRepresentation(
            filename,
            MediaType.APPLICATION_XML); // TODO: Check expirationTime, Move to proper location

    // TODO: The Transformer should perhaps be created in a more accessible location
    //      - in the application context perhaps (if there are no multithread issues - check that
    // first...)
    Transformer xsltTransformer = new Transformer(Transformer.MODE_RESPONSE, xsltSheet);

    Representation transformedRepresentation = xsltTransformer.transform(dbResultAsXML);

    // TODO: Consider more efficient things than stringifying to get bookmarking functionality

    String transformed = null;
    try {
      transformed = transformedRepresentation.getText();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Could not convert xml to html", e);
    }
    transformed =
        transformed.replace(
            "replace-with-server-and-ehrID/",
            getRequest().getHostRef().toString() + "/ehr:" + ehrID + "/");
    return transformed;
  }