Example usage for java.util Locale forLanguageTag

List of usage examples for java.util Locale forLanguageTag

Introduction

In this page you can find the example usage for java.util Locale forLanguageTag.

Prototype

public static Locale forLanguageTag(String languageTag) 

Source Link

Document

Returns a locale for the specified IETF BCP 47 language tag string.

Usage

From source file:org.alfresco.serializers.types.DefaultTypeConverter.java

@SuppressWarnings("rawtypes")
private DefaultTypeConverter() {
    ///*from www. j  a va 2 s . c om*/
    // From string
    //
    addConverter(String.class, Class.class, new TypeConverter.Converter<String, Class>() {
        public Class convert(String source) {
            try {
                return Class.forName(source);
            } catch (ClassNotFoundException e) {
                throw new TypeConversionException("Failed to convert string to class: " + source, e);
            }
        }
    });
    addConverter(String.class, Boolean.class, new TypeConverter.Converter<String, Boolean>() {
        public Boolean convert(String source) {
            return Boolean.valueOf(source);
        }
    });
    addConverter(String.class, Character.class, new TypeConverter.Converter<String, Character>() {
        public Character convert(String source) {
            if ((source == null) || (source.length() == 0)) {
                return null;
            }
            return Character.valueOf(source.charAt(0));
        }
    });
    addConverter(String.class, Number.class, new TypeConverter.Converter<String, Number>() {
        public Number convert(String source) {
            try {
                return DecimalFormat.getNumberInstance().parse(source);
            } catch (ParseException e) {
                throw new TypeConversionException("Failed to parse number " + source, e);
            }
        }
    });
    addConverter(String.class, Byte.class, new TypeConverter.Converter<String, Byte>() {
        public Byte convert(String source) {
            return Byte.valueOf(source);
        }
    });
    addConverter(String.class, Short.class, new TypeConverter.Converter<String, Short>() {
        public Short convert(String source) {
            return Short.valueOf(source);
        }
    });
    addConverter(String.class, Integer.class, new TypeConverter.Converter<String, Integer>() {
        public Integer convert(String source) {
            return Integer.valueOf(source);
        }
    });
    addConverter(String.class, Long.class, new TypeConverter.Converter<String, Long>() {
        public Long convert(String source) {
            return Long.valueOf(source);
        }
    });
    addConverter(String.class, Float.class, new TypeConverter.Converter<String, Float>() {
        public Float convert(String source) {
            return Float.valueOf(source);
        }
    });
    addConverter(String.class, Double.class, new TypeConverter.Converter<String, Double>() {
        public Double convert(String source) {
            return Double.valueOf(source);
        }
    });
    addConverter(String.class, BigInteger.class, new TypeConverter.Converter<String, BigInteger>() {
        public BigInteger convert(String source) {
            return new BigInteger(source);
        }
    });
    addConverter(String.class, BigDecimal.class, new TypeConverter.Converter<String, BigDecimal>() {
        public BigDecimal convert(String source) {
            return new BigDecimal(source);
        }
    });
    addConverter(BasicDBObject.class, BigDecimal.class,
            new TypeConverter.Converter<BasicDBObject, BigDecimal>() {
                public BigDecimal convert(BasicDBObject source) {
                    String type = (String) source.get("t");
                    if (type.equals("FIXED_POINT")) {
                        String number = (String) source.get("n");
                        Integer precision = (Integer) source.get("p");
                        MathContext ctx = new MathContext(precision);
                        return new BigDecimal(number, ctx);
                    } else {
                        throw new IllegalArgumentException("Invalid source object for conversion " + source
                                + ", expected a Fixed Decimal object");
                    }
                }
            });
    addConverter(String.class, Date.class, new TypeConverter.Converter<String, Date>() {
        public Date convert(String source) {
            try {
                Date date = ISO8601DateFormat.parse(source);
                return date;
            } catch (PlatformRuntimeException e) {
                throw new TypeConversionException("Failed to convert date " + source + " to string", e);
            } catch (AlfrescoRuntimeException e) {
                throw new TypeConversionException("Failed to convert date " + source + " to string", e);
            }
        }
    });
    addConverter(String.class, Duration.class, new TypeConverter.Converter<String, Duration>() {
        public Duration convert(String source) {
            return new Duration(source);
        }
    });
    addConverter(String.class, QName.class, new TypeConverter.Converter<String, QName>() {
        public QName convert(String source) {
            return QName.createQName(source);
        }
    });
    addConverter(BasicDBObject.class, QName.class, new TypeConverter.Converter<BasicDBObject, QName>() {
        public QName convert(BasicDBObject source) {
            String type = (String) source.get("t");
            if (type.equals("QNAME")) {
                String qname = (String) source.get("v");
                return QName.createQName(qname);
            } else {
                throw new IllegalArgumentException();
            }
        }
    });
    addConverter(String.class, ContentData.class, new TypeConverter.Converter<String, ContentData>() {
        public ContentData convert(String source) {
            return ContentData.createContentProperty(source);
        }
    });
    addConverter(String.class, NodeRef.class, new TypeConverter.Converter<String, NodeRef>() {
        public NodeRef convert(String source) {
            return new NodeRef(source);
        }
    });
    addConverter(BasicDBObject.class, NodeRef.class, new TypeConverter.Converter<BasicDBObject, NodeRef>() {
        public NodeRef convert(BasicDBObject source) {
            String type = (String) source.get("t");
            if (!type.equals("NODEREF")) {
                throw new IllegalArgumentException(
                        "Invalid source object for conversion " + source + ", expected a NodeRef object");
            }
            String protocol = (String) source.get("p");
            String storeId = (String) source.get("s");
            String id = (String) source.get("id");
            NodeRef nodeRef = new NodeRef(new StoreRef(protocol, storeId), id);
            return nodeRef;
        }
    });
    addConverter(String.class, StoreRef.class, new TypeConverter.Converter<String, StoreRef>() {
        public StoreRef convert(String source) {
            return new StoreRef(source);
        }
    });
    addConverter(BasicDBObject.class, StoreRef.class, new TypeConverter.Converter<BasicDBObject, StoreRef>() {
        public StoreRef convert(BasicDBObject source) {
            String type = (String) source.get("t");
            if (!type.equals("STOREREF")) {
                throw new IllegalArgumentException(
                        "Invalid source object for conversion " + source + ", expected a StoreRef object");
            }
            String protocol = (String) source.get("p");
            String storeId = (String) source.get("s");
            return new StoreRef(protocol, storeId);
        }
    });
    addConverter(String.class, ChildAssociationRef.class,
            new TypeConverter.Converter<String, ChildAssociationRef>() {
                public ChildAssociationRef convert(String source) {
                    return new ChildAssociationRef(source);
                }
            });
    addConverter(String.class, AssociationRef.class, new TypeConverter.Converter<String, AssociationRef>() {
        public AssociationRef convert(String source) {
            return new AssociationRef(source);
        }
    });
    addConverter(String.class, InputStream.class, new TypeConverter.Converter<String, InputStream>() {
        public InputStream convert(String source) {
            try {
                return new ByteArrayInputStream(source.getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e) {
                throw new TypeConversionException("Encoding not supported", e);
            }
        }
    });
    addConverter(String.class, MLText.class, new TypeConverter.Converter<String, MLText>() {
        public MLText convert(String source) {
            return new MLText(source);
        }
    });
    addConverter(BasicDBObject.class, MLText.class, new TypeConverter.Converter<BasicDBObject, MLText>() {
        public MLText convert(BasicDBObject source) {
            String type = (String) source.get("t");
            if (!type.equals("MLTEXT")) {
                throw new IllegalArgumentException(
                        "Invalid source object for conversion " + source + ", expected a NodeRef object");
            }

            MLText mlText = new MLText();
            for (String languageTag : source.keySet()) {
                String text = (String) source.get(languageTag);
                Locale locale = Locale.forLanguageTag(languageTag);
                mlText.put(locale, text);
            }

            return mlText;
        }
    });
    //        addConverter(BasicDBObject.class, ContentDataWithId.class, new TypeConverter.Converter<BasicDBObject, ContentDataWithId>()
    //        {
    //            public ContentDataWithId convert(BasicDBObject source)
    //            {
    //                String type = (String)source.get("t");
    //                if(!type.equals("CONTENT_DATA_ID"))
    //                {
    //                    throw new IllegalArgumentException("Invalid source object for conversion "
    //                            + source 
    //                            + ", expected a ContentDataWithId object");
    //                }
    //                String contentUrl = (String)source.get("u");
    //                String mimeType = (String)source.get("m");
    //                Long size = (Long)source.get("s");
    //                String encoding = (String)source.get("e");
    //                String languageTag = (String)source.get("l");
    //                Long id = (Long)source.get("id");
    //                Locale locale = Locale.forLanguageTag(languageTag);
    //
    //                ContentData contentData = new ContentData(contentUrl, mimeType, size, encoding, locale);
    //                ContentDataWithId contentDataWithId = new ContentDataWithId(contentData, id);
    //                return contentDataWithId;
    //            }
    //        });
    addConverter(BasicDBObject.class, ContentData.class,
            new TypeConverter.Converter<BasicDBObject, ContentData>() {
                public ContentData convert(BasicDBObject source) {
                    ContentData contentData = null;

                    String type = (String) source.get("t");
                    if (type.equals("CONTENT")) {
                        String contentUrl = (String) source.get("u");
                        String mimeType = (String) source.get("m");
                        Long size = (Long) source.get("s");
                        String encoding = (String) source.get("e");
                        String languageTag = (String) source.get("l");
                        Locale locale = Locale.forLanguageTag(languageTag);
                        contentData = new ContentData(contentUrl, mimeType, size, encoding, locale);
                    } else if (type.equals("CONTENT_DATA_ID")) {
                        String contentUrl = (String) source.get("u");
                        String mimeType = (String) source.get("m");
                        Long size = (Long) source.get("s");
                        String encoding = (String) source.get("e");
                        String languageTag = (String) source.get("l");
                        Locale locale = Locale.forLanguageTag(languageTag);
                        contentData = new ContentData(contentUrl, mimeType, size, encoding, locale);
                    } else {
                        throw new IllegalArgumentException("Invalid source object for conversion " + source
                                + ", expected a ContentData object");
                    }

                    return contentData;
                }
            });
    addConverter(BasicDBObject.class, String.class, new TypeConverter.Converter<BasicDBObject, String>() {
        public String convert(BasicDBObject source) {
            // TODO distinguish between different BasicDBObject representations e.g. for MLText, ...

            Set<String> languageTags = source.keySet();
            if (languageTags.size() == 0) {
                throw new IllegalArgumentException("Persisted MLText is invalid " + source);
            } else if (languageTags.size() > 1) {
                // TODO
                logger.warn("Persisted MLText has more than 1 locale " + source);
            }

            String languageTag = languageTags.iterator().next();
            String text = source.getString(languageTag);
            return text;
        }
    });
    addConverter(String.class, Locale.class, new TypeConverter.Converter<String, Locale>() {
        public Locale convert(String source) {
            return I18NUtil.parseLocale(source);
        }
    });
    addConverter(String.class, Period.class, new TypeConverter.Converter<String, Period>() {
        public Period convert(String source) {
            return new Period(source);
        }
    });
    addConverter(String.class, VersionNumber.class, new TypeConverter.Converter<String, VersionNumber>() {
        public VersionNumber convert(String source) {
            return new VersionNumber(source);
        }
    });

    //
    // From Locale
    //
    addConverter(Locale.class, String.class, new TypeConverter.Converter<Locale, String>() {
        public String convert(Locale source) {
            String localeStr = source.toString();
            if (localeStr.length() < 6) {
                localeStr += "_";
            }
            return localeStr;
        }
    });

    //
    // From VersionNumber
    //
    addConverter(VersionNumber.class, String.class, new TypeConverter.Converter<VersionNumber, String>() {
        public String convert(VersionNumber source) {
            return source.toString();
        }
    });

    //
    // From MLText
    //
    addConverter(MLText.class, String.class, new TypeConverter.Converter<MLText, String>() {
        public String convert(MLText source) {
            return source.getDefaultValue();
        }
    });

    addConverter(MLText.class, BasicDBObject.class, new TypeConverter.Converter<MLText, BasicDBObject>() {
        public BasicDBObject convert(MLText source) {
            BasicDBObject dbObject = new BasicDBObject("t", "MLTEXT");
            for (Map.Entry<Locale, String> entry : source.entrySet()) {
                dbObject.put(entry.getKey().toLanguageTag(), entry.getValue());
            }
            return dbObject;
        }
    });

    //        addConverter(ContentDataWithId.class, BasicDBObject.class, new TypeConverter.Converter<ContentDataWithId, BasicDBObject>()
    //        {
    //            public BasicDBObject convert(ContentDataWithId source)
    //            {
    //                BasicDBObject dbObject = new BasicDBObject("t", "CONTENT_DATA_ID");
    //
    //                String contentUrl = source.getContentUrl();
    //                Long id = source.getId();
    //                String languageTag = source.getLocale().toLanguageTag();
    //                String encoding = source.getEncoding();
    //                long size = source.getSize();
    //                String mimeType = source.getMimetype();
    //
    //                dbObject.put("u", contentUrl);
    //                dbObject.put("m", mimeType);
    //                dbObject.put("s", size);
    //                dbObject.put("e", encoding);
    //                dbObject.put("l", languageTag);
    //                dbObject.put("id", id);
    //                return dbObject;
    //            }
    //        });

    addConverter(ContentData.class, BasicDBObject.class,
            new TypeConverter.Converter<ContentData, BasicDBObject>() {
                public BasicDBObject convert(ContentData source) {
                    BasicDBObject dbObject = new BasicDBObject("t", "CONTENT");

                    String contentUrl = source.getContentUrl();
                    String languageTag = source.getLocale().toLanguageTag();
                    String encoding = source.getEncoding();
                    long size = source.getSize();
                    String mimeType = source.getMimetype();

                    dbObject.put("u", contentUrl);
                    dbObject.put("m", mimeType);
                    dbObject.put("s", size);
                    dbObject.put("e", encoding);
                    dbObject.put("l", languageTag);
                    return dbObject;
                }
            });

    //
    // From enum
    //
    addConverter(Enum.class, String.class, new TypeConverter.Converter<Enum, String>() {
        public String convert(Enum source) {
            return source.toString();
        }
    });

    // From Period
    addConverter(Period.class, String.class, new TypeConverter.Converter<Period, String>() {
        public String convert(Period source) {
            return source.toString();
        }
    });

    // From Class
    addConverter(Class.class, String.class, new TypeConverter.Converter<Class, String>() {
        public String convert(Class source) {
            return source.getName();
        }
    });

    //
    // Number to Subtypes and Date
    //
    addConverter(Number.class, Boolean.class, new TypeConverter.Converter<Number, Boolean>() {
        public Boolean convert(Number source) {
            return new Boolean(source.longValue() > 0);
        }
    });
    addConverter(Number.class, Byte.class, new TypeConverter.Converter<Number, Byte>() {
        public Byte convert(Number source) {
            return Byte.valueOf(source.byteValue());
        }
    });
    addConverter(Number.class, Short.class, new TypeConverter.Converter<Number, Short>() {
        public Short convert(Number source) {
            return Short.valueOf(source.shortValue());
        }
    });
    addConverter(Number.class, Integer.class, new TypeConverter.Converter<Number, Integer>() {
        public Integer convert(Number source) {
            return Integer.valueOf(source.intValue());
        }
    });
    addConverter(Number.class, Long.class, new TypeConverter.Converter<Number, Long>() {
        public Long convert(Number source) {
            return Long.valueOf(source.longValue());
        }
    });
    addConverter(Number.class, Float.class, new TypeConverter.Converter<Number, Float>() {
        public Float convert(Number source) {
            return Float.valueOf(source.floatValue());
        }
    });
    addConverter(Number.class, Double.class, new TypeConverter.Converter<Number, Double>() {
        public Double convert(Number source) {
            return Double.valueOf(source.doubleValue());
        }
    });
    addConverter(Number.class, Date.class, new TypeConverter.Converter<Number, Date>() {
        public Date convert(Number source) {
            return new Date(source.longValue());
        }
    });
    addConverter(Number.class, String.class, new TypeConverter.Converter<Number, String>() {
        public String convert(Number source) {
            return source.toString();
        }
    });
    addConverter(Number.class, BigInteger.class, new TypeConverter.Converter<Number, BigInteger>() {
        public BigInteger convert(Number source) {
            if (source instanceof BigDecimal) {
                return ((BigDecimal) source).toBigInteger();
            } else {
                return BigInteger.valueOf(source.longValue());
            }
        }
    });
    addConverter(Number.class, BigDecimal.class, new TypeConverter.Converter<Number, BigDecimal>() {
        public BigDecimal convert(Number source) {
            if (source instanceof BigInteger) {
                return new BigDecimal((BigInteger) source);
            } else if (source instanceof Double) {
                return BigDecimal.valueOf((Double) source);
            } else if (source instanceof Float) {
                Float val = (Float) source;
                if (val.isInfinite()) {
                    // What else can we do here?  this is 3.4 E 38 so is fairly big
                    return new BigDecimal(Float.MAX_VALUE);
                }
                return BigDecimal.valueOf((Float) source);
            } else {
                return BigDecimal.valueOf(source.longValue());
            }
        }
    });
    addDynamicTwoStageConverter(Number.class, String.class, InputStream.class);

    //
    // Date, Timestamp ->
    //
    addConverter(Timestamp.class, Date.class, new TypeConverter.Converter<Timestamp, Date>() {
        public Date convert(Timestamp source) {
            return new Date(source.getTime());
        }
    });
    addConverter(Date.class, Number.class, new TypeConverter.Converter<Date, Number>() {
        public Number convert(Date source) {
            return Long.valueOf(source.getTime());
        }
    });
    addConverter(Date.class, String.class, new TypeConverter.Converter<Date, String>() {
        public String convert(Date source) {
            try {
                return ISO8601DateFormat.format(source);
            } catch (PlatformRuntimeException e) {
                throw new TypeConversionException("Failed to convert date " + source + " to string", e);
            }
        }
    });
    addConverter(Date.class, Calendar.class, new TypeConverter.Converter<Date, Calendar>() {
        public Calendar convert(Date source) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(source);
            return calendar;
        }
    });

    addConverter(Date.class, GregorianCalendar.class, new TypeConverter.Converter<Date, GregorianCalendar>() {
        public GregorianCalendar convert(Date source) {
            GregorianCalendar calendar = new GregorianCalendar();
            calendar.setTime(source);
            return calendar;
        }
    });
    addDynamicTwoStageConverter(Date.class, String.class, InputStream.class);

    //
    // Boolean ->
    //
    final Long LONG_FALSE = new Long(0L);
    final Long LONG_TRUE = new Long(1L);
    addConverter(Boolean.class, Long.class, new TypeConverter.Converter<Boolean, Long>() {
        public Long convert(Boolean source) {
            return source.booleanValue() ? LONG_TRUE : LONG_FALSE;
        }
    });
    addConverter(Boolean.class, String.class, new TypeConverter.Converter<Boolean, String>() {
        public String convert(Boolean source) {
            return source.toString();
        }
    });
    addDynamicTwoStageConverter(Boolean.class, String.class, InputStream.class);

    //
    // Character ->
    //
    addConverter(Character.class, String.class, new TypeConverter.Converter<Character, String>() {
        public String convert(Character source) {
            return source.toString();
        }
    });
    addDynamicTwoStageConverter(Character.class, String.class, InputStream.class);

    //
    // Duration ->
    //
    addConverter(Duration.class, String.class, new TypeConverter.Converter<Duration, String>() {
        public String convert(Duration source) {
            return source.toString();
        }

    });
    addDynamicTwoStageConverter(Duration.class, String.class, InputStream.class);

    //
    // Byte
    //
    addConverter(Byte.class, String.class, new TypeConverter.Converter<Byte, String>() {
        public String convert(Byte source) {
            return source.toString();
        }
    });
    addDynamicTwoStageConverter(Byte.class, String.class, InputStream.class);

    //
    // Short
    //
    addConverter(Short.class, String.class, new TypeConverter.Converter<Short, String>() {
        public String convert(Short source) {
            return source.toString();
        }
    });
    addDynamicTwoStageConverter(Short.class, String.class, InputStream.class);

    //
    // Integer
    //
    addConverter(Integer.class, String.class, new TypeConverter.Converter<Integer, String>() {
        public String convert(Integer source) {
            return source.toString();
        }
    });
    addDynamicTwoStageConverter(Integer.class, String.class, InputStream.class);

    //
    // Long
    //
    addConverter(Long.class, String.class, new TypeConverter.Converter<Long, String>() {
        public String convert(Long source) {
            return source.toString();
        }
    });
    addDynamicTwoStageConverter(Long.class, String.class, InputStream.class);

    //
    // Float
    //
    addConverter(Float.class, String.class, new TypeConverter.Converter<Float, String>() {
        public String convert(Float source) {
            return source.toString();
        }
    });
    addDynamicTwoStageConverter(Float.class, String.class, InputStream.class);

    //
    // Double
    //
    addConverter(Double.class, String.class, new TypeConverter.Converter<Double, String>() {
        public String convert(Double source) {
            return source.toString();
        }
    });
    addDynamicTwoStageConverter(Double.class, String.class, InputStream.class);

    //
    // BigInteger
    //
    addConverter(BigInteger.class, String.class, new TypeConverter.Converter<BigInteger, String>() {
        public String convert(BigInteger source) {
            return source.toString();
        }
    });
    addDynamicTwoStageConverter(BigInteger.class, String.class, InputStream.class);

    //
    // Calendar
    //
    addConverter(Calendar.class, Date.class, new TypeConverter.Converter<Calendar, Date>() {
        public Date convert(Calendar source) {
            return source.getTime();
        }
    });
    addConverter(Calendar.class, String.class, new TypeConverter.Converter<Calendar, String>() {
        public String convert(Calendar source) {
            try {
                return ISO8601DateFormat.format(source.getTime());
            } catch (PlatformRuntimeException e) {
                throw new TypeConversionException("Failed to convert date " + source + " to string", e);
            }
        }
    });

    //
    // BigDecimal
    //
    addConverter(BigDecimal.class, BasicDBObject.class,
            new TypeConverter.Converter<BigDecimal, BasicDBObject>() {
                public BasicDBObject convert(BigDecimal source) {
                    String number = source.toPlainString();
                    int precision = source.precision();
                    BasicDBObject dbObject = new BasicDBObject();
                    dbObject.put("t", "FIXED_POINT");
                    dbObject.put("n", number);
                    dbObject.put("p", precision);
                    return dbObject;
                }
            });
    addConverter(BigDecimal.class, String.class, new TypeConverter.Converter<BigDecimal, String>() {
        public String convert(BigDecimal source) {
            return source.toString();
        }
    });
    addDynamicTwoStageConverter(BigDecimal.class, String.class, InputStream.class);

    //
    // QName
    //
    addConverter(QName.class, String.class, new TypeConverter.Converter<QName, String>() {
        public String convert(QName source) {
            return source.toString();
        }
    });
    addDynamicTwoStageConverter(QName.class, String.class, InputStream.class);

    //
    // EntityRef (NodeRef, ChildAssociationRef, NodeAssociationRef)
    //
    addConverter(EntityRef.class, String.class, new TypeConverter.Converter<EntityRef, String>() {
        public String convert(EntityRef source) {
            return source.toString();
        }
    });
    addConverter(EntityRef.class, BasicDBObject.class, new TypeConverter.Converter<EntityRef, BasicDBObject>() {
        public BasicDBObject convert(EntityRef source) {
            BasicDBObject ret = null;

            if (source instanceof NodeRef) {
                NodeRef nodeRef = (NodeRef) source;

                BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("t", "NODEREF");
                builder.add("p", nodeRef.getStoreRef().getProtocol());
                builder.add("s", nodeRef.getStoreRef().getIdentifier());
                builder.add("id", nodeRef.getId());
                ret = (BasicDBObject) builder.get();
            } else if (source instanceof StoreRef) {
                StoreRef storeRef = (StoreRef) source;

                BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("t", "STOREREF");
                builder.add("p", storeRef.getProtocol());
                builder.add("s", storeRef.getIdentifier());
                ret = (BasicDBObject) builder.get();
            } else {
                throw new IllegalArgumentException();
            }

            return ret;
        }
    });
    addDynamicTwoStageConverter(EntityRef.class, String.class, InputStream.class);

    //
    // ContentData
    //
    addConverter(ContentData.class, String.class, new TypeConverter.Converter<ContentData, String>() {
        public String convert(ContentData source) {
            return source.getInfoUrl();
        }
    });
    addDynamicTwoStageConverter(ContentData.class, String.class, InputStream.class);

    //
    // Path
    //
    addConverter(Path.class, String.class, new TypeConverter.Converter<Path, String>() {
        public String convert(Path source) {
            return source.toString();
        }
    });
    addDynamicTwoStageConverter(Path.class, String.class, InputStream.class);

    //
    // Content Reader
    //
    addConverter(ContentReader.class, InputStream.class,
            new TypeConverter.Converter<ContentReader, InputStream>() {
                public InputStream convert(ContentReader source) {
                    return source.getContentInputStream();
                }
            });
    addConverter(ContentReader.class, String.class, new TypeConverter.Converter<ContentReader, String>() {
        public String convert(ContentReader source) {
            // Getting the string from the ContentReader binary is meaningless
            return source.toString();
        }
    });

    //
    // Content Writer
    //
    addConverter(ContentWriter.class, String.class, new TypeConverter.Converter<ContentWriter, String>() {
        public String convert(ContentWriter source) {
            return source.toString();
        }
    });

    addConverter(Collection.class, BasicDBList.class, new TypeConverter.Converter<Collection, BasicDBList>() {
        public BasicDBList convert(Collection source) {
            BasicDBList ret = new BasicDBList();
            for (Object o : source) {
                ret.add(o);
            }
            return ret;
        }
    });

    addConverter(BasicDBList.class, Collection.class, new TypeConverter.Converter<BasicDBList, Collection>() {
        @SuppressWarnings("unchecked")
        public Collection convert(BasicDBList source) {
            Collection ret = new LinkedList();
            for (Object o : source) {
                ret.add(o);
            }
            return ret;
        }
    });

    //
    // Input Stream
    //
    addConverter(InputStream.class, String.class, new TypeConverter.Converter<InputStream, String>() {
        public String convert(InputStream source) {
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                byte[] buffer = new byte[8192];
                int read;
                while ((read = source.read(buffer)) > 0) {
                    out.write(buffer, 0, read);
                }
                byte[] data = out.toByteArray();
                return new String(data, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw new TypeConversionException("Cannot convert input stream to String.", e);
            } catch (IOException e) {
                throw new TypeConversionException("Conversion from stream to string failed", e);
            } finally {
                if (source != null) {
                    try {
                        source.close();
                    } catch (IOException e) {
                        //NOOP
                    }
                }
            }
        }
    });
    addDynamicTwoStageConverter(InputStream.class, String.class, Date.class);

    addDynamicTwoStageConverter(InputStream.class, String.class, Double.class);

    addDynamicTwoStageConverter(InputStream.class, String.class, Long.class);

    addDynamicTwoStageConverter(InputStream.class, String.class, Boolean.class);

    addDynamicTwoStageConverter(InputStream.class, String.class, QName.class);

    addDynamicTwoStageConverter(InputStream.class, String.class, Path.class);

    addDynamicTwoStageConverter(InputStream.class, String.class, NodeRef.class);

}

