Remove trunk directory

This commit is contained in:
Paulo Gustavo Veiga
2009-11-06 23:30:29 -02:00
parent 2494133fed
commit 75470a91fd
715 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.validator;
import org.springframework.validation.Validator;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import com.wisemapping.view.ChangePasswordBean;
import com.wisemapping.model.Constants;
public class ChangePasswordValidator
implements Validator {
public boolean supports(final Class clazz) {
return clazz.equals(ChangePasswordBean.class);
}
public void validate(Object obj, Errors errors) {
ChangePasswordBean bean = (ChangePasswordBean) obj;
if (bean == null) {
errors.rejectValue("changePassword", "error.not-specified", null, "Value required.");
} else {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "required", "Field is required.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "retryPassword", "required", "Field is required.");
ValidatorUtils.rejectIfExceeded(errors,
"password",
"The password must have less than "+ Constants.MAX_USER_PASSWORD_LENGTH + " characters.",
bean.getPassword(),
Constants.MAX_USER_PASSWORD_LENGTH);
ValidatorUtils.rejectIfExceeded(errors,
"retryPassword",
"The retryPassword must have less than "+ Constants.MAX_USER_PASSWORD_LENGTH + " characters.",
bean.getRetryPassword(),
Constants.MAX_USER_PASSWORD_LENGTH);
final String password = bean.getPassword();
if (password != null && !password.equals(bean.getRetryPassword())) {
errors.rejectValue("password", "Password mismatch", "Your password entries did not match");
}
}
}
}

View File

@@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.validator;
import com.wisemapping.view.UserBean;
import com.wisemapping.controller.Messages;
import com.wisemapping.service.UserService;
import com.wisemapping.model.User;
import com.wisemapping.model.Constants;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
public class EditProfileValidator implements Validator {
private UserService userService;
public boolean supports(final Class clazz) {
return clazz.equals(UserBean.class);
}
public void validate(Object obj, Errors errors) {
UserBean user = (UserBean) obj;
if (user == null) {
errors.rejectValue("user", "error.not-specified", null, "Value required.");
} else {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstname", "required", "Field is required.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastname", "required", "Field is required.");
ValidatorUtils.rejectIfExceeded(errors,
"firstname",
"The firstname must have less than "+ Constants.MAX_USER_FIRSTNAME_LENGTH + " characters.",
user.getFirstname(),
Constants.MAX_USER_FIRSTNAME_LENGTH);
ValidatorUtils.rejectIfExceeded(errors,
"lastname",
"The lastname must have less than "+ Constants.MAX_USER_LASTNAME_LENGTH + " characters.",
user.getLastname(),
Constants.MAX_USER_LASTNAME_LENGTH);
final String email = user.getEmail();
boolean isValid = Utils.isValidateEmailAddress(email);
if (isValid) {
final User oldUser = userService.getUserBy(email);
if (oldUser != null && user.getId() != oldUser.getId()) {
errors.rejectValue("email", Messages.EMAIL_ALREADY_EXIST);
}
} else {
Utils.validateEmailAddress(email, errors);
}
}
}
public void setUserService(UserService userService) {
this.userService = userService;
}
}

View File

@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.validator;
import org.springframework.validation.Validator;
import org.springframework.validation.Errors;
import com.wisemapping.view.ForgotPasswordBean;
import com.wisemapping.controller.Messages;
public class ForgotPasswordValidator
implements Validator {
public boolean supports(final Class clazz) {
return clazz.equals(ForgotPasswordBean.class);
}
public void validate(Object obj, Errors errors) {
ForgotPasswordBean bean = (ForgotPasswordBean) obj;
if (bean == null) {
errors.rejectValue("forgotPassword", "error.not-specified", null, "Value required.");
} else {
final String email = bean.getEmail();
boolean isValid = Utils.isValidateEmailAddress(email);
if (!isValid) {
errors.rejectValue("email", Messages.NO_VALID_EMAIL_ADDRESS);
}
}
}
}

View File

@@ -0,0 +1,57 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.validator;
import com.wisemapping.controller.Messages;
import com.wisemapping.importer.ImportFormat;
import com.wisemapping.importer.Importer;
import com.wisemapping.importer.ImporterException;
import com.wisemapping.importer.ImporterFactory;
import com.wisemapping.model.MindMap;
import com.wisemapping.view.ImportMapBean;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import java.io.ByteArrayInputStream;
public class ImportMapValidator extends MapInfoValidator {
public boolean supports(final Class clazz) {
return clazz.equals(ImportMapBean.class);
}
public void validate(Object obj, Errors errors) {
ImportMapBean bean = (ImportMapBean) obj;
super.validate(obj,errors);
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "mapFile", Messages.FIELD_REQUIRED);
try {
final Importer importer = ImporterFactory.getInstance().getImporter(ImportFormat.FREEMIND);
final ByteArrayInputStream stream = new ByteArrayInputStream(bean.getMapFile().getBytes());
final MindMap map = importer.importMap(bean.getTitle(),bean.getDescription(),stream);
bean.setImportedMap(map);
} catch (ImporterException e) {
errors.rejectValue("mapFile",Messages.IMPORT_MAP_ERROR);
}
}
}

