Search in sources :

Example 16 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class StringAdapterTest method testToLocalizedString.

/**
 * Tests {@link StringAdapter#toString(CharSequence)} for an {@link org.opengis.util.InternationalString}
 * having localizations in different languages.
 */
@Test
@DependsOnMethod("testToUnlocalizedString")
public void testToLocalizedString() {
    final DefaultInternationalString i18n = new DefaultInternationalString();
    i18n.add(Locale.ENGLISH, "A word");
    i18n.add(Locale.FRENCH, "Un mot");
    i18n.add(Locale.JAPANESE, "言葉");
    final Context context = new Context(0, Locale.ENGLISH, null, null, null, null, null, null, null);
    try {
        Context.push(Locale.JAPANESE);
        assertEquals("言葉", StringAdapter.toString(i18n));
        Context.push(Locale.FRENCH);
        assertEquals("Un mot", StringAdapter.toString(i18n));
        Context.push(Locale.ENGLISH);
        assertEquals("A word", StringAdapter.toString(i18n));
        Context.pull();
        assertEquals("Un mot", StringAdapter.toString(i18n));
        Context.pull();
        assertEquals("言葉", StringAdapter.toString(i18n));
        Context.pull();
        assertEquals("A word", StringAdapter.toString(i18n));
    } finally {
        context.finish();
    }
}
Also used : Context(org.apache.sis.internal.jaxb.Context) DefaultInternationalString(org.apache.sis.util.iso.DefaultInternationalString) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 17 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class MetadataUtilities method getObjectID.

/**
 * Returns the {@code gco:id} or {@code gml:id} value to use for the given object.
 * The returned identifier will be unique in the current XML document.
 *
 * @param  object  the object for which to get the unique identifier.
 * @return the unique XML identifier, or {@code null} if none.
 *
 * @since 0.7
 */
public static String getObjectID(final IdentifiedObject object) {
    final Context context = Context.current();
    String id = Context.getObjectID(context, object);
    if (id == null) {
        id = object.getIdentifierMap().getSpecialized(IdentifierSpace.ID);
        if (id != null) {
            final StringBuilder buffer = new StringBuilder();
            if (!Utilities.appendUnicodeIdentifier(buffer, (char) 0, id, ":-", false)) {
                return null;
            }
            id = buffer.toString();
            if (!Context.setObjectForID(context, object, id)) {
                final int s = buffer.append('-').length();
                int n = 0;
                do {
                    // Arbitrary limit.
                    if (++n == 100)
                        return null;
                    id = buffer.append(n).toString();
                    buffer.setLength(s);
                } while (!Context.setObjectForID(context, object, id));
            }
        }
    }
    return id;
}
Also used : Context(org.apache.sis.internal.jaxb.Context)

Example 18 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class PropertyType method setUUIDREF.

/**
 * Sets the {@code uuidref} attribute value.
 *
 * @param  uuid  the new attribute value.
 * @throws IllegalArgumentException if the given UUID can not be parsed.
 * @category gco:ObjectReference
 */
public final void setUUIDREF(final String uuid) throws IllegalArgumentException {
    final Context context = Context.current();
    reference(true).uuid = Context.converter(context).toUUID(context, uuid);
}
Also used : Context(org.apache.sis.internal.jaxb.Context)

Example 19 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class URIAdapter method marshal.

/**
 * Converts a {@link URI} to the object to be marshalled in a XML file or stream.
 * JAXB calls automatically this method at marshalling time.
 *
 * @param  value  the URI value, or {@code null}.
 * @return the wrapper for the given URI, or {@code null}.
 */
@Override
public GO_CharacterString marshal(final URI value) {
    if (value != null) {
        final Context context = Context.current();
        final GO_CharacterString wrapper = CharSequenceAdapter.wrap(context, value, value.toString());
        if (wrapper != null && wrapper.type == 0) {
            if (!Context.isFlagSet(context, Context.SUBSTITUTE_FILENAME)) {
                wrapper.type = GO_CharacterString.FILENAME;
            }
            return wrapper;
        }
    }
    return null;
}
Also used : Context(org.apache.sis.internal.jaxb.Context)

Example 20 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class MimeFileTypeAdapter method marshal.

/**
 * Converts a MIME type to the object to be marshalled in a XML file or stream.
 * JAXB calls automatically this method at marshalling time.
 *
 * @param  value  the MIME type, or {@code null}.
 * @return the wrapper for the given MIME type, or {@code null}.
 */
@Override
public GO_CharacterString marshal(final String value) {
    final Context context = Context.current();
    final GO_CharacterString wrapper = CharSequenceAdapter.wrap(context, value, value);
    if (wrapper != null && wrapper.type == 0) {
        if (!Context.isFlagSet(context, Context.SUBSTITUTE_MIMETYPE)) {
            wrapper.type = GO_CharacterString.MIME_TYPE;
        }
        return wrapper;
    }
    return null;
}
Also used : Context(org.apache.sis.internal.jaxb.Context) GO_CharacterString(org.apache.sis.internal.jaxb.gco.GO_CharacterString)

Aggregations

Context (org.apache.sis.internal.jaxb.Context)32 JAXBException (javax.xml.bind.JAXBException)7 XMLStreamException (javax.xml.stream.XMLStreamException)6 Locale (java.util.Locale)2 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 DefaultInternationalString (org.apache.sis.util.iso.DefaultInternationalString)2 Test (org.junit.Test)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 XmlAdapter (javax.xml.bind.annotation.adapters.XmlAdapter)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 CodeListUID (org.apache.sis.internal.jaxb.cat.CodeListUID)1 GO_CharacterString (org.apache.sis.internal.jaxb.gco.GO_CharacterString)1 Anchor (org.apache.sis.internal.jaxb.gcx.Anchor)1