Search in sources :

Example 41 with Persister

use of org.simpleframework.xml.core.Persister in project netxms by netxms.

the class XMLTools method createSerializer.

/**
 * Create serializer with registered converters
 *
 * @return serializer with registered converters
 * @throws Exception on XML library failures
 */
public static Serializer createSerializer() throws Exception {
    Registry registry = new Registry();
    registry.bind(UUID.class, UUIDConverter.class);
    return new Persister(new AnnotationStrategy(new RegistryStrategy(registry)));
}
Also used : AnnotationStrategy(org.simpleframework.xml.convert.AnnotationStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister)

Example 42 with Persister

use of org.simpleframework.xml.core.Persister in project netxms by netxms.

the class PassiveRackElementGroup method createXml.

/**
 * Create XML from configuration
 *
 * @return XML document
 * @throws Exception if the schema for the object is not valid
 */
public String createXml() throws Exception {
    Serializer serializer = new Persister();
    Writer writer = new StringWriter();
    serializer.write(this, writer);
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) Persister(org.simpleframework.xml.core.Persister) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Serializer(org.simpleframework.xml.Serializer)

Example 43 with Persister

use of org.simpleframework.xml.core.Persister in project netxms by netxms.

the class InputFieldOptions method createXml.

/**
 * Create XML from configuration.
 *
 * @return XML document or null if serialization failed
 */
public String createXml() {
    try {
        Serializer serializer = new Persister();
        Writer writer = new StringWriter();
        serializer.write(this, writer);
        return writer.toString();
    } catch (Exception e) {
        return null;
    }
}
Also used : StringWriter(java.io.StringWriter) Persister(org.simpleframework.xml.core.Persister) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Serializer(org.simpleframework.xml.Serializer)

Example 44 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class TransactionTO method save.

public void save(Transformer transformer, File transactionFile) throws Exception {
    PrintWriter out;
    if (transformer == null) {
        out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(transactionFile), "UTF-8"));
    } 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();
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Persister(org.simpleframework.xml.core.Persister) PrintWriter(java.io.PrintWriter) Serializer(org.simpleframework.xml.Serializer)

Example 45 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class ApplicationLink method createTransferSettings.

private TransferSettings createTransferSettings(byte[] plaintextPluginSettingsBytes) throws StorageException, IOException {
    // Find plugin ID and settings XML
    int pluginIdentifierLength = Ints.fromByteArray(Arrays.copyOfRange(plaintextPluginSettingsBytes, 0, INTEGER_BYTES));
    String pluginId = new String(Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES, INTEGER_BYTES + pluginIdentifierLength));
    byte[] gzippedPluginSettingsByteArray = Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES + pluginIdentifierLength, plaintextPluginSettingsBytes.length);
    String pluginSettings = IOUtils.toString(new GZIPInputStream(new ByteArrayInputStream(gzippedPluginSettingsByteArray)));
    // Create transfer settings object
    try {
        TransferPlugin plugin = Plugins.get(pluginId, TransferPlugin.class);
        if (plugin == null) {
            throw new StorageException("Link contains unknown connection type '" + pluginId + "'. Corresponding plugin not found.");
        }
        Class<? extends TransferSettings> pluginTransferSettingsClass = TransferPluginUtil.getTransferSettingsClass(plugin.getClass());
        TransferSettings transferSettings = new Persister().read(pluginTransferSettingsClass, pluginSettings);
        logger.log(Level.INFO, "(Decrypted) link contains: " + pluginId + " -- " + pluginSettings);
        return transferSettings;
    } catch (Exception e) {
        throw new StorageException(e);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) ByteArrayInputStream(java.io.ByteArrayInputStream) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) StorageException(org.syncany.plugins.transfer.StorageException) IOException(java.io.IOException)

Aggregations

Persister (org.simpleframework.xml.core.Persister)187 Serializer (org.simpleframework.xml.Serializer)149 StringWriter (java.io.StringWriter)74 Writer (java.io.Writer)62 Registry (org.simpleframework.xml.convert.Registry)30 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)30 Strategy (org.simpleframework.xml.strategy.Strategy)30 AnnotationStrategy (org.simpleframework.xml.convert.AnnotationStrategy)20 File (java.io.File)19 Test (org.junit.Test)14 IOException (java.io.IOException)13 Format (org.simpleframework.xml.stream.Format)11 StorageException (org.syncany.plugins.transfer.StorageException)8 Style (org.simpleframework.xml.stream.Style)7 RegistryMatcher (org.simpleframework.xml.transform.RegistryMatcher)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 SimpleDateFormat (java.text.SimpleDateFormat)5 ArrayList (java.util.ArrayList)5 CamelCaseStyle (org.simpleframework.xml.stream.CamelCaseStyle)5 ConfigTO (org.syncany.config.to.ConfigTO)5