Example usage for javax.xml.bind PropertyException getMessage

List of usage examples for javax.xml.bind PropertyException getMessage

Introduction

In this page you can find the example usage for javax.xml.bind PropertyException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.iflytek.edu.cloud.frame.spring.Jaxb2RootElementHttpMessageConverterExt.java

@Override
protected void customizeMarshaller(Marshaller marshaller) {
    try {/*from   ww w .  j  a v a 2s  . c o m*/
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
    } catch (PropertyException e) {
        LOGGER.error(e.getMessage(), e);
    }
}

From source file:org.docx4all.ui.menu.FileMenu.java

protected boolean save(WordprocessingMLPackage wmlPackage, String saveAsFilePath, String callerActionName) {
    boolean success = true;
    try {/*from   w w w .  j  a v a 2s.c  om*/
        if (saveAsFilePath.endsWith(Constants.DOCX_STRING)) {
            SaveToVFSZipFile saver = new SaveToVFSZipFile(wmlPackage);
            saver.save(saveAsFilePath);
        } else if (saveAsFilePath.endsWith(Constants.FLAT_OPC_STRING)) {

            FlatOpcXmlCreator xmlPackageCreator = new FlatOpcXmlCreator(wmlPackage);
            org.docx4j.xmlPackage.Package flatOPC = xmlPackageCreator.get();

            FileObject fo = VFSUtils.getFileSystemManager().resolveFile(saveAsFilePath);
            OutputStream fos = fo.getContent().getOutputStream();

            Marshaller m = Context.jcXmlPackage.createMarshaller();
            try {
                NamespacePrefixMapperUtils.setProperty(m, NamespacePrefixMapperUtils.getPrefixMapper());

                m.setProperty("jaxb.formatted.output", true);
            } catch (javax.xml.bind.PropertyException cnfe) {
                log.error(cnfe.getMessage(), cnfe);
            }
            m.marshal(flatOPC, fos);
            try {
                //just in case
                fos.close();
            } catch (IOException exc) {
                ;//ignore
            }

        } else if (saveAsFilePath.endsWith(Constants.HTML_STRING)) {
            FileObject fo = VFSUtils.getFileSystemManager().resolveFile(saveAsFilePath);
            OutputStream fos = fo.getContent().getOutputStream();
            javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(fos);
            //wmlPackage.html(result);
            AbstractHtmlExporter exporter = new HtmlExporterNG2();

            // .. the HtmlSettings object
            HtmlSettings htmlSettings = new HtmlSettings();
            htmlSettings.setImageDirPath(saveAsFilePath + "_files");
            htmlSettings.setImageTargetUri(
                    saveAsFilePath.substring(saveAsFilePath.lastIndexOf("/") + 1) + "_files");

            exporter.html(wmlPackage, result, htmlSettings);

            try {
                //just in case
                fos.close();
            } catch (IOException exc) {
                ;//ignore
            }
        } else {
            throw new Docx4JException("Invalid filepath = " + VFSUtils.getFriendlyName(saveAsFilePath));
        }
    } catch (Exception exc) {
        exc.printStackTrace();

        success = false;
        WordMLEditor wmlEditor = WordMLEditor.getInstance(WordMLEditor.class);
        ResourceMap rm = wmlEditor.getContext().getResourceMap(getClass());

        String title = rm.getString(callerActionName + ".Action.text");
        String message = rm.getString(callerActionName + ".Action.errorMessage") + "\n"
                + VFSUtils.getFriendlyName(saveAsFilePath);
        wmlEditor.showMessageDialog(title, message, JOptionPane.ERROR_MESSAGE);
    }

    return success;
}

From source file:org.drools.semantics.lang.dl.DL_9_CompilationTest.java

