@SuppressWarnings("unchecked") public static <T> T unmarshal(final InputStream in) throws IOException { final Unmarshaller unmarshaller = SardineUtil.createUnmarshaller(); try { final XMLReader reader = XMLReaderFactory.createXMLReader(); try { reader.setFeature("http://xml.org/sax/features/external-general-entities", Boolean.FALSE); } catch (final SAXException e) {; // Not all parsers will support this attribute } try { reader.setFeature("http://xml.org/sax/features/external-parameter-entities", Boolean.FALSE); } catch (final SAXException e) {; // Not all parsers will support this attribute } try { reader.setFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.FALSE); } catch (final SAXException e) {; // Not all parsers will support this attribute } try { reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); } catch (final SAXException e) {; // Not all parsers will support this attribute } return (T) unmarshaller.unmarshal(new SAXSource(reader, new InputSource(in))); } catch (final SAXException e) { throw new RuntimeException(e.getMessage(), e); } catch (final JAXBException e) { // Server does not return any valid WebDAV XML that matches our JAXB context final IOException failure = new IOException("Not a valid DAV response"); // Backward compatibility failure.initCause(e); throw failure; } }
/** * @param jaxbElement An object from the model * @return The XML string for the WebDAV request * @throws IOException When there is a JAXB error */ public static String toXml(final Object jaxbElement) { final StringWriter writer = new StringWriter(); try { final Marshaller marshaller = SardineUtil.createMarshaller(); marshaller.marshal(jaxbElement, writer); } catch (final JAXBException e) { throw new RuntimeException(e.getMessage(), e); } return writer.toString(); }
public static List<QName> toQName(final List<String> removeProps) { if (removeProps == null) { return Collections.emptyList(); } final List<QName> result = new ArrayList<QName>(removeProps.size()); for (final String entry : removeProps) { result.add(SardineUtil.createQNameWithCustomNamespace(entry)); } return result; }
public static Map<QName, String> toQName(final Map<String, String> setProps) { if (setProps == null) { return Collections.emptyMap(); } final Map<QName, String> result = new HashMap<QName, String>(setProps.size()); for (final Map.Entry<String, String> entry : setProps.entrySet()) { result.put(SardineUtil.createQNameWithCustomNamespace(entry.getKey()), entry.getValue()); } return result; }
/** @param key Fully qualified element name. */ public static Element createElement(final QName key) { return SardineUtil.createDocument() .createElementNS(key.getNamespaceURI(), key.getPrefix() + ":" + key.getLocalPart()); }