Skip to content

Commit

Permalink
Ensure absolute path in non empty opac search interface urls
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Jul 1, 2022
1 parent 20c48fd commit 36643ea
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ INSERT IGNORE INTO importconfiguration (title, description, configuration_type,
default_searchfield_id, identifier_searchfield_id, metadata_format, scheme,
host, path, sru_version, sru_record_schema)
VALUES ('K10Plus-SLUB-PICA', 'K10Plus OPAC PICA', 'OPAC_SEARCH', 'SRU', 'XML', 2, 2, 'PICA', 'https', 'sru.k10plus.de',
'gvk', '1.1', 'picaxml');
'/gvk', '1.1', 'picaxml');

-- 8. Add search fields for K10Plus import configuration
INSERT IGNORE INTO searchfield (importconfiguration_id, field_label, field_value) VALUES (1, 'Titel', 'pica.tit');
Expand Down
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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,24 @@
<p:ajax event="change"
oncomplete="toggleSave()"/>
</p:selectOneMenu>
<p:inputText id="host" styleClass="input url-part"
<p:inputText id="host"
styleClass="input url-part"
value="#{importConfigurationEditView.importConfiguration.host}"
placeholder="#{msgs['importConfig.field.host']}"
disabled="#{isViewMode}"
required="#{not empty param['editForm:save']}"/>
<p:inputText id="port" styleClass="input url-part"
<p:inputText id="port"
styleClass="input url-part"
value="#{importConfigurationEditView.importConfiguration.port}"
placeholder="#{msgs['importConfig.field.port']}"
disabled="#{isViewMode}">
<p:keyFilter mask="int"/>
</p:inputText>
<p:inputText id="path" styleClass="input url-part"
<p:inputText id="path"
styleClass="input url-part"
value="#{importConfigurationEditView.importConfiguration.path}"
placeholder="#{msgs['importConfig.field.path']}"
validator="AbsolutePathValidator"
disabled="#{isViewMode}"/>
</p:panelGrid>
<p:commandButton id="urlHelp" type="button"
Expand Down
7 changes: 2 additions & 5 deletions Kitodo/src/main/webapp/pages/importConfigurationEdit.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,14 @@
icon="fa fa-times fa-lg" iconPos="right"
styleClass="secondary"/>
<p:commandButton id="save"
widgetVar="save"
value="#{msgs.save}"
action="#{importConfigurationEditView.save}"
icon="fa fa-floppy-o fa-lg"
iconPos="right"
rendered="#{isEditMode || isCreateMode}"
disabled="#{importConfigurationEditView.saveDisabled}"
onclick="setConfirmUnload(false);"
onsuccess="PF('notifications').renderMessage({
'summary':'#{msgs.configurationSaving}',
'detail':'#{msgs.youWillBeRedirected}',
'severity':'info'});"/>
onclick="setConfirmUnload(false);PF('save').disable();"/>
<p:commandButton id="saveButtonToggler"
actionListener="#{importConfigurationEditView.setSaveDisabled(false)}"
update="save"
Expand Down

0 comments on commit 36643ea

Please sign in to comment.