Package org.jdom.output

Examples of org.jdom.output.XMLOutputter


      replyDoc.getRootElement().removeChild(DATA_AREA);
    }

    // Build the reply document as if there were no errors.
    String strReplyDoc = buildReplyDocument(senderControlArea, replyDoc);
    XMLOutputter xmlOut = new XMLOutputter();

    // Now add the errors into the control area
    Result aResult = new Result();

    Document localReplyDoc = null;
    try {
      XmlDocumentReader xmlReader = new XmlDocumentReader();
      localReplyDoc = xmlReader.initializeDocument(new ByteArrayInputStream(strReplyDoc.getBytes()), false);
      Element replyControlArea = getControlArea(localReplyDoc.getRootElement());
      localReplyDoc.getRootElement().removeContent(replyControlArea);
      Element eResult = replyControlArea.getChild("Result");
      aResult.buildObjectFromInput(eResult);
      aResult.setStatus("failure");

      for (int i=0; i<errors.size(); i++) {
        org.openeai.moa.objects.resources.Error anError =
          (org.openeai.moa.objects.resources.Error)errors.get(i);
        aResult.addError(anError);
      }

      replyControlArea.removeChild("Result");
      replyControlArea.addContent((Element)aResult.buildOutputFromObject());
      localReplyDoc.getRootElement().addContent(replyControlArea);
      if (needsDataArea) {
        localReplyDoc.getRootElement().addContent(new Element(DATA_AREA));
      }
      return xmlOut.outputString(localReplyDoc);
    }
    catch (Exception e) {
      // We'll just have to return the replyDoc after we've added our error
      // to it without the Dynamic ControlArea information...
      logger.fatal("Error building error reply document.");
View Full Code Here


  *  Generic-Response-Reply document or a 'response-reply' document specific to the message object/action
  *  being processed (e.g. InstitutionalIdentity-Response-Reply).
  */
  public final String buildReplyDocument(Element senderControlArea, Document replyDoc) {

    XMLOutputter xmlOut = new XMLOutputter();
    Document localReplyDoc = (Document)replyDoc.clone();

    String msgAction = senderControlArea.getAttribute(MESSAGE_ACTION).getValue();

    Element replyControlArea = getControlArea(localReplyDoc.getRootElement());
    localReplyDoc.getRootElement().removeContent(replyControlArea);

    // A DataArea will only exist for some reply documents,
    // later when we rebuild the reply document, we'll check to see
    // if this element is null before we try to add it back into
    // the document.  We need to do this so when we re-build the document
    // we can add the ControlArea and DataAreas in the proper order...
    Element replyDataArea = localReplyDoc.getRootElement().getChild(DATA_AREA);
    if (replyDataArea != null) {
      localReplyDoc.getRootElement().removeChild(DATA_AREA);
    }

    replyControlArea.removeChild("Result");
    replyControlArea.removeChild("Datetime");
    replyControlArea.removeChild("Sender");

    Result aResult = new Result();

    ProcessedMessageId processedMsgId = new ProcessedMessageId();
    Element eRequestSender = senderControlArea.getChild("Sender");

    processedMsgId.setProducerId(eRequestSender.getChild("MessageId").
      getChild("ProducerId").getText());
    processedMsgId.setSenderAppId(eRequestSender.getChild("MessageId").
      getChild("SenderAppId").getText());
    processedMsgId.setMessageSeq(eRequestSender.getChild("MessageId").
      getChild("MessageSeq").getText());

    aResult.setAction(msgAction);
    aResult.setStatus("success");
    aResult.setProcessedMessageId(processedMsgId);

    // Set the sender element (the replier)
    Sender sender = new Sender();

    MessageId replierMsgId = new MessageId();
    replierMsgId.setProducerId(eRequestSender.getChild("MessageId").
      getChild("ProducerId").getText());
    replierMsgId.setSenderAppId(getAppName());
    replierMsgId.setMessageSeq(eRequestSender.getChild("MessageId").
      getChild("MessageSeq").getText());
    sender.setMessageId(replierMsgId);

    Authentication auth = new Authentication();
    auth.setAuthUserId(getAppName());
    auth.setAuthUserSignature(getAppName());
    sender.setAuthentication(auth);

    Element eSender = null;
    try {
      XmlLayout xmlLayout = (XmlLayout)sender.getOutputLayoutManager("xml");
      sender.setOutputLayoutManager(xmlLayout);
      eSender = (Element)sender.buildOutputFromObject();
    }
    catch (Exception e) {
      logger.fatal("[buildReplyDocument] Exception occurred building an Element from the Sender object.  Exception: " + e.getMessage());
      return xmlOut.outputString(replyDoc);
    }

    // Set the datetime element (for the replier)
    Datetime dt = new Datetime();
    Element eDatetime = null;
    try {
      eDatetime = (Element)dt.buildOutputFromObject();
    }
    catch (Exception e) {
      logger.fatal("[buildReplyDocument] Exception occurred building an Element from the Datetime object.  Exception: " + e.getMessage());
      return xmlOut.outputString(replyDoc);
    }

    try {
      replyControlArea.addContent(eSender);
      replyControlArea.addContent(eDatetime);
      replyControlArea.addContent((Element)aResult.buildOutputFromObject());
      localReplyDoc.getRootElement().addContent(replyControlArea);
      if (replyDataArea != null) {
        localReplyDoc.getRootElement().addContent(replyDataArea);
      }
    }
    catch (Exception e) {
      logger.fatal("Error building reply document, returning Reply Document passed in");
      logger.fatal(e.getMessage(), e);
      return xmlOut.outputString(replyDoc);
    }
    return xmlOut.outputString(localReplyDoc);
  }
View Full Code Here

    try {
      EnterpriseLayoutManager elm = getOutputLayoutManager("xml");
      if (elm != null) {
        Object obj = elm.buildOutputFromObject(this);
        if (obj instanceof Element) {
          XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
          logger.info(fmt.outputString((Element)obj));
        }
      }
    }
    catch (Exception exc) {
      logger.fatal("dumpData: Exception caught: " + exc.getMessage());
View Full Code Here

      xeo.setOutputLayoutManager(outElm);
      xeo.setInputLayoutManager(inElm);

      logger.debug("re-building object from input...");
      xeo.buildObjectFromInput(eOutput);
      XMLOutputter xmlOut = new XMLOutputter();
      String objAsXmlString = xmlOut.outputString((Element)xeo.buildOutputFromObject());
      logger.debug("[toXmlString] " + className + " as an XML String: \n" + objAsXmlString);

      // To test to make sure it doesn't have any goofy characters in it...
      // If it does, an exception will be thrown here.
      XmlDocumentReader xmlReader = new XmlDocumentReader();
View Full Code Here

  * @throws TransportExceptom if errors occur.
  **/
  public boolean publishMessage(ActionableEnterpriseObject theObject, Document doc)
  throws TransportException {
    TextMessage outMessage = createTextMessage();
    XMLOutputter xmlOut = new XMLOutputter();
    String messageBody = xmlOut.outputString(doc);
    String xmlMsgId = theObject.getMessageId().toString();
    logger.debug("PubSubProducer: ProducerId is: " + getProducerId(null).getId());
    logger.debug("PubSubProducer: MessageId is: " + xmlMsgId);

    try {
View Full Code Here

    Element dataArea = updateDoc.getRootElement().getChild("DataArea");

    Element oldElement = dataArea.getChild("NewData").getChild(getElementName());
    Element oldBaselineElement = dataArea.getChild("BaselineData").getChild(getElementName());

    XMLOutputter xmlOut = new XMLOutputter();
    Element newElement = null;
    try {
      newElement = (Element)buildOutputFromObject();
    }
    catch (EnterpriseLayoutException e) {
      logger.fatal("Error building updateMessage for object " + getClass().getName() + " content of object: " + toString());
      String errMessage = "Error building updateMessage for object " +
        getClass().getName() + "  Exception: " + e.getMessage();
      throw new EnterpriseObjectUpdateException(errMessage, e);
    }

    // need check for null baseline!
    if (getBaseline() == null) {
      logger.warn("buildUpdateMessage:  baseline is null!");
      try {
        setBaseline((XmlEnterpriseObject)clone());
        getBaseline().buildObjectFromInput(oldBaselineElement);
      }
      catch (Exception e) {
        logger.fatal("Error building baseline object from element for object (baseline/clone) " +
          getBaseline().getClass().getName() + " content of element: " +
          xmlOut.outputString(oldBaselineElement));
        String errMessage = "Error building baseline object from element for object " +
          getClass().getName() + "  Exception: " + e.getMessage();
        throw new EnterpriseObjectUpdateException(errMessage, e);
      }
    }
View Full Code Here

  //============================================================================
  //============================================================================
  private void outputXMLDocument(Document doc, String message) {
    try {
      XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
      logger.fatal(message);
      logger.fatal("\n" + fmt.outputString(doc));
    }
    catch (Exception exc) {
      logger.fatal("Error converting XML Document to String.");
      logger.fatal(exc.getMessage(), exc);
    }
View Full Code Here

  //============================================================================
  //============================================================================
  private void outputXMLElement(Element element, String message) {
    try {
      XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
      logger.fatal(message);
      logger.fatal("\n" + fmt.outputString(element));
    }
    catch (Exception exc) {
      logger.fatal("Error converting XML Element to String.");
      logger.fatal(exc.getMessage(), exc);
    }
View Full Code Here

  *  Returns the messageBody that was built during the initializeInput method call.
  *  this will be a 'String' object built from the message body of the JMS message passed in.
  *  @return  String
  */
  public final String getMessageBody(Document inDoc) {
    XMLOutputter xmlOut = new XMLOutputter();
    return xmlOut.outputString(inDoc);
  }
View Full Code Here

    File messageStore = new File(msgDumpDir);
    if (messageStore.exists() == false) {
      messageStore.mkdirs();
    }

    XMLOutputter xmlOut = new XMLOutputter();
    Element eControlArea = getControlArea(doc.getRootElement());
    Element eMessageId = eControlArea.getChild("Sender").getChild("MessageId");
    String senderAppId = eMessageId.getChild("SenderAppId").getText();
    String producerId = eMessageId.getChild("ProducerId").getText();
    String messageSeq = eMessageId.getChild("MessageSeq").getText();
    String fileName = senderAppId + "-" + producerId + "-" + messageSeq + ".xml";
    if (msgDumpDir.lastIndexOf("/") != msgDumpDir.length() - 1) {
      msgDumpDir = msgDumpDir + "/";
    }
    logger.info("Writing message to file: " + msgDumpDir + fileName);
    try {
       xmlOut.output(doc, new FileOutputStream(msgDumpDir + fileName));
    }
    catch (Exception e) {
      String msg = "Error dumping message to a file.  Exception: " + e.getMessage();
      logger.fatal(msg);
      throw new IOException(msg);
View Full Code Here

TOP

Related Classes of org.jdom.output.XMLOutputter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.