public String retrieveDocumentIdFromMessage(String rnifMessage) throws MessageHelperException {
   RnifMessageEntity rnifMsgTemplate;
   try {
     rnifMsgTemplate = _rnifDao.getRnifMessageTemplate(getPipCode());
     return findValue(rnifMessage, rnifMsgTemplate.getPath(RnifMessageEntity.PATH_DOC_ID));
   } catch (MessageDaoException e) {
     throw new MessageHelperException("Error in DAO", e);
   }
 }
  /**
   * Generates an RNIF message from the specified PIP instance Id, document Id and document template
   *
   * @param pipInstId The PIP instance ID for which to create a message
   * @param documentId The document Id to inject into the message
   * @return The RNIF message generated
   * @throws MessageHelperException
   * @throws IOException
   */
  public String generatePipMessage(
      String senderDuns, String receiverDuns, String pipInstId, String documentId)
      throws MessageHelperException {
    String mn = "generateRnifMessage";
    logDebug(mn, "Start.PIP inst. Id.:" + pipInstId);
    String preambleContentID = genContentID();
    String deliveryContentID = genContentID();
    String serviceHeaderContentID = genContentID();
    String serviceContentContentID = genContentID();
    String deliverTs = genTs();
    String initiatorDuns = senderDuns;
    String msgTrackingID = "1";
    String docGenTs = genTs();

    String template = null;
    try {
      RnifMessageEntity rnifMsg = _rnifDao.getRnifMessageTemplate(getPipCode());
      template = getContent(rnifMsg.getTemplateFile());
      String content = template.replaceAll(PREAMPLE_CID_PLACEHOLDER, preambleContentID);
      content = content.replaceAll(DELIVERY_CID_PLACEHOLDER, deliveryContentID);
      content = content.replaceAll(SERVICEH_CID_PLACEHOLDER, serviceHeaderContentID);
      content = content.replaceAll(SERVICEC_CID_PLACEHOLDER, serviceContentContentID);
      content = content.replaceAll(DELIVERY_TS_PLACEHOLDER, deliverTs);
      content = content.replaceAll(SENDER_DUNS_PLACEHOLDER, senderDuns);
      content = content.replaceAll(RECEIVER_DUNS_PLACEHOLDER, receiverDuns);
      content = content.replaceAll(INITIATOR_DUNS_PLACEHOLDER, initiatorDuns);
      content = content.replaceAll(MSG_TRACKING_ID_PLACEHOLDER, msgTrackingID);
      content = content.replaceAll(PIP_INST_ID_PLACEHOLDER, pipInstId);
      content = content.replaceAll(DOC_GEN_TS_PLACEHOLDER, docGenTs);
      content = content.replaceAll(DOC_ID_PLACEHOLDER, documentId);

      // Get action-specific variables (?)
      Properties actionProp = rnifMsg.getParams();
      Enumeration keys = actionProp.propertyNames();
      while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        String val = actionProp.getProperty(key);
        content = content.replaceAll(key, val);
      }
      //			logDebug(mn, "Content:\n"+content);
      return content;
    } catch (IOException e) {
      throw new MessageHelperException("IO Error reading template", e);
    } catch (MessageDaoException e) {
      throw new MessageHelperException("Error in DAO", e);
    }
  }