From source file:com.kaikoda.cah.TestDeck.java

@Test
public void testDeckTranslate_dictionaryNotFound()
        throws SAXException, IOException, TransformerException, ParserConfigurationException {

    Deck customDeck = new Deck(this.getDocument("/data/test/cards/netherlands.xml"));
    customDeck.setErrorListener(new ProgressReporter());

    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("Dictionary not found.");

    customDeck.translate(Locale.forLanguageTag("en-gb"), new File("non-existant.file"));

}

From source file:it.smartcommunitylab.aac.apimanager.APIProviderManager.java

/**
 * @param reg// w  ww.j  a va 2  s . c  om
 * @param key
 * @throws RegistrationException
 */
private void sendConfirmationMail(APIProvider provider, String key) throws RegistrationException {
    RegistrationBean user = new RegistrationBean(provider.getEmail(), provider.getName(),
            provider.getSurname());
    String lang = StringUtils.hasText(provider.getLang()) ? provider.getLang() : Config.DEFAULT_LANG;
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("user", user);
    vars.put("url", applicationURL + "/internal/confirm?confirmationCode=" + key);
    String subject = messageSource.getMessage("confirmation.subject", null, Locale.forLanguageTag(lang));
    sender.sendEmail(provider.getEmail(), "mail/provider_reg_" + lang, subject, vars);
}

