Merge branch 'master' of https://git.bukova.info/repos/git/isspst
						commit
						10439b5001
					
				@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					package info.bukova.isspst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.regex.Matcher;
 | 
				
			||||||
 | 
					import java.util.regex.Pattern;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class RegExUtils {
 | 
				
			||||||
 | 
						public static List<String> getMatches(String input, String regEx, int group) {
 | 
				
			||||||
 | 
							List<String> list = new ArrayList<String>();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if (!StringUtils.isNullOrEmpty(input) && !StringUtils.isNullOrEmpty(regEx)) {
 | 
				
			||||||
 | 
								Pattern pattern = Pattern.compile(regEx);
 | 
				
			||||||
 | 
								Matcher matcher = pattern.matcher(input);
 | 
				
			||||||
 | 
								int groupCount = matcher.groupCount() + 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if ((groupCount >= 0) && (group < groupCount)) {
 | 
				
			||||||
 | 
									while (matcher.find()) {
 | 
				
			||||||
 | 
										String item = matcher.group(group);
 | 
				
			||||||
 | 
										list.add(item);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return list;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public static List<String> getMatches(String input, String regEx) {
 | 
				
			||||||
 | 
							return RegExUtils.getMatches(input, regEx, 0);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					package info.bukova.isspst.ui;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.zkoss.bind.annotation.Init;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class BindingViewModel<T> extends DocumentViewModel {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private BindingForm<T> dataForm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Init
 | 
				
			||||||
 | 
						public void initBindingViewModel() {
 | 
				
			||||||
 | 
							super.initDocumentViewModel();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							dataForm = new BindingForm<T>();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public BindingForm<T> getDataForm() {
 | 
				
			||||||
 | 
							return this.dataForm;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,155 @@
 | 
				
			|||||||
 | 
					package info.bukova.isspst.validators;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import info.bukova.isspst.Constants;
 | 
				
			||||||
 | 
					import info.bukova.isspst.RegExUtils;
 | 
				
			||||||
 | 
					import info.bukova.isspst.StringUtils;
 | 
				
			||||||
 | 
					import info.bukova.isspst.data.Requirement;
 | 
				
			||||||
 | 
					import info.bukova.isspst.data.SettingsData;
 | 
				
			||||||
 | 
					import info.bukova.isspst.sort.ReflectionTools;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.slf4j.Logger;
 | 
				
			||||||
 | 
					import org.slf4j.LoggerFactory;
 | 
				
			||||||
 | 
					import org.zkoss.bind.ValidationContext;
 | 
				
			||||||
 | 
					import org.zkoss.zk.ui.Component;
 | 
				
			||||||
 | 
					import org.zkoss.zul.Tab;
 | 
				
			||||||
 | 
					import org.zkoss.zul.Tabbox;
 | 
				
			||||||
 | 
					import org.zkoss.zul.Window;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class GlobalSettingValidator extends BaseValidator {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private final static Logger log = LoggerFactory.getLogger(GlobalSettingValidator.class.getName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private Window mainWindow;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private SettingsData settingsData;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public GlobalSettingValidator(Window mainWindow) {
 | 
				
			||||||
 | 
							this.mainWindow = mainWindow;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private String SwitchTabs(String idIncludedPage, String idTabBox, String idTab, boolean select) {
 | 
				
			||||||
 | 
							if (this.mainWindow == null) {
 | 
				
			||||||
 | 
								log.warn("Neznámé okno globálního nastavení!!!");
 | 
				
			||||||
 | 
								return "";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (StringUtils.isNullOrEmpty(idTabBox) || StringUtils.isNullOrEmpty(idTab)) {
 | 
				
			||||||
 | 
								log.warn("Neznámý Tabbox nebo Tab identifikátor globálního nastavení!!!");
 | 
				
			||||||
 | 
								return "";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Component component = this.mainWindow;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!StringUtils.isNullOrEmpty(idIncludedPage)) {
 | 
				
			||||||
 | 
								Component includedPageComponent = component.getFellow(idIncludedPage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (includedPageComponent != null) {
 | 
				
			||||||
 | 
									component = includedPageComponent;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Tabbox tabBox = (Tabbox) component.getFellowIfAny(idTabBox, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (tabBox == null) {
 | 
				
			||||||
 | 
								log.warn("Neznámý Tabbox identifikátor '" + idTabBox + "' globálního nastavení!!!");
 | 
				
			||||||
 | 
								return "";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else {
 | 
				
			||||||
 | 
								Tab tab = (Tab) component.getFellowIfAny(idTab, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (tab == null) {
 | 
				
			||||||
 | 
									log.warn("Neznámý Tab identifikátor '" + idTab + "' globálního nastavení!!!");
 | 
				
			||||||
 | 
									return "";
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (select) {
 | 
				
			||||||
 | 
										tabBox.setSelectedTab(tab);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									return tab.getLabel();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private void validateMailMessage(String text, String idTab, String idComponent) {
 | 
				
			||||||
 | 
							if (this.ctx == null) {
 | 
				
			||||||
 | 
								log.warn("Neznámý ValidationContext!!!");
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							List<String> properties = ReflectionTools.getEntityFields(Requirement.class);
 | 
				
			||||||
 | 
							properties.add(Constants.MAIL_URL_KEYWORD);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (StringUtils.isNullOrEmpty(text)) {
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							List<String> matches;
 | 
				
			||||||
 | 
							final String regex = "\\[([^\\[\\]]*?)\\]";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							matches = RegExUtils.getMatches(text, regex, 1);
 | 
				
			||||||
 | 
							String message = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							for (int i = 0; i < matches.size(); i++) {
 | 
				
			||||||
 | 
								String propertyCandidate = matches.get(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (!properties.contains(propertyCandidate)) {
 | 
				
			||||||
 | 
									message = "Vlastnost [" + propertyCandidate + "] neexistuje!";
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if (StringUtils.isNullOrEmpty(message)) {
 | 
				
			||||||
 | 
								text = text.replaceAll(regex, "");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (StringUtils.isNullOrEmpty(message) && text.contains("[")) {
 | 
				
			||||||
 | 
								message = "Chybně použitý speciální znak '[' !\n";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (StringUtils.isNullOrEmpty(message) && text.contains("]")) {
 | 
				
			||||||
 | 
								message = "Chybně použitý speciální znak ']' !\n";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							boolean badCondition = !StringUtils.isNullOrEmpty(message);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if (badCondition) {
 | 
				
			||||||
 | 
								this.SwitchTabs("", "idTabBox", "idTabEmails", true);
 | 
				
			||||||
 | 
								this.SwitchTabs("idIncludedPageEmails", "idTabBoxEmails", idTab, true);
 | 
				
			||||||
 | 
								this.errorMsg(this.ctx, message, idComponent);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						public void validate(ValidationContext ctx) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							super.validate(ctx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Map<String, Property[]> map = ctx.getProperties();
 | 
				
			||||||
 | 
							//
 | 
				
			||||||
 | 
							// for (Map.Entry<String, Property[]> entry : map.entrySet()) {
 | 
				
			||||||
 | 
							// String key = entry.getKey();
 | 
				
			||||||
 | 
							// Property[] values = entry.getValue();
 | 
				
			||||||
 | 
							// }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							String value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							value = this.getStringProperty("newReqTemplate.text");
 | 
				
			||||||
 | 
							this.validateMailMessage(value, "idTabEmailsNewRequirement", "idEmailNewReqTemplateText");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							value = this.getStringProperty("authReqTemplate.text");
 | 
				
			||||||
 | 
							this.validateMailMessage(value, "idTabEmailsAuthRequirement", "idEmailAuthReqTemplateText");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							value = this.getStringProperty("confReqTemplate.text");
 | 
				
			||||||
 | 
							this.validateMailMessage(value, "idTabEmailsConfirmRequirement", "idEmailConfReqTemplateText");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							value = this.getStringProperty("reqPassenger.text");
 | 
				
			||||||
 | 
							this.validateMailMessage(value, "idTabEmailsReqTripPassengers", "idEmailReqPassengerTemplateText");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							value = this.getStringProperty("confReqTripPassenger.text");
 | 
				
			||||||
 | 
							this.validateMailMessage(value, "idTabEmailsConfirmTripPassengers", "idEmailConfReqTripPassengerTemplateText");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
					Loading…
					
					
				
		Reference in New Issue