-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure absolute path in non empty opac search interface urls
- Loading branch information
Showing
4 changed files
with
50 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Kitodo/src/main/java/org/kitodo/production/forms/validators/AbsolutePathValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* (c) Kitodo. Key to digital objects e. V. <[email protected]> | ||
* | ||
* This file is part of the Kitodo project. | ||
* | ||
* It is licensed under GNU General Public License version 3 or later. | ||
* | ||
* For the full copyright and license information, please read the | ||
* GPL3-License.txt file that was distributed with this source code. | ||
*/ | ||
|
||
package org.kitodo.production.forms.validators; | ||
|
||
import javax.faces.application.FacesMessage; | ||
import javax.faces.component.UIComponent; | ||
import javax.faces.context.FacesContext; | ||
import javax.faces.validator.FacesValidator; | ||
import javax.faces.validator.Validator; | ||
import javax.faces.validator.ValidatorException; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
|
||
@FacesValidator("AbsolutePathValidator") | ||
public class AbsolutePathValidator implements Validator<String> { | ||
|
||
private static final String SAVE = "editForm:save"; | ||
|
||
@Override | ||
public void validate(FacesContext facesContext, UIComponent uiComponent, String pathString) | ||
throws ValidatorException { | ||
// only validate when saving | ||
if (!facesContext.getExternalContext().getRequestParameterMap().containsKey(SAVE)) { | ||
return; | ||
} | ||
if (StringUtils.isNotBlank(pathString) && !pathString.startsWith("/")) { | ||
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, | ||
"Non empty URL path must be absolute, e.g. start with a '/'!", null)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters