Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ public interface ResourceConfig {
*/
String SELECTOR_NONE = "none";


/**
* A reserved selector for resources that hold config parameters.
*/
String GLOBAL_PARAMETERS = "global-parameters";


/**
* Performs a shallow clone of this <code>ResourceConfig</code>.
*
Expand Down
14 changes: 5 additions & 9 deletions core/src/main/java/org/smooks/FilterSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@
import org.smooks.engine.delivery.dom.DOMFilterType;
import org.smooks.engine.delivery.sax.ng.SaxNgFilterType;
import org.smooks.engine.lookup.ResourceConfigSeqsLookup;
import org.smooks.engine.resource.config.DefaultResourceConfig;

import java.util.Properties;

import static org.smooks.api.resource.config.ResourceConfig.GLOBAL_PARAMETERS;
import org.smooks.engine.resource.config.GlobalParamsResourceConfig;

/**
* Smooks filter settings for programmatic configuration of the {@link Smooks} instance.
Expand Down Expand Up @@ -220,16 +216,16 @@ private void assertNonStaticDecl() {
}

private void setParameter(String name, Object value, Registry registry) {
ResourceConfig resourceConfig = new DefaultResourceConfig(GLOBAL_PARAMETERS, new Properties());
resourceConfig.setParameter(name, value);
registry.registerResourceConfig(resourceConfig);
ResourceConfig globalParamsResourceConfig = new GlobalParamsResourceConfig();
globalParamsResourceConfig.setParameter(name, value);
registry.registerResourceConfig(globalParamsResourceConfig);
}

private void removeParameter(String name, Registry registry) {
for (ResourceConfigSeq resourceConfigSeq : registry.lookup(new ResourceConfigSeqsLookup())) {
for (int i = 0; i < resourceConfigSeq.size(); i++) {
ResourceConfig nextResourceConfig = resourceConfigSeq.get(i);
if (GLOBAL_PARAMETERS.equals(nextResourceConfig.getSelectorPath().getSelector())) {
if (GlobalParamsResourceConfig.GLOBAL_PARAMETERS.equals(nextResourceConfig.getSelectorPath().getSelector())) {
nextResourceConfig.removeParameter(name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.smooks.engine.bean.context.DefaultBeanIdStore;
import org.smooks.engine.delivery.DefaultReaderPoolFactory;
import org.smooks.engine.resource.config.DefaultResourceConfig;
import org.smooks.engine.resource.config.GlobalParamsResourceConfig;
import org.smooks.engine.resource.config.SystemResourceConfigSeqFactory;
import org.smooks.api.ApplicationContext;
import org.smooks.api.ApplicationContextBuilder;
Expand All @@ -71,8 +72,6 @@
import java.util.Properties;
import java.util.ServiceLoader;

import static org.smooks.api.resource.config.ResourceConfig.GLOBAL_PARAMETERS;

public class DefaultApplicationContextBuilder implements ApplicationContextBuilder {

protected boolean systemResources = true;
Expand Down Expand Up @@ -217,8 +216,8 @@ protected void registerSystemResources(final Registry registry, final Applicatio
}

protected void setParameter(String name, Object value, Registry registry) {
ResourceConfig resourceConfig = new DefaultResourceConfig(GLOBAL_PARAMETERS, new Properties());
resourceConfig.setParameter(name, value);
registry.registerResourceConfig(resourceConfig);
ResourceConfig globalParamsResourceConfig = new GlobalParamsResourceConfig();
globalParamsResourceConfig.setParameter(name, value);
registry.registerResourceConfig(globalParamsResourceConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,12 @@ public Class<BeforeVisitor> getTarget() {
return BeforeVisitor.class;
}
}

public ApplicationContext getApplicationContext() {
return applicationContext;
}

public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.smooks.api.delivery.ContentDeliveryConfig;
import org.smooks.api.resource.config.ResourceConfig;
import org.smooks.api.resource.config.ResourceConfigSeq;
import org.smooks.engine.resource.config.GlobalParamsResourceConfig;
import org.smooks.engine.resource.config.ParameterDecoder;
import org.smooks.engine.resource.config.TokenizedStringParameterDecoder;

Expand Down Expand Up @@ -82,7 +83,7 @@ public ParameterAccessor apply(final Map<Object, Object> registryEntries) {
for (final ResourceConfigSeq resourceConfigSeq : resourceConfigSeqs) {
for (int i = 0; i < resourceConfigSeq.size(); i++) {
final ResourceConfig nextResourceConfig = resourceConfigSeq.get(i);
if (ResourceConfig.GLOBAL_PARAMETERS.equals(nextResourceConfig.getSelectorPath().getSelector())) {
if (GlobalParamsResourceConfig.GLOBAL_PARAMETERS.equals(nextResourceConfig.getSelectorPath().getSelector())) {
for (Map.Entry<String, Object> globalParameter : nextResourceConfig.getParameters().entrySet()) {
if (globalParams.get(globalParameter.getKey()) == null) {
String systemProperty = System.getProperty(globalParameter.getKey());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*-
* ========================LICENSE_START=================================
* Smooks Core
* %%
* Copyright (C) 2020 - 2024 Smooks
* %%
* Licensed under the terms of the Apache License Version 2.0, or
* the GNU Lesser General Public License version 3.0 or later.
*
* SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later
*
* ======================================================================
*
* Licensed 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.
*
* ======================================================================
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* =========================LICENSE_END==================================
*/
package org.smooks.engine.resource.config;

import org.smooks.api.profile.Profile;

import java.util.Properties;

public class GlobalParamsResourceConfig extends DefaultResourceConfig {

/**
* A reserved selector for resources that hold config parameters.
*/
public static final String GLOBAL_PARAMETERS = "global-parameters";

public GlobalParamsResourceConfig() {
setSelector(GLOBAL_PARAMETERS, new Properties());
setProfile(Profile.DEFAULT_PROFILE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.smooks.engine.resource.config.DefaultResourceConfig;
import org.smooks.engine.resource.config.DefaultResourceConfigFactory;
import org.smooks.engine.resource.config.DefaultResourceConfigSeq;
import org.smooks.engine.resource.config.GlobalParamsResourceConfig;
import org.smooks.engine.resource.config.loader.xml.extension.ExtensionContext;
import org.smooks.io.source.DOMSource;
import org.smooks.resource.URIResourceLocator;
Expand Down Expand Up @@ -220,10 +221,10 @@ protected void digestParams(Element paramsElement) {
NodeList paramNodes = paramsElement.getElementsByTagName("param");

if (paramNodes.getLength() > 0) {
ResourceConfig globalParamsConfig = new DefaultResourceConfig(ResourceConfig.GLOBAL_PARAMETERS, new Properties());
ResourceConfig globalParamsResourceConfig = new GlobalParamsResourceConfig();

digestParameters(paramsElement, globalParamsConfig);
resourceConfigSeq.add(globalParamsConfig);
digestParameters(paramsElement, globalParamsResourceConfig);
resourceConfigSeq.add(globalParamsResourceConfig);
}
}

Expand Down
Loading