Package org.docx4j.jaxb

Examples of org.docx4j.jaxb.JaxbValidationEventHandler


        
         *  But it is better, I think to always get rid of the alternate content entirely.
       */
     
      log.info("proactively pre-processing to remove any AlternateContent");
      JaxbValidationEventHandler eventHandler = new JaxbValidationEventHandler();
      eventHandler.setContinue(true);
     
      // There is no JAXBResult(binder),
      // so use a
      DOMResult result = new DOMResult();
     
View Full Code Here


      // unmarshalling here from an Element doesn't implement that fix, so beware.
     
    try {

      binder = jc.createBinder();
      JaxbValidationEventHandler eventHandler = new JaxbValidationEventHandler();
      eventHandler.setContinue(false);
      binder.setEventHandler(eventHandler);
     
      try {
        jaxbElement =  (Sld) binder.unmarshal( el );
      } catch (UnmarshalException ue) {
        log.info("encountered unexpected content; pre-processing");
        try {
          org.w3c.dom.Document doc;
          if (el instanceof org.w3c.dom.Document) {
            doc = (org.w3c.dom.Document) el;
          } else {
            // Hope for the best. Dodgy though; what if this is
            // being used on something deep in the tree?
            // TODO: revisit
            doc = el.getOwnerDocument();
          }
          eventHandler.setContinue(true);
          DOMResult result = new DOMResult();
          Templates mcPreprocessorXslt = JaxbValidationEventHandler
              .getMcPreprocessor();
          XmlUtils.transform(doc, mcPreprocessorXslt, null, result);
          doc = (org.w3c.dom.Document) result.getNode();
View Full Code Here

     
    try {
       
      Unmarshaller u = jc.createUnmarshaller();
     
      JaxbValidationEventHandler eventHandler = new JaxbValidationEventHandler();
      if (is.markSupported()) {
        // Only fail hard if we know we can restart
        eventHandler.setContinue(false);
      }
      u.setEventHandler(eventHandler);
     
      try {
        jaxbElement = (E) XmlUtils.unwrap(
            u.unmarshal( is ));           
      } catch (UnmarshalException ue) {
       
        if (is.markSupported() ) {
          // When reading from zip, we use a ByteArrayInputStream,
          // which does support this.
       
          log.info("encountered unexpected content; pre-processing");
          eventHandler.setContinue(true);
                   
          try {
            Templates mcPreprocessorXslt = JaxbValidationEventHandler.getMcPreprocessor();
            is.reset();
            JAXBResult result = XmlUtils.prepareJAXBResult(jc);
View Full Code Here

    public E unmarshal(org.w3c.dom.Element el) throws JAXBException {

    try {

      Unmarshaller u = jc.createUnmarshaller();
      JaxbValidationEventHandler eventHandler = new JaxbValidationEventHandler();
      eventHandler.setContinue(false);
      u.setEventHandler(eventHandler);
     
      try {
        jaxbElement = (E) XmlUtils.unwrap(
            u.unmarshal( el ) );
      } catch (UnmarshalException ue) {
        log.info("encountered unexpected content; pre-processing");
        try {
          org.w3c.dom.Document doc;
          if (el instanceof org.w3c.dom.Document) {
            doc = (org.w3c.dom.Document) el;
          } else {
            // Hope for the best. Dodgy though; what if this is
            // being used on something deep in the tree?
            // TODO: revisit
            doc = el.getOwnerDocument();
          }
          eventHandler.setContinue(true);
          JAXBResult result = XmlUtils.prepareJAXBResult(jc);
          Templates mcPreprocessorXslt = JaxbValidationEventHandler
              .getMcPreprocessor();
          XmlUtils.transform(doc, mcPreprocessorXslt, null, result);
          jaxbElement = (E) XmlUtils.unwrap(
View Full Code Here

      //
      binder = jc.createBinder();
     
      log.debug("info: " + binder.getClass().getName());
     
      JaxbValidationEventHandler eventHandler = new JaxbValidationEventHandler();
      eventHandler.setContinue(false);
      binder.setEventHandler(eventHandler);
     
      try {
        unwrapUsually(binder,  doc)// unlikely to need this in the code below
         
      } catch (Exception ue) {

        if (ue instanceof UnmarshalException) {
          // Usually..
        } else {
          // eg java.lang.NumberFormatException
          log.error( ue.getMessage(), ue);
        }
       
        if (is.markSupported() ) {
          // When reading from zip, we use a ByteArrayInputStream,
          // which does support this.
       
          log.info("encountered unexpected content; pre-processing");
          /* Always try our preprocessor, since if what is first encountered is
           * eg:
           *
                  <w14:glow w14:rad="101600"> ...
           *
           * the error would be:
           * 
           *    unexpected element (uri:"http://schemas.microsoft.com/office/word/2010/wordml", local:"glow")
           *
           * but there could well be mc:AlternateContent somewhere
           * further down in the document.
           */
 
          // mimic docx4j 2.7.0 and earlier behaviour; this will
          // drop w14:glow etc; the preprocessor doesn't need to
          // do that       
          eventHandler.setContinue(true);
         
          // There is no JAXBResult(binder),
          // so use a
          DOMResult result = new DOMResult();
         
View Full Code Here

    try {
      log.info("For " + this.getClass().getName() + ", unmarshall via binder");

      binder = jc.createBinder();
      JaxbValidationEventHandler eventHandler = new JaxbValidationEventHandler();
      eventHandler.setContinue(false);
      binder.setEventHandler(eventHandler);
     
      try {
//        jaxbElement =  (E) XmlUtils.unwrap(binder.unmarshal( el ));
        unwrapUsually(binder,  el)// unlikely to need this in the code below
       
       
      } catch (Exception ue) {
        if (ue instanceof UnmarshalException) {
          // Usually..
        } else {
          // eg java.lang.NumberFormatException
          log.error( ue.getMessage(), ue);
          log.info(".. can recover if problem is w:tblW/@w:w");         
        }
        log.info("encountered unexpected content; pre-processing");
        org.w3c.dom.Document doc = null;
        try {
          if (el instanceof org.w3c.dom.Document) {
            doc = (org.w3c.dom.Document) el;
          } else {
            // Hope for the best. Dodgy though; what if this is
            // being used on something deep in the tree?
            // TODO: revisit
            doc = el.getOwnerDocument();
          }
          eventHandler.setContinue(true);
          DOMResult result = new DOMResult();
          Templates mcPreprocessorXslt = JaxbValidationEventHandler
              .getMcPreprocessor();
          XmlUtils.transform(doc, mcPreprocessorXslt, null, result);
          doc = (org.w3c.dom.Document) result.getNode();
View Full Code Here

      throws Docx4JException {

    final JAXBResult result;
    try {
      final Unmarshaller unmarshaller = context.createUnmarshaller();
      unmarshaller.setEventHandler(new JaxbValidationEventHandler());
      result = new JAXBResult(unmarshaller);

    } catch (JAXBException e) {
      throw new Docx4JException("Error preparing empty JAXB result", e);
    }
View Full Code Here

      // So, our marshall should be to a W3C document
      org.w3c.dom.Document doc = XmlUtils.marshaltoW3CDomDocument(o, jc);
     
      // OK, unmarshall to binder
      binder = jc.createBinder();
      JaxbValidationEventHandler eventHandler = new JaxbValidationEventHandler();
      eventHandler.setContinue(false);
      binder.setEventHandler(eventHandler);
      jaxbElement =  binder.unmarshal( doc);
     
      //log.debug("Clone: " + XmlUtils.marshaltoString(jaxbElement, true, true));
     
View Full Code Here

TOP

Related Classes of org.docx4j.jaxb.JaxbValidationEventHandler

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.