Search in sources :

Example 81 with Persister

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

the class DeviceFacadeImpl method parseDevicePropertiesXML.

/**
 * Parse the XML representation of the properties of a device (which comes
 * from configuration) and return it as a list of {@link DeviceProperty}
 * objects.
 *
 * @param xmlString the XML representation string of the device properties
 *
 * @return the list of device properties
 * @throws Exception if the XML could not be parsed
 */
private List<DeviceProperty> parseDevicePropertiesXML(String xmlString) throws Exception {
    List<DeviceProperty> deviceProperties = new ArrayList<>();
    Serializer serializer = new Persister();
    DevicePropertyList devicePropertyList = serializer.read(DevicePropertyList.class, xmlString);
    for (DeviceProperty deviceProperty : devicePropertyList.getDeviceProperties()) {
        // Remove all whitespace and control characters
        if (deviceProperty.getValue() != null) {
            deviceProperty.setValue(deviceProperty.getValue().replaceAll("[\u0000-\u001f]", "").trim());
        }
        deviceProperties.add(deviceProperty);
    }
    return deviceProperties;
}
Also used : DeviceProperty(cern.c2mon.shared.client.device.DeviceProperty) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 82 with Persister

use of org.simpleframework.xml.core.Persister in project java-apply by javachengwc.

the class Main method main.

public static void main(String[] args) throws Exception {
    Serializer serializer = new Persister();
    Main example = new Main("Example message", 123);
    File result = new File("E:/tmp/example.xml");
    serializer.write(example, result);
    Main _obj = serializer.read(Main.class, result);
    System.out.println(_obj.getMessage());
}
Also used : Persister(org.simpleframework.xml.core.Persister) File(java.io.File)

Example 83 with Persister

use of org.simpleframework.xml.core.Persister in project java-apply by javachengwc.

the class Main2 method main.

public static void main(String[] args) throws Exception {
    Customer customer = new Customer(111L, "张三");
    Order order1 = new Order(1L, new Date());
    Order order2 = new Order(2L, new Date());
    Item item11 = new Item(1, 11L);
    Item item21 = new Item(2, 21L);
    Address address = new Address("450000", "瑞达路XX#", true);
    customer.setAddress(address);
    customer.getOrderList().add(order1);
    customer.getOrderList().add(order2);
    order1.getItemList().add(item11);
    order2.getItemList().add(item21);
    Serializer serializer = new Persister();
    File result = new File("E:/tmp/customer.xml");
    serializer.write(customer, result);
    Customer _obj = serializer.read(Customer.class, result);
    System.out.println(_obj.getName());
    System.out.println(_obj.getOrderList().get(0).getCdate());
}
Also used : Order(com.model.Order) Item(com.model.Item) Address(com.model.Address) Customer(com.model.Customer) Persister(org.simpleframework.xml.core.Persister) File(java.io.File) Date(java.util.Date)

Example 84 with Persister

use of org.simpleframework.xml.core.Persister in project formplayer by dimagi.

the class FormSubmissionController method parseSubmitResponseMessage.

private void parseSubmitResponseMessage(String responseBody, SubmitResponseBean submitResponseBean) {
    if (responseBody != null) {
        try {
            Serializer serializer = new Persister();
            OpenRosaResponse openRosaResponse = serializer.read(OpenRosaResponse.class, responseBody);
            if (openRosaResponse != null && openRosaResponse.getMessage() != null) {
                submitResponseBean.setSubmitResponseMessage(openRosaResponse.getMessage());
            }
        } catch (Exception e) {
            log.error("Exception parsing submission response body", e);
        }
    }
}
Also used : Persister(org.simpleframework.xml.core.Persister) OpenRosaResponse(org.commcare.formplayer.beans.OpenRosaResponse) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) InvalidCaseGraphException(org.commcare.cases.util.InvalidCaseGraphException) Serializer(org.simpleframework.xml.Serializer)

Example 85 with Persister

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

the class ConfigTO method load.

public static ConfigTO load(File file) throws ConfigException {
    try {
        Registry registry = new Registry();
        Strategy strategy = new RegistryStrategy(registry);
        registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter());
        registry.bind(String.class, new EncryptedTransferSettingsConverter());
        return new Persister(strategy).read(ConfigTO.class, file);
    } catch (ClassNotFoundException ex) {
        // Ugly hack to catch common case of non-existing plugin
        String message = ex.getMessage();
        if (!message.startsWith("org.syncany.plugins.")) {
            // Apparently there are other ClassNotFoundExceptions possible.
            throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
        }
        message = message.replaceFirst("org.syncany.plugins.", "");
        message = message.replaceAll("\\..*", "");
        throw new ConfigException("Is the " + message + " plugin installed?");
    } catch (Exception ex) {
        throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
    }
}
Also used : SaltedSecretKeyConverter(org.syncany.crypto.SaltedSecretKeyConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) ConfigException(org.syncany.config.ConfigException) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) EncryptedTransferSettingsConverter(org.syncany.plugins.transfer.EncryptedTransferSettingsConverter) ConfigException(org.syncany.config.ConfigException)

Aggregations

Persister (org.simpleframework.xml.core.Persister)177 Serializer (org.simpleframework.xml.Serializer)141 StringWriter (java.io.StringWriter)74 Writer (java.io.Writer)62 Registry (org.simpleframework.xml.convert.Registry)23 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)23 Strategy (org.simpleframework.xml.strategy.Strategy)23 AnnotationStrategy (org.simpleframework.xml.convert.AnnotationStrategy)20 File (java.io.File)18 Test (org.junit.Test)14 IOException (java.io.IOException)12 StorageException (org.syncany.plugins.transfer.StorageException)8 RegistryMatcher (org.simpleframework.xml.transform.RegistryMatcher)6 ConfigTO (org.syncany.config.to.ConfigTO)5 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileOutputStream (java.io.FileOutputStream)4 DateFormat (java.text.DateFormat)4 SimpleDateFormat (java.text.SimpleDateFormat)4 ArrayList (java.util.ArrayList)4