private void checkJaxbRefresh(Object obj, ClassLoader urlKL) {
    try {/*from w ww. java  2s .c  o  m*/
        JAXBContext jaxbContext;
        jaxbContext = JAXBContext.newInstance(obj.getClass().getPackage().getName(), urlKL);
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        StringWriter sw = new StringWriter();
        marshaller.marshal(obj, sw);

        System.out.println(sw.toString());

        jaxbContext = JAXBContext.newInstance(obj.getClass().getPackage().getName(), urlKL);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        Marshaller marshaller2 = jaxbContext.createMarshaller();
        marshaller2.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller2.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        Object clone = unmarshaller.unmarshal(new StringReader(sw.toString()));

        StringWriter sw2 = new StringWriter();
        marshaller2.marshal(clone, sw2);
        System.err.println(sw2.toString());

        assertEquals(sw.toString(), sw2.toString());
    } catch (PropertyException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (JAXBException e) {
        fail(e.getMessage());
    }
}

From source file:org.genericprodigy.rp.heroquest.classes.ClassMarshaller.java

/**
 * Marshals the {@link Model} object passed in to the {@code createInstance}
 * factory method into a new {@code MarshalledModel} entity object.
 *
 * @return {@link MarshalledModel} entity object with an XML representation
 * of the object state./*  ww w  . j a va 2 s .  c om*/
 */
public MarshalledModel marshal() {

    MarshalledXml xml = new MarshalledXml();
    String data = null;

    try {
        JAXBContext context = JAXBContext.newInstance(this.model.getClass());
        Marshaller marshaller = context.createMarshaller();
        StringWriter sw = new StringWriter();
        marshaller.marshal(this.model, sw);
        data = sw.toString();
        log.debug("Output Xml = " + sw.toString());
    } catch (javax.xml.bind.PropertyException propEx) {
        log.error("javax.xml.bind.PropertyException caught: " + propEx.getMessage(), propEx);
        propEx.printStackTrace();
    } catch (javax.xml.bind.JAXBException jaxbEx) {
        log.error("javax.xml.bind.JAXBException caught: " + jaxbEx.getMessage(), jaxbEx);
        jaxbEx.printStackTrace();
    } catch (Exception ex) {
        log.error("Exception caught: " + ex.getMessage(), ex);
        ex.printStackTrace();
    }

    xml.setData(data);
    return xml;
}

From source file:org.genericprodigy.rp.heroquest.classes.ClassMarshaller.java

/**
 * Unmarshals the {@link MarshalledModel} entity object from XML to a
 * {@link Model} object complete with existing state.
 *
 * @param data Marshalled entity representation of the object.
 * @return Unmarshalled entity object complete with state.
 *//*from www  .j av a 2  s .  c o  m*/
public T unmarshal(MarshalledModel data) {

    MarshalledXml xml = (MarshalledXml) data;
    T response = null;

    try {
        JAXBContext context = JAXBContext.newInstance(this.model.getClass());
        Unmarshaller unmarshaller = context.createUnmarshaller();
        StringReader sr = new StringReader(xml.getData());
        this.model = (T) unmarshaller.unmarshal(sr);
    } catch (javax.xml.bind.PropertyException propEx) {
        log.error("javax.xml.bind.PropertyException caught: " + propEx.getMessage(), propEx);
        propEx.printStackTrace();
    } catch (javax.xml.bind.JAXBException jaxbEx) {
        log.error("javax.xml.bind.JAXBException caught: " + jaxbEx.getMessage(), jaxbEx);
        jaxbEx.printStackTrace();
    } catch (Exception ex) {
        log.error("Exception caught: " + ex.getMessage(), ex);
        ex.printStackTrace();
    }

    return this.model;

}

From source file:org.genericprodigy.rp.heroquest.XmlMarshaller.java

/**
 * Marshals the {@link Model} object passed in to the {@code createInstance}
 * factory method into a new {@code MarshalledModel} entity object.
 *
 * @return {@link MarshalledModel} entity object with an XML representation
 * of the object state.// w w  w . ja  v a2 s .c o  m
 */
@Override
public MarshalledModel marshal() {
    MarshalledXml response = new MarshalledXml();

    String data = null;

    try {
        JAXBContext context = JAXBContext.newInstance(this.model.getClass());
        Marshaller marshaller = context.createMarshaller();
        StringWriter sw = new StringWriter();
        marshaller.marshal(this.model, sw);
        data = sw.toString();
        response.setData(data);
        log.debug("Output Xml = " + sw.toString());
    } catch (javax.xml.bind.PropertyException propEx) {
        log.error("javax.xml.bind.PropertyException caught: " + propEx.getMessage(), propEx);
        propEx.printStackTrace();
    } catch (javax.xml.bind.JAXBException jaxbEx) {
        log.error("javax.xml.bind.JAXBException caught: " + jaxbEx.getMessage(), jaxbEx);
        jaxbEx.printStackTrace();
    } catch (Exception ex) {
        log.error("Exception caught: " + ex.getMessage(), ex);
        ex.printStackTrace();
    }

    return (MarshalledModel) response;
}

From source file:org.genericprodigy.rp.heroquest.XmlMarshaller.java

/**
 * Unmarshals the {@link MarshalledModel} entity object from XML to a
 * {@link Model} object complete with existing state.
 *
 * @param data Marshalled entity representation of the object.
 * @return Unmarshalled entity object complete with state.
 *///from w w  w. j ava 2s . c  o  m
@Override
public T unmarshal(MarshalledModel data) {

    MarshalledXml xml = (MarshalledXml) data;
    T response = null;

    try {
        JAXBContext context = JAXBContext.newInstance(this.model.getClass());
        Unmarshaller unmarshaller = context.createUnmarshaller();
        StringReader sr = new StringReader(xml.getData());
        this.model = (T) unmarshaller.unmarshal(sr);
    } catch (javax.xml.bind.PropertyException propEx) {
        log.error("javax.xml.bind.PropertyException caught: " + propEx.getMessage(), propEx);
        propEx.printStackTrace();
    } catch (javax.xml.bind.JAXBException jaxbEx) {
        log.error("javax.xml.bind.JAXBException caught: " + jaxbEx.getMessage(), jaxbEx);
        jaxbEx.printStackTrace();
    } catch (Exception ex) {
        log.error("Exception caught: " + ex.getMessage(), ex);
        ex.printStackTrace();
    }

    return this.model;

}