public static Object unmarshallWithFilter(Unmarshaller unmarshaller, java.io.File source) throws FileNotFoundException, JAXBException { FileReader fr = null; try { fr = new FileReader(source); XMLReader reader = new NamespaceFilterXMLReader(); InputSource is = new InputSource(fr); SAXSource ss = new SAXSource(reader, is); return unmarshaller.unmarshal(ss); } catch (SAXException e) { //not technically a jaxb exception, but close enough throw new JAXBException(e); } catch (ParserConfigurationException e) { //not technically a jaxb exception, but close enough throw new JAXBException(e); } finally { FileUtil.close(fr); //replace with this some safe close method you have } }
/** * KML to Java * Similar to the other unmarshal methods * * with the exception that it transforms a InputStream into a graph of Java objects. * * */ public static Kml unmarshal(final InputStream content) { try { Unmarshaller unmarshaller = JAXBContext.newInstance((Kml.class)).createUnmarshaller(); InputSource input = new InputSource(content); SAXSource saxSource = new SAXSource(new NamespaceFilterXMLReader(false), input); Kml jaxbRootElement = ((Kml) unmarshaller.unmarshal(saxSource)); return jaxbRootElement; } catch (SAXException _x) { _x.printStackTrace(); } catch (ParserConfigurationException _x) { _x.printStackTrace(); } catch (JAXBException _x) { _x.printStackTrace(); } return null; }
/** * KML to Java * Similar to the other unmarshal methods * * with the exception that it transforms a InputStream into a graph of Java objects. * * */ public static Kml unmarshal(final InputStream content) { try { Unmarshaller unmarshaller = JAXBContext.newInstance((Kml.class)).createUnmarshaller(); InputSource input = new InputSource(content); SAXSource saxSource = new SAXSource(new NamespaceFilterXMLReader(false), input); Kml jaxbRootElement = ((Kml) unmarshaller.unmarshal(saxSource)); return jaxbRootElement; } catch (SAXException _x) { _x.printStackTrace(); } catch (ParserConfigurationException _x) { _x.printStackTrace(); } catch (JAXBException _x) { _x.printStackTrace(); } return null; }
/** * KML to Java * Similar to the other unmarshal methods * * with the exception that it transforms a String into a graph of Java objects. * * */ public static Kml unmarshal(final String content) { try { Unmarshaller unmarshaller = JAXBContext.newInstance((Kml.class)).createUnmarshaller(); InputSource input = new InputSource(new StringReader(content)); SAXSource saxSource = new SAXSource(new NamespaceFilterXMLReader(false), input); Kml jaxbRootElement = ((Kml) unmarshaller.unmarshal(saxSource)); return jaxbRootElement; } catch (SAXException _x) { _x.printStackTrace(); } catch (ParserConfigurationException _x) { _x.printStackTrace(); } catch (JAXBException _x) { _x.printStackTrace(); } return null; }
/** * KML to Java * Similar to the other unmarshal methods * * with the exception that it transforms a String into a graph of Java objects. * * */ public static Kml unmarshal(final String content) { try { Unmarshaller unmarshaller = JAXBContext.newInstance((Kml.class)).createUnmarshaller(); InputSource input = new InputSource(new StringReader(content)); SAXSource saxSource = new SAXSource(new NamespaceFilterXMLReader(false), input); Kml jaxbRootElement = ((Kml) unmarshaller.unmarshal(saxSource)); return jaxbRootElement; } catch (SAXException _x) { _x.printStackTrace(); } catch (ParserConfigurationException _x) { _x.printStackTrace(); } catch (JAXBException _x) { _x.printStackTrace(); } return null; }
/** * KML to Java * KML given as a file object is transformed into a graph of Java objects. * The boolean value indicates, whether the File object should be validated * automatically during unmarshalling and be checked if the object graph meets * all constraints defined in OGC's KML schema specification. * */ public static Kml unmarshal(final File file, final boolean validate) { try { Unmarshaller unmarshaller = JAXBContext.newInstance((Kml.class)).createUnmarshaller(); if (validate == true) { Kml.validate(unmarshaller); } InputSource input = new InputSource(new FileReader(file)); SAXSource saxSource = new SAXSource(new NamespaceFilterXMLReader(validate), input); Kml jaxbRootElement = ((Kml) unmarshaller.unmarshal(saxSource)); return jaxbRootElement; } catch (SAXException _x) { _x.printStackTrace(); } catch (ParserConfigurationException _x) { _x.printStackTrace(); } catch (JAXBException _x) { _x.printStackTrace(); } catch (FileNotFoundException _x) { _x.printStackTrace(); } return null; }
/** * KML to Java * KML given as a file object is transformed into a graph of Java objects. * The boolean value indicates, whether the File object should be validated * automatically during unmarshalling and be checked if the object graph meets * all constraints defined in OGC's KML schema specification. * */ public static Kml unmarshal(final File file, final boolean validate) { try { Unmarshaller unmarshaller = JAXBContext.newInstance((Kml.class)).createUnmarshaller(); if (validate == true) { Kml.validate(unmarshaller); } InputSource input = new InputSource(new FileReader(file)); SAXSource saxSource = new SAXSource(new NamespaceFilterXMLReader(validate), input); Kml jaxbRootElement = ((Kml) unmarshaller.unmarshal(saxSource)); return jaxbRootElement; } catch (SAXException _x) { _x.printStackTrace(); } catch (ParserConfigurationException _x) { _x.printStackTrace(); } catch (JAXBException _x) { _x.printStackTrace(); } catch (FileNotFoundException _x) { _x.printStackTrace(); } return null; }