/** * Replace any text in mlText having the same language (but any variant) as contentLocale * with updatedText keyed by the language of contentLocale. This ensures that the mlText * will have no more than one entry for the particular language. * * @param contentLocale Locale * @param updatedText String * @param mlText MLText */ private void replaceTextForLanguage(Locale contentLocale, String updatedText, MLText mlText) { String language = contentLocale.getLanguage(); // Remove all text entries having the same language as the chosen contentLocale // (e.g. if contentLocale is en_GB, then remove text for en, en_GB, en_US etc. Iterator<Locale> locales = mlText.getLocales().iterator(); while (locales.hasNext()) { Locale locale = locales.next(); if (locale.getLanguage().equals(language)) { locales.remove(); } } // Add the new value for the specific language mlText.addValue(new Locale(language), updatedText); } }
/** * Replace any text in mlText having the same language (but any variant) as contentLocale * with updatedText keyed by the language of contentLocale. This ensures that the mlText * will have no more than one entry for the particular language. * * @param contentLocale Locale * @param updatedText String * @param mlText MLText */ private void replaceTextForLanguage(Locale contentLocale, String updatedText, MLText mlText) { String language = contentLocale.getLanguage(); // Remove all text entries having the same language as the chosen contentLocale // (e.g. if contentLocale is en_GB, then remove text for en, en_GB, en_US etc. Iterator<Locale> locales = mlText.getLocales().iterator(); while (locales.hasNext()) { Locale locale = locales.next(); if (locale.getLanguage().equals(language)) { locales.remove(); } } // Add the new value for the specific language mlText.addValue(new Locale(language), updatedText); } }
private ArrayList<MLText> makeMLTextMVP(int position) { MLText m1 = new MLText(); m1.addValue(Locale.ENGLISH, mlOrderable_en[position]); MLText m2 = new MLText(); m2.addValue(Locale.FRENCH, mlOrderable_fr[position]); ArrayList<MLText> answer = new ArrayList<MLText>(2); answer.add(m1); answer.add(m2); return answer; }
private NodeRef addSortableNull(String id) { Map<QName, Serializable> properties = new HashMap<QName, Serializable>(); MLText ml = new MLText(); ml.addValue(Locale.ENGLISH, "Test null"); properties.put(ContentModel.PROP_DESCRIPTION, ml); properties.put(ContentModel.PROP_TITLE, ml); properties.put(ContentModel.PROP_NAME, "Test null "+id); properties.put(ContentModel.PROP_CREATED, new Date()); NodeRef c0 = nodeService.createNode(f0, ContentModel.ASSOC_CONTAINS, QName.createQName("cm", "Test One", namespaceService), extendedContent, properties).getChildRef(); return c0; }
/** * @return properties */ public Map<QName, Serializable> getOrderProperties() { Map<QName, Serializable> testProperties = new HashMap<QName, Serializable>(); testProperties.put(CREATED_DATE, orderDate); testProperties.put(ORDER_DOUBLE, orderDoubleCount); testProperties.put(ORDER_FLOAT, orderFloatCount); testProperties.put(ORDER_LONG, orderLongCount); testProperties.put(ORDER_INT, orderIntCount); testProperties.put(ORDER_TEXT, new String(new char[] { (char) ('a' + orderTextCount) }) + " cabbage"); MLText mlText = new MLText(); mlText.addValue(Locale.ENGLISH, new String(new char[] { (char) ('a' + orderTextCount) }) + " banana"); mlText.addValue(Locale.FRENCH, new String(new char[] { (char) ('Z' - orderTextCount) }) + " banane"); mlText.addValue(Locale.CHINESE, new String(new char[] { (char) ('香' + orderTextCount) }) + " 香蕉"); testProperties.put(ORDER_ML_TEXT, mlText); orderDate = Duration.subtract(orderDate, new Duration("P1D")); orderDoubleCount += 0.1d; orderFloatCount += 0.82f; orderLongCount += 299999999999999l; orderIntCount += 8576457; orderTextCount++; return testProperties; }
@Test public void testLongMLTextValues() throws Exception { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 4096; i++) { sb.append(" ").append(i); } String longString = sb.toString(); // Set the server default locale Locale.setDefault(Locale.ENGLISH); // Set it as a normal string nodeService.setProperty( rootNodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE, longString); MLText mlTextProperty = new MLText(); mlTextProperty.addValue(Locale.ENGLISH, longString); mlTextProperty.addValue(Locale.FRENCH, longString); mlTextProperty.addValue(Locale.GERMAN, longString); // Set it as MLText nodeService.setProperty( rootNodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE, mlTextProperty); }
@Test @SuppressWarnings("unchecked") public void testMultiValueMLTextProperties() throws Exception { NodeRef nodeRef = nodeService.createNode( rootNodeRef, ASSOC_TYPE_QNAME_TEST_CHILDREN, QName.createQName("pathA"), TYPE_QNAME_TEST_MANY_ML_PROPERTIES).getChildRef(); // Create MLText properties and add to a collection List<MLText> mlTextCollection = new ArrayList<MLText>(2); MLText mlText0 = new MLText(); mlText0.addValue(Locale.ENGLISH, "Hello"); mlText0.addValue(Locale.FRENCH, "Bonjour"); mlTextCollection.add(mlText0); MLText mlText1 = new MLText(); mlText1.addValue(Locale.ENGLISH, "Bye bye"); mlText1.addValue(Locale.FRENCH, "Au revoir"); mlTextCollection.add(mlText1); nodeService.setProperty(nodeRef, PROP_QNAME_MULTI_ML_VALUE, (Serializable) mlTextCollection); Collection<MLText> mlTextCollectionCheck = (Collection<MLText>) nodeService.getProperty(nodeRef, PROP_QNAME_MULTI_ML_VALUE); assertEquals("MLText collection didn't come back correctly.", mlTextCollection, mlTextCollectionCheck); }
public void testMLTextValues() throws Exception { // Set the server default locale Locale.setDefault(Locale.ENGLISH); MLText mlTextProperty = new MLText(); mlTextProperty.addValue(Locale.ENGLISH, "Very good!"); mlTextProperty.addValue(Locale.FRENCH, "Très bon!"); mlTextProperty.addValue(Locale.GERMAN, "Sehr gut!"); nodeService.setProperty( rootNodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE, mlTextProperty); // Check unfiltered property retrieval Serializable textValueDirect = nodeService.getProperty( rootNodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE); assertEquals( "MLText type not returned direct", mlTextProperty, textValueDirect); // Check unfiltered mass property retrieval Map<QName, Serializable> propertiesDirect = nodeService.getProperties(rootNodeRef); assertEquals( "MLText type not returned direct in Map", mlTextProperty, propertiesDirect.get(BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE)); }
ml.addValue(Locale.ENGLISH, "Test " + position); properties.put(ContentModel.PROP_DESCRIPTION, ml); properties.put(ContentModel.PROP_TITLE, ml);
/** * Ensure that plain strings going into MLText properties is handled */ @SuppressWarnings("unchecked") public void testSingleStringMLTextProperty() throws Exception { // Set the property with single-value MLText MLText mlText = new MLText(); mlText.addValue(Locale.GERMAN, "Sehr gut!"); nodeService.setProperty(rootNodeRef, PROP_QNAME_ML_TEXT_VALUE, mlText); // Get it back and check MLText mlTextCheck = (MLText) nodeService.getProperty(rootNodeRef, PROP_QNAME_ML_TEXT_VALUE); assertEquals("Setting of MLText over String failed.", mlText, mlTextCheck); }
String DEFAULT_DESCRIPTION = "default description"; MLText description = new MLText(); description.addValue(Locale.getDefault(), DEFAULT_DESCRIPTION); description.addValue(Locale.FRANCE, FRENCH_DESCRIPTION); description.addValue(Locale.GERMAN, GERMAN_DESCRIPTION); description.addValue(Locale.ITALY, ITALY_DESCRIPTION); props.put(ContentModel.PROP_DESCRIPTION, description);
FileInfo content = fileFolderService.create(exportFolder.getNodeRef(), "file", ContentModel.TYPE_CONTENT); MLText title = new MLText(); title.addValue(Locale.ENGLISH, null); title.addValue(Locale.FRENCH, "bonjour"); nodeService.setProperty(content.getNodeRef(), ContentModel.PROP_TITLE, title); nodeService.setProperty(content.getNodeRef(), ContentModel.PROP_NAME, "file");