Ejemplo n.º 1
0
 @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;
   }
 }
Ejemplo n.º 2
0
 /**
  * @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();
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 /** @param key Fully qualified element name. */
 public static Element createElement(final QName key) {
   return SardineUtil.createDocument()
       .createElementNS(key.getNamespaceURI(), key.getPrefix() + ":" + key.getLocalPart());
 }