View File

@@ -0,0 +1,83 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.validator;
import com.wisemapping.controller.Messages;
import com.wisemapping.model.MindMap;
import com.wisemapping.model.User;
import com.wisemapping.model.Constants;
import com.wisemapping.service.MindmapService;
import com.wisemapping.view.MindMapInfoBean;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
public class MapInfoValidator implements Validator {
private MindmapService mindmapService;
public boolean supports(final Class clazz) {
return clazz.equals(MindMapInfoBean.class);
}
public void validate(Object obj, Errors errors) {
final MindMapInfoBean map = (MindMapInfoBean) obj;
if (map == null) {
errors.rejectValue("map", "error.not-specified", null, "Value required.");
} else {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", Messages.FIELD_REQUIRED);
final String title = map.getTitle();
final String desc = map.getDescription();
if (title != null && title.length() > 0) {
if (title.length() > Constants.MAX_MAP_NAME_LENGTH) {
errors.rejectValue("title", "field.max.length",
new Object[]{Constants.MAX_MAP_NAME_LENGTH},
"The title must have less than " + Constants.MAX_MAP_NAME_LENGTH + " characters.");
} else {
// Map alredy exists ?
final MindmapService service = this.getMindmapService();
final User user = com.wisemapping.security.Utils.getUser();
final MindMap mindMap = service.getMindmapByTitle(title, user);
if (mindMap != null) {
errors.rejectValue("title", Messages.MAP_TITLE_ALREADY_EXISTS);
}
}
}
ValidatorUtils.rejectIfExceeded(errors,
"description",
"The description must have less than "+Constants.MAX_MAP_DESCRIPTION_LENGTH + " characters.",
desc,
Constants.MAX_MAP_DESCRIPTION_LENGTH);
}
}
public MindmapService getMindmapService() {
return mindmapService;
}
public void setMindmapService(MindmapService mindmapService) {
this.mindmapService = mindmapService;
}
}

View File

@@ -0,0 +1,83 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.validator;
import org.springframework.validation.Validator;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import com.wisemapping.service.MindmapService;
import com.wisemapping.view.MindMapInfoBean;
import com.wisemapping.controller.Messages;
import com.wisemapping.model.Constants;
import com.wisemapping.model.User;
import com.wisemapping.model.MindMap;
public class RenameMapValidator
implements Validator {
private MindmapService mindmapService;
public boolean supports(final Class clazz) {
return clazz.equals(MindMapInfoBean.class);
}
public void validate(Object obj, Errors errors) {
final MindMapInfoBean map = (MindMapInfoBean) obj;
if (map == null) {
errors.rejectValue("map", "error.not-specified", null, "Value required.");
} else {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", Messages.FIELD_REQUIRED);
final String title = map.getTitle();
final String desc = map.getDescription();
if (title != null && title.length() > 0) {
if (title.length() > Constants.MAX_MAP_NAME_LENGTH) {
errors.rejectValue("title", "field.max.length",
new Object[]{Constants.MAX_MAP_NAME_LENGTH},
"The title must have less than " + Constants.MAX_MAP_NAME_LENGTH + " characters.");
} else {
// Map alredy exists ?
final MindmapService service = this.getMindmapService();
final User user = com.wisemapping.security.Utils.getUser();
final MindMap mindMap = service.getMindmapByTitle(title, user);
if (mindMap != null && map.getMindMap().getId() != mindMap.getId() ) {
errors.rejectValue("title", Messages.MAP_TITLE_ALREADY_EXISTS);
}
}
}
ValidatorUtils.rejectIfExceeded(errors,
"description",
"The description must have less than "+Constants.MAX_MAP_DESCRIPTION_LENGTH + " characters.",
desc,
Constants.MAX_MAP_DESCRIPTION_LENGTH);
}
}
public MindmapService getMindmapService() {
return mindmapService;
}
public void setMindmapService(MindmapService mindmapService) {
this.mindmapService = mindmapService;
}
}

View File

