Package org.simpleframework.xml.core

Examples of org.simpleframework.xml.core.Persister


 
  //FIXME (need to be removed in later versions) HACK to fix 2 deleted nodes in users.xml and inline Adresses and sipData
  private List<User> readUserList(InputSource xml, String listNodeName) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer ser = new Persister(strategy);

    registry.bind(Organisation.class, new OrganisationConverter(orgDao, organisationsMap));
    registry.bind(State.class, new StateConverter(statemanagement));
    registry.bind(Date.class, DateConverter.class);

    DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = dBuilder.parse(xml);
    NodeList nl = getNode(getNode(doc, "root"), listNodeName).getChildNodes();
    userEmailMap.clear();
    //add existence email from database
    List<User>  users = usersDao.getAllUsers();
    for (User u : users){
      if (u.getAdresses() == null || u.getAdresses().getEmail() == null || Type.user != u.getType()) {
        continue;
      }
      userEmailMap.put(u.getAdresses().getEmail(), -1);
    }
    // one of the old OM version created 2 nodes "deleted" this code block handles this
    for (int i = 0; i < nl.getLength(); ++i) {
      Node user = nl.item(i);
      NodeList nl1 = user.getChildNodes();
      boolean deletedFound = false;
      for (int j = 0; j < nl1.getLength(); ++j) {
        Node node = nl1.item(j);
        if (node.getNodeType() == Node.ELEMENT_NODE && "deleted".equals(node.getNodeName())) {
          if (deletedFound) {
            user.removeChild(node);
            break;
          }
          deletedFound = true;
        }
      }
    }
   
    StringWriter sw = new StringWriter();
    Transformer xformer = TransformerFactory.newInstance().newTransformer();
        xformer.transform(new DOMSource(doc), new StreamResult(sw));
       
    List<User> list = new ArrayList<User>();
    InputNode root = NodeBuilder.read(new StringReader(sw.toString()));
    InputNode root1 = NodeBuilder.read(new StringReader(sw.toString())); //HACK to handle Address inside user
    InputNode root2 = NodeBuilder.read(new StringReader(sw.toString())); //HACK to handle old om_time_zone, level_id, status
    InputNode listNode = root.getNext();
    InputNode listNode1 = root1.getNext(); //HACK to handle Address inside user
    InputNode listNode2 = root2.getNext(); //HACK to handle old om_time_zone
    if (listNodeName.equals(listNode.getName())) {
      InputNode item = listNode.getNext();
      InputNode item1 = listNode1.getNext(); //HACK to handle Address inside user
      InputNode item2 = listNode2.getNext(); //HACK to handle old om_time_zone, level_id, status
      while (item != null) {
        User u = ser.read(User.class, item, false);
       
        boolean needToSkip1 = true;
        //HACK to handle Address inside user
        if (u.getAdresses() == null) {
          Address a = ser.read(Address.class, item1, false);
          u.setAdresses(a);
          needToSkip1 = false;
        }
        if (needToSkip1) {
          do {
View Full Code Here


  public void performExport(File filePath, File backup_dir, boolean includeFiles) throws Exception {
    if (!backup_dir.exists()) {
      backup_dir.mkdirs();
    }
    Serializer simpleSerializer = new Persister();
   
    /*
     * ##################### Backup Organizations
     */
    writeList(simpleSerializer, backup_dir, "organizations.xml",
        "organisations", organisationDao.get(0, Integer.MAX_VALUE));

    /*
     * ##################### Backup Users
     */
    exportUsers(backup_dir, usersDao.getAllBackupUsers());

    /*
     * ##################### Backup Room
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(RoomType.class, RoomTypeConverter.class);
     
      writeList(serializer, backup_dir, "rooms.xml", "rooms", roomDao.get());
    }

    /*
     * ##################### Backup Room Organizations
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(Organisation.class, OrganisationConverter.class);
      registry.bind(Room.class, RoomConverter.class);
     
      writeList(serializer, backup_dir, "rooms_organisation.xml",
          "room_organisations", roomOrganisationDao.get());
    }

    /*
     * ##################### Backup Appointments
     */
    {
      List<Appointment> list = appointmentDao.getAppointments();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(AppointmentCategory.class, AppointmentCategoryConverter.class);
      registry.bind(User.class, UserConverter.class);
      registry.bind(AppointmentReminderTyps.class, AppointmentReminderTypeConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getStart().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "appointements.xml", "appointments", list);
    }

    /*
     * ##################### Backup Meeting Members
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Appointment.class, AppointmentConverter.class);
     
      writeList(serializer, backup_dir, "meetingmembers.xml",
          "meetingmembers", meetingMemberDao.getMeetingMembers());
    }

    /*
     * ##################### LDAP Configs
     */
    writeList(simpleSerializer, backup_dir, "ldapconfigs.xml",
        "ldapconfigs", ldapConfigDao.get());

    /*
     * ##################### Cluster servers
     */
    writeList(simpleSerializer, backup_dir, "servers.xml", "servers", serverDao.get(0, Integer.MAX_VALUE));

    /*
     * ##################### OAuth2 servers
     */
    writeList(simpleSerializer, backup_dir, "oauth2servers.xml", "oauth2servers", auth2Dao.get(0, Integer.MAX_VALUE));

    /*
     * ##################### Private Messages
     */
    {
      List<PrivateMessage> list = privateMessagesDao.get(0, Integer.MAX_VALUE);
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getInserted().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "privateMessages.xml",
          "privatemessages", list);
    }

    /*
     * ##################### Private Message Folders
     */
    writeList(simpleSerializer, backup_dir, "privateMessageFolder.xml",
        "privatemessagefolders", privateMessageFolderDao.get(0, Integer.MAX_VALUE));

    /*
     * ##################### User Contacts
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
     
      writeList(serializer, backup_dir, "userContacts.xml",
          "usercontacts", userContactsDao.getUserContacts());
    }

    /*
     * ##################### File-Explorer
     */
    {
      List<FileExplorerItem> list = fileExplorerItemDao.getFileExplorerItems();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getInserted().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "fileExplorerItems.xml",
          "fileExplorerItems", list);
    }

    /*
     * ##################### Recordings
     */
    {
      List<FlvRecording> list = flvRecordingDao.getAllFlvRecordings();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getInserted().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "flvRecordings.xml",
          "flvrecordings", list);
    }

    /*
     * ##################### Polls
     */
    {
      List<RoomPoll> list = pollManager.getPollListBackup();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      registry.bind(PollType.class, PollTypeConverter.class);
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getCreated().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "roompolls.xml", "roompolls", list);
    }

    /*
     * ##################### Config
     */
    {
      List<Configuration> list = configurationDao.getConfigurations(
          0, Integer.MAX_VALUE, "c.configuration_id", true);
      Registry registry = new Registry();
      registry.bind(State.class, StateConverter.class);
      registry.bind(User.class, UserConverter.class);
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getStarttime().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "configs.xml", "configs", list);
    }
   
    /*
     * ##################### Chat
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      List<ChatMessage> list = chatDao.get(0, Integer.MAX_VALUE);
      if (list != null && list.size() > 0) {
View Full Code Here

  }
 
  public void exportUsers(OutputStream os, List<User> list) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(Organisation.class, OrganisationConverter.class);
    registry.bind(State.class, StateConverter.class);
    if (list != null && list.size() > 0) {
      registry.bind(list.get(0).getRegdate().getClass(), DateConverter.class);
View Full Code Here

  private void check(char[] chars) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
   
    RegistryMatcher rm = new RegistryMatcher();
    rm.bind(String.class, XmlStringTransformerAccess.getInstance());
    Persister persister = new Persister(rm);
    persister.write(new Model(new String(chars)), baos);

    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    try {
      docBuilder.parse(new ByteArrayInputStream(baos.toByteArray()));
View Full Code Here

  private final Map<Class<?>, SimpleXmlResponseExtractor<?>> cache = new HashMap<Class<?>, SimpleXmlResponseExtractor<?>>();

  private final Persister persister;

  public SimpleXmlExtractorFactory() {
    this.persister = new Persister();
  }
View Full Code Here

public class SimpleXmlRequestMarshaller implements RequestBodyMarshaller {

  private final Persister persister;

  public SimpleXmlRequestMarshaller() {
    this.persister = new Persister();
  }
View Full Code Here

   *
   * @param object property annotated object
   * @return XML representation of the object
   */
  public static String generateRequest(Object object) {
    Serializer serializer = new Persister();
    StringWriter writer = new StringWriter();
    try {
      serializer.write(object, writer);
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, "Failed to generate XML request!", e);
      return null;
    }
    return writer.toString();
View Full Code Here

   *
   * @param object property annotated object
   * @param outputStream the stream to write the XML to
   */
  public static void generateRequest(Object object, OutputStream outputStream) {
    Serializer serializer = new Persister();
    try {
      serializer.write(object, outputStream);
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, "Failed to generate XML request!", e);
    }
  }
View Full Code Here

   * @param xml string containing the XML to be converted to object
   * @param clazz the type of the return object
   * @return
   */
  public static <T> T parseResponse(String xml, Class<T> clazz) {
    Serializer serializer = new Persister(new JWebThumbMatcher());
    try {
      return serializer.read(clazz, xml);
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, "Failed to parse XML response!", e);
      return null;
    }
  }
View Full Code Here

   * @param inputStream the stream to read the XML from
   * @param clazz the type of the return object
   * @return
   */
  public static <T> T parseResponse(InputStream inputStream, Class<T> clazz) {
    Serializer serializer = new Persister(new JWebThumbMatcher());
    try {
      return serializer.read(clazz, inputStream);
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, "Failed to parse XML response!", e);
      return null;
    }
  }
View Full Code Here

TOP

Related Classes of org.simpleframework.xml.core.Persister

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.