From source file:org.wso2.carbon.uuf.internal.deployment.AppCreator.java

private void addI18nResources(Map<String, Properties> componentI18nResources, I18nResources i18nResources) {
    if ((componentI18nResources == null) || componentI18nResources.isEmpty()) {
        return;/*from  w  w w.j  a  va  2s .c  o m*/
    }
    componentI18nResources.forEach((localString, properties) -> {
        Locale locale = Locale.forLanguageTag(localString.replace("_", "-"));
        if (locale.getLanguage().isEmpty()) {
            throw new UUFException(
                    "Locale is not found for the given language code. Hence language file will not"
                            + " be deployed for" + localString);
        } else {
            i18nResources.addI18nResource(locale, properties);
        }
    });
}

From source file:com.kaikoda.cah.TestDeck.java

@Test
public void testDeckTranslate_nullDictionary()
        throws SAXException, IOException, TransformerException, ParserConfigurationException {

    Deck customDeck = new Deck(this.getDocument("/data/test/cards/netherlands.xml"));
    customDeck.setErrorListener(new ProgressReporter());

    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("Dictionary required.");

    customDeck.translate(Locale.forLanguageTag("en-gb"), null);

}

From source file:alfio.manager.AdminReservationManager.java

private Result<Triple<TicketReservation, List<Ticket>, Event>> performConfirmation(String reservationId,
        Event event, TicketReservation original) {
    try {//from  ww  w. j a va2  s  .c  om
        ticketReservationManager.completeReservation(event.getId(), reservationId, original.getEmail(),
                new CustomerName(original.getFullName(), original.getFirstName(), original.getLastName(),
                        event),
                Locale.forLanguageTag(original.getUserLanguage()), original.getBillingAddress(),
                Optional.empty(), PaymentProxy.ADMIN);
        return loadReservation(reservationId);
    } catch (Exception e) {
        return Result.error(ErrorCode.ReservationError.UPDATE_FAILED);
    }
}

