Search in sources :

Example 1 with Link

use of com.enonic.xp.util.Link in project xp by enonic.

the class ScriptValueTranslator method handleValue.

private void handleValue(final PropertySet parent, final String name, final Object value) {
    if (value instanceof Instant) {
        parent.addInstant(name, (Instant) value);
    } else if (value instanceof GeoPoint) {
        parent.addGeoPoint(name, (GeoPoint) value);
    } else if (value instanceof Double) {
        parent.addDouble(name, (Double) value);
    } else if (value instanceof Float) {
        parent.addDouble(name, ((Float) value).doubleValue());
    } else if (value instanceof Integer) {
        parent.addLong(name, ((Integer) value).longValue());
    } else if (value instanceof Byte) {
        parent.addLong(name, ((Byte) value).longValue());
    } else if (value instanceof Long) {
        parent.addLong(name, ((Long) value));
    } else if (value instanceof Number) {
        parent.addDouble(name, ((Number) value).doubleValue());
    } else if (value instanceof Boolean) {
        parent.addBoolean(name, (Boolean) value);
    } else if (value instanceof LocalDateTime) {
        parent.addLocalDateTime(name, (LocalDateTime) value);
    } else if (value instanceof LocalDate) {
        parent.addLocalDate(name, (LocalDate) value);
    } else if (value instanceof LocalTime) {
        parent.addLocalTime(name, (LocalTime) value);
    } else if (value instanceof Date) {
        parent.addInstant(name, ((Date) value).toInstant());
    } else if (value instanceof Reference) {
        parent.addReference(name, (Reference) value);
    } else if (value instanceof BinaryReference) {
        parent.addBinaryReference(name, (BinaryReference) value);
    } else if (value instanceof Link) {
        parent.addLink(name, (Link) value);
    } else if (value instanceof BinaryAttachment) {
        final BinaryAttachment binaryAttachment = (BinaryAttachment) value;
        parent.addBinaryReference(name, binaryAttachment.getReference());
        if (includeBinaryAttachments) {
            this.binaryAttachmentsBuilder.add(new BinaryAttachment(binaryAttachment.getReference(), binaryAttachment.getByteSource()));
        }
    } else {
        parent.addString(name, value.toString());
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) BinaryReference(com.enonic.xp.util.BinaryReference) Reference(com.enonic.xp.util.Reference) Instant(java.time.Instant) BinaryReference(com.enonic.xp.util.BinaryReference) LocalDate(java.time.LocalDate) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Date(java.util.Date) LocalDate(java.time.LocalDate) GeoPoint(com.enonic.xp.util.GeoPoint) Link(com.enonic.xp.util.Link)

Example 2 with Link

use of com.enonic.xp.util.Link in project xp by enonic.

the class PropertyTreeTest method setLink.

@Test
public void setLink() {
    PropertyTree tree = new PropertyTree();
    Link link1 = Link.from("enonic.com");
    tree.setLink("enonic", link1);
    assertEquals(1, tree.getTotalSize());
    assertEquals(link1, tree.getLink("enonic"));
    Link link2 = Link.from("wiki.enonic.com");
    tree.setLink(PropertyPath.from("wiki"), link2);
    assertEquals(2, tree.getTotalSize());
    assertEquals(link2, tree.getLink(PropertyPath.from("wiki")));
    Link link3 = Link.from("youtrack.enonic.net");
    tree.setLink("youtrack", 0, link3);
    assertEquals(3, tree.getTotalSize());
    assertEquals(link3, tree.getLink("youtrack", 0));
    assertEquals("youtrack.enonic.net", tree.getLinks("youtrack").iterator().next().toString());
}
Also used : Link(com.enonic.xp.util.Link) Test(org.junit.jupiter.api.Test) AbstractEqualsTest(com.enonic.xp.support.AbstractEqualsTest)

Aggregations

Link (com.enonic.xp.util.Link)2 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)1 AbstractEqualsTest (com.enonic.xp.support.AbstractEqualsTest)1 BinaryReference (com.enonic.xp.util.BinaryReference)1 GeoPoint (com.enonic.xp.util.GeoPoint)1 Reference (com.enonic.xp.util.Reference)1 Instant (java.time.Instant)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 Date (java.util.Date)1 Test (org.junit.jupiter.api.Test)1