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();
}
}
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;
}
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);
}
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;
}
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;
}
Aggregations