From source file:com.kaikoda.cah.TestDeck.java

@Test
public void testDeckTranslate_sourceLocaleUnknown()
        throws SAXException, IOException, TransformerException, ParserConfigurationException {

    Deck customDeck = new Deck(this.getDocument("/data/test/cards/no_language.xml"));

    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("The language of the card deck isn't specified.");

    customDeck.translate(Locale.forLanguageTag("en-gb"), TestDeck.DICTIONARY_DATA_ENGLISH);

}

From source file:com.kaikoda.cah.TestDeck.java

/**
 * Check that the language and data remain unchanged if the target language
 * is the same as the current language.//from ww  w  . j  a  va  2  s . c om
 * 
 * @throws SAXException
 * @throws IOException
 * @throws TransformerException
 * @throws ParserConfigurationException
 */
@Test
public void testDeckTranslate_targetLanguageIsSourceLanguage()
        throws SAXException, IOException, TransformerException, ParserConfigurationException {

    Document expected = this.getDocument("/data/test/cards/netherlands.xml");
    Deck customDeck = new Deck(expected);
    customDeck.setErrorListener(new ProgressReporter());

    Locale targetLanguage = Locale.forLanguageTag("en-nl");
    assertEquals(targetLanguage, customDeck.getLocale());

    customDeck.translate(targetLanguage, TestDeck.DICTIONARY_DATA_ENGLISH);
    Document result = customDeck.getData();

    assertEquals(targetLanguage, customDeck.getLocale());
    assertXMLEqual(expected, result);
}

