1 40 package org.jahia.engines.validation; 41 42 import java.util.*; 43 44 import org.apache.commons.lang.StringUtils; 45 import org.apache.commons.lang.builder.ToStringBuilder; 46 47 57 public class JahiaMltHelper { 58 private String [] text = null; 59 private String [] language = null; 60 private List languageSettings = null; 61 62 65 public JahiaMltHelper(List currentLanguageSettings) { 66 super(); 67 languageSettings = currentLanguageSettings; 68 } 69 70 76 public String getText(String lang) { 77 for (int i = 0; i < language.length; i++) { 78 if (language[i].equals(lang)) { 79 return text[i]; 80 } 81 } 82 return ""; 83 } 84 85 88 public String [] getLanguage() { 89 return language; 90 } 91 92 95 public String [] getText() { 96 return text; 97 } 98 99 102 public void setLanguage(String [] strings) { 103 language = strings; 104 } 105 106 109 public void setText(String [] strings) { 110 text = strings; 111 } 112 113 118 public void addMltItem(String lang, String txt) { 119 if (language != null && text != null) { 120 int oldLen = language.length; 121 String newLanguage[] = new String [oldLen + 1]; 122 String newText[] = new String [oldLen + 1]; 123 124 System.arraycopy(language, 0, newLanguage, 0, oldLen); 125 System.arraycopy(text, 0, newText, 0, oldLen); 126 newLanguage[oldLen] = lang; 127 newText[oldLen] = txt; 128 language = newLanguage; 129 text = newText; 130 } else { 131 language = new String [1]; 132 language[0] = lang; 133 text = new String [1]; 134 text[0] = txt; 135 } 136 } 137 138 141 public List getLanguageSettings() { 142 return languageSettings; 143 } 144 145 public String toString() { 146 return ToStringBuilder.reflectionToString(this); 147 } 148 149 public boolean isEmpty() { 150 boolean nonEmpty = false; 151 for (int i = 0; i < text.length && !nonEmpty; i++) { 152 String s = text[i]; 153 if(StringUtils.trimToNull(s)!=null)nonEmpty =true; 154 } 155 return !nonEmpty; 156 } 157 } 158 | Popular Tags |