Ejemplo n.º 1
0
  private String transformContent(
      ServerRequestContext context, String xsltId, String xmlNotif, String action, String user)
      throws RegistryException {
    try {
      RepositoryItem repositoryItem =
          RepositoryManagerFactory.getInstance().getRepositoryManager().getRepositoryItem(xsltId);
      StreamSource xsltIn = new StreamSource(repositoryItem.getDataHandler().getInputStream());

      TransformerFactory tFactory = TransformerFactory.newInstance();
      Transformer transformer = tFactory.newTransformer(xsltIn);

      // transformer.setURIResolver(rm.getURIResolver());
      transformer.setErrorListener(
          new ErrorListener() {
            public void error(TransformerException exception) throws TransformerException {
              log.info(ServerResourceBundle.getInstance().getString("xsltError"), exception);
            }

            public void fatalError(TransformerException exception) throws TransformerException {
              log.error(ServerResourceBundle.getInstance().getString("xsltFatalError"), exception);
              throw exception;
            }

            public void warning(TransformerException exception) throws TransformerException {
              log.info(ServerResourceBundle.getInstance().getString("xsltWarning"), exception);
            }
          });

      // Set parameters
      transformer.setParameter("action", action);
      transformer.setParameter("user", user);
      transformer.setParameter(
          "registryBaseURL", RegistryProperties.getInstance().getProperty("omar.registry.baseurl"));

      ByteArrayInputStream bais = new ByteArrayInputStream(xmlNotif.getBytes("utf-8"));
      StreamSource inputSrc = new StreamSource(bais);

      // TODO: use file in case we have a large amount of data to transform?
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      StreamResult streamResult = new StreamResult(baos);

      transformer.transform(inputSrc, streamResult);

      return baos.toString("utf-8");
    } catch (Exception e) {
      log.error(
          ServerResourceBundle.getInstance().getString("message.prettyPrintNotificationFailure"),
          e);
      throw new RegistryException(e);
    }
  }
Ejemplo n.º 2
0
  /**
   * Creates a new version of the RepositoryItem associated with specified ExtrinsicObject. Note
   * that when the RepositoryItem is versioned its ExtrinsicObject must also be versioned.
   */
  public RepositoryItem createRepositoryItemVersion(ExtrinsicObjectType eo)
      throws RegistryException {
    RepositoryItem riNew = null;

    try {
      ExtrinsicObjectType eoNew = (ExtrinsicObjectType) createRegistryObjectVersion(eo);

      String latestContentVersionName = rm.getLatestVersionName(context, eo.getLid());
      String nextContentVersionName = nextVersion(latestContentVersionName);

      VersionInfoType nextContentVersionInfo = bu.rimFac.createVersionInfoType();
      nextContentVersionInfo.setVersionName(nextContentVersionName);

      // Set the contentComment from the submitted object's contentVersionInfo
      VersionInfoType submittedContentVersionInfo = eo.getContentVersionInfo();
      if (submittedContentVersionInfo != null) {
        nextContentVersionInfo.setComment(submittedContentVersionInfo.getComment());
      }

      // Update the eo contentVersionName to match newContentVersionName
      eoNew.setContentVersionInfo(nextContentVersionInfo);

      RepositoryItem riOld = (RepositoryItem) context.getRepositoryItemsMap().get(eo.getId());
      riNew = (RepositoryItem) riOld.clone();

      // A new version must have a unique id that matches its new ExtrinsicObject eoNew
      riNew.setId(eoNew.getId());

      // Now remeber in context.newRIVersionMap fro later replacement
      // Should we be using old or new eo.getId().
      // Maybe we dont need newRIVersionMap and newROVersionMap
      // Lets see how to just use existing idMap and other structures.
      context.getNewRIVersionMap().put(context.getRepositoryItemsMap().get(eo.getId()), riNew);
    } catch (CloneNotSupportedException e) {
      // This cannot happen
      throw new RegistryException(e);
    } catch (JAXBException e) {
      throw new RegistryException(e);
    }

    return riNew;
  }
Ejemplo n.º 3
0
  private boolean repositoryItemsAreIdentical(RepositoryItem ri1, RepositoryItem ri2) {
    DataHandler dh1 = ri1.getDataHandler();
    DataHandler dh2 = ri2.getDataHandler();

    return dh1.equals(dh2);
  }