From source file:me.cavar.pg2tei.TEIDoc.java

/**
 *
 * @return Document//from w  w w. j  a v a 2 s .co  m
 * @throws ParserConfigurationException
 */
public void genTEIXMLDom() {
    try {
        DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
        this.mydom = docBuilder.newDocument();

        // TEI root element
        Element root = this.mydom.createElement("TEI");
        root.setAttribute("xmlns", "http://www.tei-c.org/ns/1.0");
        this.mydom.appendChild(root);
        this.mydom.insertBefore(this.mydom.createProcessingInstruction("xml-model",
                "href=\"http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/teilite.rng\""
                        + " schematypens=\"http://relaxng.org/ns/structure/1.0\""),
                root);

        // create teiHeader section
        Element teiHeader = this.mydom.createElement("teiHeader");
        root.appendChild(teiHeader);

        // create fileDescription section
        Element fileDesc = this.mydom.createElement("fileDesc");
        teiHeader.appendChild(fileDesc);

        // create titleStmt
        Element titleStmt = this.mydom.createElement("titleStmt");
        // check for multi-line titles
        Element ltmp;
        Element tmp = this.mydom.createElement("title");
        tmp.setAttribute("type", "full");
        int numTitles = this.title.size();
        if (numTitles > 0) {
            String tmpStr = this.title.get(numTitles - 1);
            if (tmpStr.contains("\n")) {
                // make multiple title statements
                String[] subStrs = tmpStr.split("\n");

                // the first one is main
                ltmp = this.mydom.createElement("title");
                ltmp.setAttribute("type", "main");
                ltmp.appendChild(this.mydom.createTextNode(subStrs[0]));
                tmp.appendChild(ltmp);

                // TODO
                // all others are sub should not be... but...
                for (int i = 1; i < subStrs.length; i++) {
                    ltmp = this.mydom.createElement("title");
                    ltmp.setAttribute("type", "sub");
                    ltmp.appendChild(this.mydom.createTextNode(subStrs[i]));
                    tmp.appendChild(ltmp);
                }
                // titleStmt.appendChild(tmp);
            } else { // make single title statement
                ltmp = this.mydom.createElement("title");
                ltmp.setAttribute("type", "main");
                ltmp.appendChild(this.mydom.createTextNode(this.title.get(numTitles - 1)));
                tmp.appendChild(ltmp);
            }
        }
        ltmp = this.mydom.createElement("title");
        ltmp.setAttribute("type", "alt");
        ltmp.appendChild(this.mydom.createTextNode(this.friendlyTitle));
        tmp.appendChild(ltmp);
        titleStmt.appendChild(tmp);

        // add author information
        tmp = this.mydom.createElement("author");
        if (this.creator != null) {
            // split year of from author string
            Pattern nameSplitRE = Pattern
                    .compile("(?<name>[\\w,\\s]+)(?<year>,\\s+\\d\\d\\d\\d\\s?-+\\s?\\d\\d\\d\\d)");
            Matcher matcher = nameSplitRE.matcher(this.creator);
            if (matcher.find(0)) {
                String tmpN = matcher.group("name");
                //String tmpY = matcher.group("year");
                tmp.appendChild(this.mydom.createTextNode(tmpN));
            } else {
                tmp.appendChild(this.mydom.createTextNode(this.creator));
            }
        }
        titleStmt.appendChild(tmp);
        fileDesc.appendChild(titleStmt);

        // publicationStmt in fileDesc
        Element publicationStmt = this.mydom.createElement("publicationStmt");
        tmp = this.mydom.createElement("publisher");
        if (this.publisher != null) {
            tmp.appendChild(this.mydom.createTextNode(this.publisher));
        }
        publicationStmt.appendChild(tmp);
        // date
        tmp = this.mydom.createElement("date");
        if (this.createdW3CDTF != null) {
            tmp.appendChild(this.mydom.createTextNode(this.createdW3CDTF));
        }
        publicationStmt.appendChild(tmp);
        // availability
        tmp = this.mydom.createElement("availability");
        ltmp = this.mydom.createElement("licence");
        for (String right : this.rights) {
            Element ptmp = this.mydom.createElement("p");
            ptmp.appendChild(this.mydom.createTextNode(right));
            ltmp.appendChild(ptmp);
        }
        tmp.appendChild(ltmp);
        publicationStmt.appendChild(tmp);
        // distributor
        tmp = this.mydom.createElement("distributor");
        // tmp.appendChild(doc.createTextNode("Distributed in the TEI XML format by:"));
        Element ptmp;
        ptmp = this.mydom.createElement("name");
        ptmp.setAttribute("xml:id", "DC");
        ptmp.appendChild(this.mydom.createTextNode("Damir Cavar"));
        tmp.appendChild(ptmp);
        ptmp = this.mydom.createElement("name");
        ptmp.setAttribute("xml:id", "LTL");
        ptmp.appendChild(this.mydom.createTextNode("Language Technology Lab"));
        tmp.appendChild(ptmp);
        ptmp = this.mydom.createElement("name");
        ptmp.setAttribute("xml:id", "ILIT");
        ptmp.appendChild(this.mydom.createTextNode("Institute for Language Information and Technology"));
        tmp.appendChild(ptmp);
        ptmp = this.mydom.createElement("name");
        ptmp.setAttribute("xml:id", "EMU");
        ptmp.appendChild(this.mydom.createTextNode("Eastern Michigan University"));
        tmp.appendChild(ptmp);

        ltmp = this.mydom.createElement("address");
        // add address info
        ptmp = this.mydom.createElement("addrLine");
        ptmp.appendChild(this.mydom.createTextNode("2000 E. Huron River Dr., Suite 104"));
        ltmp.appendChild(ptmp);
        ptmp = this.mydom.createElement("addrLine");
        ptmp.appendChild(this.mydom.createTextNode("Ypsilanti, MI 48197"));
        ltmp.appendChild(ptmp);
        ptmp = this.mydom.createElement("addrLine");
        ptmp.appendChild(this.mydom.createTextNode("USA"));
        ltmp.appendChild(ptmp);
        tmp.appendChild(ltmp);
        publicationStmt.appendChild(tmp);
        // idno
        tmp = this.mydom.createElement("idno");
        if (this.id != null) {
            tmp.appendChild(this.mydom.createTextNode(Integer.toString(this.idN)));
        }
        publicationStmt.appendChild(tmp);
        fileDesc.appendChild(publicationStmt);

        // --------------------------------------------
        // sourceDesc in fileDesc
        Element sourceDesc = this.mydom.createElement("sourceDesc");
        // contains a <p> with a description of the source
        tmp = this.mydom.createElement("p");
        tmp.appendChild(this.mydom.createTextNode("This text was automatically "
                + "converted from the corresponding HTML formated text found in the "
                + "Project Gutenberg (http://www.gutenberg.org/) collection."));
        sourceDesc.appendChild(tmp);
        if (this.creator != null) {
            tmp = this.mydom.createElement("p");
            tmp.appendChild(this.mydom.createTextNode("Creator: " + this.creator));
            sourceDesc.appendChild(tmp);
        }
        if (this.description != null) {
            tmp = this.mydom.createElement("p");
            tmp.appendChild(this.mydom.createTextNode(this.description));
            sourceDesc.appendChild(tmp);
        }
        fileDesc.appendChild(sourceDesc);

        // --------------------------------------------
        // encodingDesc in teiHeader
        Element encodingDesc = this.mydom.createElement("encodingDesc");
        // contains a appInfo with a description of the source
        tmp = this.mydom.createElement("appInfo");
        // appInfo contains application
        ltmp = this.mydom.createElement("application");
        ltmp.setAttribute("ident", "gutenberg2tei");
        ltmp.setAttribute("version", "1.0");
        ptmp = this.mydom.createElement("desc");
        ptmp.appendChild(
                this.mydom.createTextNode("Conversion tool using the RDF file catalog and meta-information "
                        + "and conversion of HTML to TEI XML."));
        ltmp.appendChild(ptmp);
        tmp.appendChild(ltmp);
        encodingDesc.appendChild(tmp);
        // contains projectDesc
        tmp = this.mydom.createElement("projectDesc");
        ltmp = this.mydom.createElement("p");
        ltmp.appendChild(this.mydom.createTextNode("The conversion of the Project Gutenberg "
                + "texts to the TEI XML format started as an independent project at ILIT, EMU."));
        tmp.appendChild(ltmp);
        encodingDesc.appendChild(tmp);
        // contains samplingDecl
        tmp = this.mydom.createElement("samplingDecl");
        ltmp = this.mydom.createElement("p");
        ltmp.appendChild(this.mydom.createTextNode(""));
        tmp.appendChild(ltmp);
        encodingDesc.appendChild(tmp);
        // classDecl
        tmp = this.mydom.createElement("classDecl");
        ltmp = this.mydom.createElement("taxonomy");
        ltmp.setAttribute("xml:id", "lcsh");
        ptmp = this.mydom.createElement("bibl");
        ptmp.appendChild(this.mydom.createTextNode("Library of Congress Subject Headings"));
        ltmp.appendChild(ptmp);
        tmp.appendChild(ltmp);
        ltmp = this.mydom.createElement("taxonomy");
        ltmp.setAttribute("xml:id", "lc");
        ptmp = this.mydom.createElement("bibl");
        ptmp.appendChild(this.mydom.createTextNode("Library of Congress Classification"));
        ltmp.appendChild(ptmp);
        tmp.appendChild(ltmp);
        ltmp = this.mydom.createElement("taxonomy");
        ltmp.setAttribute("xml:id", "pg");
        ptmp = this.mydom.createElement("bibl");
        ptmp.appendChild(this.mydom.createTextNode("Project Gutenberg Category"));
        ltmp.appendChild(ptmp);
        tmp.appendChild(ltmp);
        encodingDesc.appendChild(tmp);

        teiHeader.appendChild(encodingDesc);

        // --------------------------------------------
        // profileDesc in teiHeader
        Element profileDesc = this.mydom.createElement("profileDesc");
        // contains creation contains date
        tmp = this.mydom.createElement("creation");
        ltmp = this.mydom.createElement("date");
        ltmp.appendChild(this.mydom.createTextNode(this.createdW3CDTF));
        tmp.appendChild(ltmp);
        // add the author name here too, although not correct...
        //ltmp = doc.createElement("name");
        //ltmp.appendChild(doc.createTextNode(this.creator));
        //tmp.appendChild(ltmp);
        profileDesc.appendChild(tmp);
        // contains langUsage
        if (this.languageCode != null) {
            tmp = this.mydom.createElement("langUsage");
            ltmp = this.mydom.createElement("language");
            ltmp.setAttribute("ident", this.languageCode);
            Locale aLocale = Locale.forLanguageTag(this.languageCode);
            ltmp.appendChild(this.mydom.createTextNode(aLocale.getDisplayLanguage() + "."));
            tmp.appendChild(ltmp);
            profileDesc.appendChild(tmp);
        }
        // textClass
        tmp = this.mydom.createElement("textClass");
        ltmp = this.mydom.createElement("keywords");
        ltmp.setAttribute("scheme", "#lcsh");
        if (this.subjectHeadingsLCC.size() > 0) {
            for (String term : this.subjectHeadingsLCC) {
                ptmp = this.mydom.createElement("term");
                ptmp.appendChild(this.mydom.createTextNode(term));
                ltmp.appendChild(ptmp);
            }
        } else {
            ptmp = this.mydom.createElement("term");
            // ptmp.appendChild(doc.createTextNode(term));
            ltmp.appendChild(ptmp);
        }
        tmp.appendChild(ltmp);
        if (this.classificationLCC != null) {
            ltmp = this.mydom.createElement("classCode");
            ltmp.setAttribute("scheme", "#lc");
            ltmp.appendChild(this.mydom.createTextNode(this.classificationLCC));
            tmp.appendChild(ltmp);
        }
        if (this.projGCategory != null) {
            ltmp = this.mydom.createElement("classCode");
            ltmp.setAttribute("scheme", "#pg");
            ltmp.appendChild(this.mydom.createTextNode(this.projGCategory));
            tmp.appendChild(ltmp);
        }
        profileDesc.appendChild(tmp);
        teiHeader.appendChild(profileDesc);

        // --------------------------------------------
        // revisionDesc in teiHeader
        Element revisionDesc = this.mydom.createElement("revisionDesc");
        // contains a list of change tags
        tmp = this.mydom.createElement("change");
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
        Date t = new Date();
        tmp.setAttribute("when", ft.format(t));
        tmp.setAttribute("who", "#DC");
        tmp.appendChild(this.mydom.createTextNode("Initial conversion from HTML to TEI XML."));
        revisionDesc.appendChild(tmp);
        teiHeader.appendChild(revisionDesc);
        // create text section
        // Element text = this.mydom.createElement("text");
        // !!!
        // skip that and just append the text-Element from the converted HTML-document.
        // !!!
        // root.appendChild(text);
    } catch (ParserConfigurationException e) {
        Logger.getLogger(Fetcher.class.getName()).log(Level.SEVERE, null, e);
    }
}

