Пример #1
0
  @Override
  public InputStream getRenderInputStream(
      PresentationType presentationType, List<Artifact> artifacts) throws OseeCoreException {
    InputStream stream = null;
    try {
      if (artifacts.isEmpty()) {
        stream =
            Streams.convertStringToInputStream(
                WordWholeDocumentAttribute.getEmptyDocumentContent(), "UTF-8");
      } else {
        Artifact artifact = artifacts.iterator().next();
        String content =
            artifact.getOrInitializeSoleAttributeValue(CoreAttributeTypes.WholeWordContent);
        if (presentationType == PresentationType.DIFF
            && WordUtil.containsWordAnnotations(content)) {
          throw new OseeStateException(
              "Trying to diff the [%s] artifact on the [%s] branch, which has tracked changes turned on.  All tracked changes must be removed before the artifacts can be compared.",
              artifact.getName(), artifact.getBranch().getName());
        }

        LinkType linkType = LinkType.OSEE_SERVER_LINK;
        content = WordMlLinkHandler.link(linkType, artifact, content);

        String classification = WordRendererUtil.getDataRightsClassification(artifact);
        if (Strings.isValid(classification)) {
          content = addDataRights(content, classification, artifact);
        }

        stream = Streams.convertStringToInputStream(content, "UTF-8");
      }
    } catch (IOException ex) {
      OseeExceptions.wrapAndThrow(ex);
    }
    return stream;
  }
Пример #2
0
  private String addDataRights(String content, String classification, Artifact artifact) {
    String toReturn = content;
    PageOrientation orientation = WordRendererUtil.getPageOrientation(artifact);
    DataRightInput request = new DataRightInput();
    request.addData(artifact.getGuid(), classification, orientation, 0);

    DataRightProvider provider = new DataRightProviderImpl();
    DataRightResult dataRights = provider.getDataRights(request);
    String footer = dataRights.getContent(artifact.getGuid(), orientation);

    Matcher startFtr = START_PATTERN.matcher(footer);
    Matcher endFtr = END_PATTERN.matcher(footer);
    if (startFtr.find() && endFtr.find()) {
      ChangeSet ftrCs = new ChangeSet(footer);
      ftrCs.delete(0, startFtr.end());
      ftrCs.delete(endFtr.start(), footer.length());
      footer = ftrCs.applyChangesToSelf().toString();
    }

    startFtr.reset(content);
    endFtr.reset(content);
    ChangeSet cs = new ChangeSet(content);
    while (startFtr.find()) {
      if (endFtr.find()) {
        cs.replace(startFtr.end(), endFtr.start(), footer);
      }
    }
    toReturn = cs.applyChangesToSelf().toString();
    return toReturn;
  }