/** Checks if object exist in registry. */
 private boolean objectExists(String id) throws RegistryException {
   boolean exists = false;
   try {
     RegistryObjectType ro = context.getRegistryObject(id, "RegistryObject", true);
     if (ro != null) {
       exists = true;
     }
   } catch (ObjectNotFoundException e) {
     // do nothing
   }
   return exists;
 }
Esempio n. 2
0
  protected void sendNotification(
      ServerRequestContext context,
      NotifyActionType notifyAction,
      NotificationType notification,
      AuditableEventType ae)
      throws RegistryException {
    log.trace("Sending email notification");

    String endpoint = notifyAction.getEndPoint();

    if ((endpoint == null) || !endpoint.startsWith("mailto:")) {
      throw new RegistryException(
          ServerResourceBundle.getInstance()
              .getString("message.emailNotificationWOmailto", new Object[] {endpoint}));
    }

    try {
      // get the body of the message , not yet defined !
      StringWriter sw = new StringWriter();
      Marshaller marshaller = BindingUtility.getInstance().rimFac.createMarshaller();
      marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
      marshaller.marshal(notification, sw);

      // Now get the RegistryResponse as a String

      // Produce verbose response
      String notif = sw.toString();
      String action = ae.getEventType();
      String userId = ae.getUser();

      String userInfo;
      if (userId != null) {
        UserType user = (UserType) context.getRegistryObject(userId, "User_");
        userInfo =
            ServerResourceBundle.getInstance()
                .getString("message.user", new String[] {getUserInfo(user)});
      } else {
        userInfo = ServerResourceBundle.getInstance().getString("message.userUnknown");
      }

      SubscriptionType subscription =
          (SubscriptionType)
              context.getRegistryObject(notification.getSubscription(), "Subscription");
      String xsltId = getStyleSheetId(subscription);
      RepositoryItem repositoryItem = null;

      // empty string for notification property == use old format
      if (!"".equals(xsltId)) {
        // Dont use transform if there are any problems
        try {
          repositoryItem =
              RepositoryManagerFactory.getInstance()
                  .getRepositoryManager()
                  .getRepositoryItem(xsltId);
        } catch (Exception e) {
          log.warn(ServerResourceBundle.getInstance().getString("message.rawEmailNotification"), e);
        }
      }

      String contentType;
      String message;
      if (repositoryItem == null) {
        // No style sheet so skip the tranformation
        contentType = "text/xml";
        message = sw.toString();
      } else {
        contentType = "text/html";
        try {
          message = transformContent(context, xsltId, notif, action, userInfo);
        } catch (RegistryException e) {
          contentType = "text/xml";
          message = sw.toString();
        }
      }

      // set parameters and send the mail
      String subject =
          ServerResourceBundle.getInstance()
              .getString("message.registryNotification", new Object[] {notification.getId()});
      postMail(endpoint, message, subject, contentType);
    } catch (MessagingException e) {
      throw new RegistryException(e);
    } catch (JAXBException e) {
      throw new RegistryException(e);
    }
  }