From source file:org.aksw.simba.bengal.triple2nl.TripleConverter.java

/**
 * Convert a triple into a phrase object
 *
 * @param t//  www.  java 2  s  .c o  m
 *            the triple
 * @param negated
 *            if phrase is negated
 * @param reverse
 *            whether subject and object should be changed during
 *            verbalization
 * @return the phrase
 */
public SPhraseSpec convertToPhrase(Triple t, boolean negated, boolean reverse) {
    logger.debug("Verbalizing triple " + t);
    SPhraseSpec p = nlgFactory.createClause();

    Node subject = t.getSubject();
    Node predicate = t.getPredicate();
    Node object = t.getObject();

    // process predicate
    // start with variables
    if (predicate.isVariable()) {
        // if subject is variable then use variable label, else generate
        // textual representation
        // first get the string representation for the subject
        NLGElement subjectElement = processSubject(subject);
        p.setSubject(subjectElement);

        // predicate is variable, thus simply use variable label
        p.setVerb("be related via " + predicate.toString() + " to");

        // then process the object
        NLGElement objectElement = processObject(object, false);
        p.setObject(objectElement);
    } // more interesting case. Predicate is not a variable
      // then check for noun and verb. If the predicate is a noun or a
      // verb, then
      // use possessive or verbal form, else simply get the boa pattern
    else {
        // check if object is class
        boolean objectIsClass = predicate.matches(RDF.type.asNode());

        // first get the string representation for the subject
        NLGElement subjectElement = processSubject(subject);

        // then process the object
        NPPhraseSpec objectElement = processObject(object, objectIsClass);

        // handle the predicate
        PropertyVerbalization propertyVerbalization = pp.verbalize(predicate.getURI());
        String predicateAsString = propertyVerbalization.getVerbalizationText();

        // if the object is a class we generate 'SUBJECT be a(n) OBJECT'
        if (objectIsClass) {
            p.setSubject(subjectElement);
            p.setVerb("be");
            objectElement.setSpecifier("a");
            p.setObject(objectElement);
        } else {
            // get the lexicalization type of the predicate

            PropertyVerbalizationType type;
            if (predicate.matches(RDFS.label.asNode())) {
                type = PropertyVerbalizationType.NOUN;
            } else {
                type = propertyVerbalization.getVerbalizationType();
            }

            /*-
             * if the predicate is a noun we generate a possessive form, i.e. 'SUBJECT'S PREDICATE be OBJECT'
             */
            if (type == PropertyVerbalizationType.NOUN) {
                // subject is a noun with possessive feature
                // NLGElement subjectWord =
                // nlgFactory.createInflectedWord(realiser.realise(subjectElement).getRealisation(),
                // LexicalCategory.NOUN);
                // subjectWord.setFeature(LexicalFeature.PROPER, true);
                // subjectElement =
                // nlgFactory.createNounPhrase(subjectWord);
                subjectElement.setFeature(Feature.POSSESSIVE, true);
                // build the noun phrase for the predicate
                NPPhraseSpec predicateNounPhrase = nlgFactory
                        .createNounPhrase(PlingStemmer.stem(predicateAsString));
                // set the possessive subject as specifier
                predicateNounPhrase.setFeature(InternalFeature.SPECIFIER, subjectElement);

                // check if object is a string literal with a language tag
                if (considerLiteralLanguage) {
                    if (object.isLiteral() && object.getLiteralLanguage() != null
                            && !object.getLiteralLanguage().isEmpty()) {
                        String languageTag = object.getLiteralLanguage();
                        String language = Locale.forLanguageTag(languageTag).getDisplayLanguage(Locale.ROOT);
                        predicateNounPhrase.setPreModifier(language);
                    }
                }

                p.setSubject(predicateNounPhrase);

                // we use 'be' as the new predicate
                p.setVerb("be");

                // add object
                p.setObject(objectElement);

                // check if we have to use the plural form
                // simple heuristic: OBJECT is variable and predicate is of
                // type owl:FunctionalProperty or rdfs:range is xsd:boolean
                boolean isPlural = determinePluralForm && usePluralForm(t);
                predicateNounPhrase.setPlural(isPlural);
                p.setPlural(isPlural);

                // check if we reverse the triple representation
                if (reverse) {
                    subjectElement.setFeature(Feature.POSSESSIVE, false);
                    p.setSubject(subjectElement);
                    p.setVerbPhrase(nlgFactory.createVerbPhrase("be " + predicateAsString + " of"));
                    p.setObject(objectElement);
                }
            } // if the predicate is a verb
            else if (type == PropertyVerbalizationType.VERB) {
                p.setSubject(subjectElement);
                p.setVerb(pp.getInfinitiveForm(predicateAsString));
                p.setObject(objectElement);
                p.setFeature(Feature.TENSE, propertyVerbalization.getTense());
            } // in other cases, use the BOA pattern
            else {

                List<org.aksw.simba.bengal.triple2nl.nlp.relation.Pattern> l = BoaPatternSelector
                        .getNaturalLanguageRepresentation(predicate.toString(), 1);
                if (l.size() > 0) {
                    String boaPattern = l.get(0).naturalLanguageRepresentation;
                    // range before domain
                    if (boaPattern.startsWith("?R?")) {
                        p.setSubject(subjectElement);
                        p.setObject(objectElement);
                    } else {
                        p.setObject(subjectElement);
                        p.setSubject(objectElement);
                    }
                    p.setVerb(BoaPatternSelector.getNaturalLanguageRepresentation(predicate.toString(), 1)
                            .get(0).naturalLanguageRepresentationWithoutVariables);
                } // last resort, i.e., no BOA pattern found
                else {
                    p.setSubject(subjectElement);
                    p.setVerb("be related via \"" + predicateAsString + "\" to");
                    p.setObject(objectElement);
                }
            }
        }
    }
    // check if the meaning of the triple is it's negation, which holds for
    // boolean properties with FALSE as value
    if (!negated) {
        // check if object is boolean literal
        if (object.isLiteral() && object.getLiteralDatatype() != null
                && object.getLiteralDatatype().equals(XSDDatatype.XSDboolean)) {
            // omit the object
            p.setObject(null);

            negated = !(boolean) object.getLiteralValue();

        }
    }

    // set negation
    if (negated) {
        p.setFeature(Feature.NEGATED, negated);
    }

    // set present time as tense
    // p.setFeature(Feature.TENSE, Tense.PRESENT);
    // System.out.println(realiser.realise(p));
    return p;
}