Class XmlHelper

java.lang.Object
com.priint.pubserver.comet.xml.XmlHelper

public class XmlHelper extends Object
Internal use only The Class XmlHelper.
  • Field Details

    • FORMATTED_OUTPUT

      public static final Boolean FORMATTED_OUTPUT
      If set to true, the XML output will be formatted (line breaks + indent), otherwise ignorable whitespaces will be omitted.
    • RAISE_EXCEPTIONS

      public static final Boolean RAISE_EXCEPTIONS
      If set to true, RuntimeExceptions will be raised upon error, otherwise the serialize / deserialize methods will just return null.
  • Method Details

    • deserialize

      public static <T> T deserialize(String xml, Class<T> clazz)
      Deserialize a piece of XML and return a CometCollection.
      Type Parameters:
      T - the generic type
      Parameters:
      xml - the xml
      clazz - target class (CometCollection<T>, e.g. com.priint.comet.configuration.entities.Actions)
      Returns:
      CometCollection list of the requested target class or null on any failure
    • deserialize

      public static <T> T deserialize(byte[] data, Class<T> clazz)
      Deserialize a piece of XML and return a CometCollection.
      Type Parameters:
      T - the generic type
      Parameters:
      data - the data
      clazz - target class (CometCollection<T>, e.g. com.priint.comet.configuration.entities.Actions)
      Returns:
      CometCollection list of the requested target class or null on any failure
    • deserialize

      public static <T> T deserialize(jakarta.activation.DataHandler data, Class<T> clazz)
      Deserialize a piece of XML and return a CometCollection
      Type Parameters:
      T - the generic type
      Parameters:
      data - the data
      clazz - target class (CometCollection<T>, e.g. com.priint.comet.configuration.entities.Actions)
      Returns:
      CometCollection list of the requested target class or null on any failure
    • deserialize

      public static <T> T deserialize(InputStream in, Class<T> clazz)
      Deserialize a piece of XML and return a CometCollection
      Type Parameters:
      T - the generic type
      Parameters:
      in - the in
      clazz - target class (CometCollection<T>, e.g. com.priint.comet.configuration.entities.Actions)
      Returns:
      CometCollection list of the requested target class or null on any failure
    • serialize

      public static <T> ByteArrayOutputStream serialize(List<T> list, String rootElement)
      Serialize a List, use an arbitrary name for the root element.
      Type Parameters:
      T - the generic type
      Parameters:
      list - the list
      rootElement - the root element
      Returns:
      XML (OutputStream) or null on failure
    • serialize

      public static ByteArrayOutputStream serialize(Object item, String rootElement)
      Serialize an Object, use an arbitrary name for the root element.
      Parameters:
      item - the item
      rootElement - the root element
      Returns:
      XML (OutputStream) or null on failure
    • generateSchema

      public static OutputStream generateSchema(Class<?>[] clazz)
      Generate schema.
      Parameters:
      clazz - the clazz
      Returns:
      the output stream
    • generateSchema

      public static OutputStream generateSchema(Class<?> clazz)
      Generate schema.
      Parameters:
      clazz - the clazz
      Returns:
      the output stream
    • getDataHandler

      public static <T> jakarta.activation.DataHandler getDataHandler(List<T> list, String rootElementName)

      Create a DataHandler from a CometCollection.

      This is just a shortcut for

                              DataHandler data = new DataHandler (new DataSource () {
                              @Override
                              public String getContentType() {
                                      return "application/xml";
                              }
       
                              @Override
                              public InputStream getInputStream()
                                              throws IOException {
                                      return null;
                              }
       
                              @Override
                              public String getName() {
                                      return list.getXmlFileName ();
                              }
       
                              @Override
                              public OutputStream getOutputStream()
                                              throws IOException {
                                      return XmlUtils.serialize (list);
                              }
                              
                      });
       

      Type Parameters:
      T - the generic type
      Parameters:
      list - the list
      rootElementName - the root element name
      Returns:
      DataHandler or null on any failure
    • getInputStream

      public static <T> InputStream getInputStream(List<T> list, String rootElementName)