@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.validator;
import com.wisemapping.model.Constants;
import com.wisemapping.view.TagBean;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
public class TagValidator implements Validator {
public boolean supports(final Class clazz) {
return clazz.equals(TagBean.class);
}
public void validate(Object obj, Errors errors) {
TagBean tag = (TagBean) obj;
if (tag == null) {
errors.rejectValue("user", "error.not-specified");
} else {
// Validate email address ...
final String tags = tag.getMindmapTags();
ValidatorUtils.rejectIfExceeded(errors,
"mindmapTags",
"The tags must have less than "+ Constants.MAX_TAGS_LENGTH + " characters.",
tags,
Constants.MAX_TAGS_LENGTH);
}
}
}

View File

@@ -0,0 +1,104 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.validator;
import com.wisemapping.controller.Messages;
import com.wisemapping.service.UserService;
import com.wisemapping.view.UserBean;
import com.wisemapping.model.Constants;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
public class UserValidator
implements Validator {
private UserService userService;
public boolean supports(final Class clazz) {
return clazz.equals(UserBean.class);
}
public void validate(Object obj, Errors errors) {
UserBean user = (UserBean) obj;
if (user == null) {
errors.rejectValue("user", "error.not-specified");
} else {
// Validate email address ...
final String email = user.getEmail();
boolean isValid = Utils.isValidateEmailAddress(email);
if (isValid) {
if (userService.getUserBy(email) != null) {
errors.rejectValue("email", Messages.EMAIL_ALREADY_EXIST);
}
} else {
Utils.validateEmailAddress(email, errors);
}
// Validate username ...
final String username = user.getUsername();
if (username != null && userService.getUserByUsername(username) != null) {
errors.rejectValue("username", Messages.USERNAME_ALREADY_EXIST);
} else {
ValidationUtils.rejectIfEmpty(errors, "username", Messages.FIELD_REQUIRED);
}
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstname", Messages.FIELD_REQUIRED);
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastname", Messages.FIELD_REQUIRED);
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", Messages.FIELD_REQUIRED);
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "retypePassword", Messages.FIELD_REQUIRED);
ValidatorUtils.rejectIfExceeded(errors,
"firstname",
"The firstname must have less than "+ Constants.MAX_USER_FIRSTNAME_LENGTH + " characters.",
user.getFirstname(),
Constants.MAX_USER_FIRSTNAME_LENGTH);
ValidatorUtils.rejectIfExceeded(errors,
"lastname",
"The lastname must have less than "+ Constants.MAX_USER_LASTNAME_LENGTH + " characters.",
user.getLastname(),
Constants.MAX_USER_LASTNAME_LENGTH);
ValidatorUtils.rejectIfExceeded(errors,
"username",
"The username must have less than "+ Constants.MAX_USER_USERNAME_LENGTH + " characters.",
username,
Constants.MAX_USER_USERNAME_LENGTH);
ValidatorUtils.rejectIfExceeded(errors,
"password",
"The password must have less than "+ Constants.MAX_USER_PASSWORD_LENGTH + " characters.",
user.getPassword(),
Constants.MAX_USER_PASSWORD_LENGTH);
ValidatorUtils.rejectIfExceeded(errors,
"retypePassword",
"The retypePassword must have less than "+ Constants.MAX_USER_PASSWORD_LENGTH + " characters.",
user.getRetypePassword(),
Constants.MAX_USER_PASSWORD_LENGTH);
final String password = user.getPassword();
if (password != null && !password.equals(user.getRetypePassword())) {
errors.rejectValue("password", Messages.PASSWORD_MISSMATCH);
}
}
}
public void setUserService(UserService userService) {
this.userService = userService;
}
}

View File

@@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.validator;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import com.wisemapping.controller.Messages;
public class Utils {
//Set the email emailPattern string
static private Pattern emailPattern = Pattern.compile(".+@.+\\.[a-z]+");
private Utils() {
}
static void validateEmailAddress(final String email, final Errors errors) {
if (email == null || email.trim().length() == 0) {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", Messages.FIELD_REQUIRED);
} else {
boolean isValid = Utils.isValidateEmailAddress(email);
if (!isValid) {
errors.rejectValue("email", Messages.NO_VALID_EMAIL_ADDRESS);
}
}
}
static boolean isValidateEmailAddress(final String email) {
//Match the given string with the emailPattern
final Matcher m = emailPattern.matcher(email);
//check whether match is found
return m.matches();
}
}

View File

@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
*/
package com.wisemapping.validator;
import org.springframework.validation.ValidationUtils;
public class ValidatorUtils
extends ValidationUtils
{
public static void rejectIfExceeded(org.springframework.validation.Errors errors,
java.lang.String title,
java.lang.String message,
String value,
int limit)
{
if (value != null && value.length() > limit) {
errors.rejectValue(title, "field.max.length",message);
}
}
}