Refine search
protected static org.docx4j.wml.P loadParagraph(String filename) throws Exception { java.io.File f = new java.io.File(filename); java.io.InputStream is = new java.io.FileInputStream(f); JAXBContext jc = org.docx4j.jaxb.Context.jc; Unmarshaller u = jc.createUnmarshaller(); //u.setSchema(org.docx4j.jaxb.WmlSchema.schema); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); return (org.docx4j.wml.P)u.unmarshal( is ); }
/** * Prepare a JAXB transformation result for some given context. * @param context The JAXB context. * @return The result data structure created. * @throws Docx4JException In case of configuration errors. */ public static JAXBResult prepareJAXBResult(final JAXBContext context) 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); } return result; }
Unmarshaller u = m_context.createUnmarshaller(); u.setEventHandler(new JAXBValidator()); u.unmarshal(...);
public static Object unmarshalString(String str, JAXBContext jc, Class declaredType) throws JAXBException { Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); Object o = u.unmarshal( new javax.xml.transform.stream.StreamSource(new java.io.StringReader(str)), declaredType); if (o instanceof JAXBElement) { return ((JAXBElement)o).getValue(); } else { return o; } }
Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(eventHandler);
public final T load(StreamSource source, Class<T> clazz, Class<?> factory, URL xsdFile) throws JAXBException, SAXException { T result; synchronized (SYNC_OBJECT) { // TODO creating a JaxbContext is expensive, consider pooling. Unmarshaller unmarshaller = createUnmarshaller(factory, xsdFile); unmarshaller.setEventHandler(new XmlValidationEventHandler()); result = unmarshaller.unmarshal(source, clazz).getValue(); } return result; }
public static Object unmarshal(Node n, JAXBContext jc, Class declaredType) throws JAXBException { // THIS DOESN"T WORK PROPERLY WITH 1.6.0.03 JAXB RI // (at least with CTTextParagraphProperties in // a Xalan org.apache.xml.dtm.ref.DTMNodeProxy) // but converting the Node to a String and // unmarshalling that is fine! Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); Object o = u.unmarshal(n, declaredType); if ( o instanceof javax.xml.bind.JAXBElement) { return ((JAXBElement)o).getValue(); } else { return o; } }
Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(eventHandler);
public static <T> T unmarshal(final Class<T> clazz, final InputSource inputSource, final JAXBContext jaxbContext, final boolean validate) { final Unmarshaller um = getUnmarshallerFor(clazz, jaxbContext, validate); LOG.trace("unmarshalling class {} from input source {} with unmarshaller {}", clazz.getSimpleName(), inputSource, um); try { final XMLFilter filter = getXMLFilterForClass(clazz); final SAXSource source = new SAXSource(filter, inputSource); um.setEventHandler(new LoggingValidationEventHandler()); final JAXBElement<T> element = um.unmarshal(source, clazz); return element.getValue(); } catch (final SAXException e) { throw EXCEPTION_TRANSLATOR.translate("creating an XML reader object", e); } catch (final JAXBException e) { throw EXCEPTION_TRANSLATOR.translate("unmarshalling an object (" + clazz.getSimpleName() + ")", e); } }
public static void enteredTbl(BindingTraverserState btState, NodeIterator nodeIterator) { Node n = nodeIterator.nextNode(); //It is never null if (n != null) { try { Unmarshaller u = Context.jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); Object jaxb = u.unmarshal(n); btState.tblStack.push( (Tbl)jaxb); } catch (ClassCastException e) { log.error("Couldn't cast to Tbl!"); } catch (JAXBException e) { log.error(e.getMessage(), e); } } }
/** * Convert any w:fldSimple in this part to complex field. * @param part * @throws Docx4JException */ public static void complexifyFields(JaxbXmlPart part) throws Docx4JException { org.w3c.dom.Document doc = XmlUtils.marshaltoW3CDomDocument( part.getJaxbElement() ); // XPathsPart xPathsPart = null; JAXBContext jc = Context.jc; try { // Use constructor which takes Unmarshaller, rather than JAXBContext, // so we can set JaxbValidationEventHandler Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); javax.xml.bind.util.JAXBResult result = new javax.xml.bind.util.JAXBResult(u ); org.docx4j.XmlUtils.transform(doc, xslt, null, result); part.setJaxbElement(result); } catch (Exception e) { throw new Docx4JException("Problems transforming fields", e); } }
public static void enteredTc(BindingTraverserState btState, NodeIterator nodeIterator) { Node n = nodeIterator.nextNode(); //It is never null if (n!=null) { try { Unmarshaller u = Context.jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); Object jaxb = u.unmarshal(n); btState.tcStack.push( (Tc)jaxb ); } catch (ClassCastException e) { log.error("Couldn't cast to RPr!"); } catch (JAXBException e) { log.error(e.getMessage(), e); } } }
Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); javax.xml.bind.util.JAXBResult result = new javax.xml.bind.util.JAXBResult(u );
@Override // need this so that resetIdAllocator() is called public Relationships unmarshal(org.w3c.dom.Element el) throws JAXBException { try { Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); jaxbElement = (Relationships) u.unmarshal( el ); } catch (JAXBException e) { // e.printStackTrace(); log.error(e.getMessage(), e); throw e; } resetIdAllocator(); return jaxbElement; }
protected Unmarshaller getUnmarshaller() { try { Unmarshaller um = getContext().createUnmarshaller(); um.setEventHandler(null); return um; } catch (JAXBException e) { throw new RuntimeException(e); } }
/** * Unmarshal a node using Context.jc, WITHOUT fallback to pre-processing in case of failure. * @param n * @return * @throws JAXBException */ public static Object unmarshal(Node n) throws JAXBException { Unmarshaller u = Context.jc.createUnmarshaller(); JaxbValidationEventHandler veh = new org.docx4j.jaxb.JaxbValidationEventHandler(); veh.setContinue(true); u.setEventHandler(veh); return u.unmarshal( n ); }
protected Unmarshaller getUnmarshaller() { try { Unmarshaller um = getContext().createUnmarshaller(); um.setEventHandler(null); return um; } catch (JAXBException e) { throw new RuntimeException(e); } }
/** * Unmarshal a node using Context.jc, WITHOUT fallback to pre-processing in case of failure. * @param n * @return * @throws JAXBException */ private Object unmarshal(Node n, boolean continu) throws JAXBException { Unmarshaller u = Context.jc.createUnmarshaller(); JaxbValidationEventHandler veh = new org.docx4j.jaxb.JaxbValidationEventHandler(); veh.setContinue(continu); u.setEventHandler(veh); return u.unmarshal( n ); }
public Unmarshaller create(final IJaxbContext jaxbContext) throws JAXBException, SAXException { final JAXBContext context = JAXBContext.newInstance(jaxbContext.getObjectFactories()); final Unmarshaller unmarshaller = context.createUnmarshaller(); final SchemaFactory schemaFactory = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); final Source[] sources = jaxbContext.getSchemaSources(); final Schema schema = schemaFactory.newSchema(sources); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler()); return unmarshaller; }
/** * Unmarshal a node using Context.jc, WITHOUT fallback to pre-processing in case of failure. * @param n * @return * @throws JAXBException */ private Object unmarshal(Node n, boolean continu) throws JAXBException { Unmarshaller u = Context.jc.createUnmarshaller(); JaxbValidationEventHandler veh = new org.docx4j.jaxb.JaxbValidationEventHandler(); veh.setContinue(continu); u.setEventHandler(veh); return u.unmarshal( n ); }