Package org.simpleframework.xml

Examples of org.simpleframework.xml.Serializer


 
  //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) {
        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
    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
      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 save(File file, List<CipherSpec> cipherSpecs, SaltedSecretKey masterKey) throws ConfigException {
    try {

      ByteArrayOutputStream plaintextRepoOutputStream = new ByteArrayOutputStream();

      Serializer serializer = new Persister();
      serializer.write(this, plaintextRepoOutputStream);

      CipherUtil.encrypt(new ByteArrayInputStream(plaintextRepoOutputStream.toByteArray()), new FileOutputStream(file), cipherSpecs, masterKey);
    }
    catch (Exception e) {
      throw new ConfigException("Cannot write repoTO (encrypted) to file " + file, e);
View Full Code Here

    else {
      out = new PrintWriter(new OutputStreamWriter(
          transformer.createOutputStream(new FileOutputStream(transactionFile)), "UTF-8"));
    }

    Serializer serializer = new Persister();
    serializer.write(this, out);
    out.flush();
    out.close();
  }
View Full Code Here

    lts.setPath(File.createTempFile("aaa", "bbb"));
    ts.subsettings = lts;

    assertTrue(ts.isValid());

    Serializer serializer = new Persister();
    serializer.write(conf, tmpFile);

    System.out.println(new String(Files.readAllBytes(Paths.get(tmpFile.toURI()))));

    ConfigTO confRestored = ConfigTO.load(tmpFile);
    TransferPlugin plugin = Plugins.get(confRestored.getTransferSettings().getType(), TransferPlugin.class);
View Full Code Here

    assertFalse(ts.isValid());
  }

  @Test
  public void testDeserializeCorrectClass() throws Exception {
    Serializer serializer = new Persister();

    // Always LocalTransferSettings
    serializer.write(TestConfigUtil.createTestInitOperationOptions("syncanytest").getConfigTO(), tmpFile);

    ConfigTO confRestored = ConfigTO.load(tmpFile);

    assertEquals(LocalTransferSettings.class, confRestored.getTransferSettings().getClass());
  }
View Full Code Here

  public void testDeserializeWrongClass() throws Exception {

    LocalTransferSettings lts = new LocalTransferSettings();
    lts.setPath(tmpFile);

    Serializer serializer = new Persister();
    serializer.write(lts, tmpFile);

    // This shouldn't blow up!
    serializer.read(DummyTransferSettings.class, tmpFile);
  }
View Full Code Here

    }
  }

  private void verifyRepoFile(String repoFileStr) throws StorageException {
    try {
      Serializer serializer = new Persister();
      serializer.read(RepoTO.class, repoFileStr);
    }
    catch (Exception e) {
      throw new StorageException("Repo file corrupt.", e);
    }
  }
View Full Code Here

    }
  }

  private MasterTO readMasterFile(File tmpMasterFile) throws StorageException {
    try {
      Serializer serializer = new Persister();
      return serializer.read(MasterTO.class, tmpMasterFile);
    }
    catch (Exception e) {
      throw new StorageException("Master file corrupt.", e);
    }
  }
View Full Code Here

    return toStringArray(bufferedCliOut);
  }

  private static void fixMachineName(Map<String, String> client) throws Exception {
    File configFile = new File(client.get("localdir") + "/" + Config.DIR_APPLICATION + "/" + Config.FILE_CONFIG);
    Serializer serializer = new Persister();

    ConfigTO configTO = serializer.read(ConfigTO.class, configFile);
    configTO.setMachineName(client.get("machinename"));

    serializer.write(configTO, configFile);
  }
View Full Code Here

        TimeZone.setDefault(TimeZone.getTimeZone("GMT 0"));
       
        Long version = appDefinitionDao.getLatestVersion(appId);
        AppDefinition appDef = appDefinitionDao.loadVersion(appId, version);

        Serializer serializer = new Persister();
        AppDefinition newAppDef = null;

        try {
            newAppDef = serializer.read(AppDefinition.class, new ByteArrayInputStream(getAppDefinitionXml(appId, version)), "UTF-8");
        } catch (Exception e) {
            LogUtil.error(AppServiceImpl.class.getName(), e, appId);
        } finally {
            TimeZone.setDefault(current);
        }
View Full Code Here

TOP

Related Classes of org.simpleframework.xml.Serializer

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.