org.magicwerk.brownies.jdom.XmlStylesheet Maven / Gradle / Ivy
/*
* Copyright 2010 by Thomas Mauch
*
* 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.
*
* $Id$
*/
package org.magicwerk.brownies.jdom;
import java.util.function.Function;
import javax.xml.transform.stream.StreamSource;
import org.magicwerk.brownies.collections.Key1List;
/**
* This class describes a transformation using a XSLT stylesheet.
* The transformation can use parameters to customize the transformation.
*
* @author Thomas Mauch
* @version $Id$
*/
public class XmlStylesheet {
private StreamSource streamSource;
private Key1List params = new Key1List.Builder().withPrimaryKey1Map(
new Function() {
@Override
public String apply(XmlParam param) {
return param.getName();
}
}
).build();
/**
* Construct XML stylesheet from specified URL.
*
* @param url XML stylesheet document
*/
public XmlStylesheet(String url) {
this(XmlProcessor.getStreamSource(url));
}
/**
* Construct XML stylesheet from specified stream source.
*
* @param streamSource stream souce
*/
public XmlStylesheet(StreamSource streamSource) {
this.streamSource = streamSource;
}
public StreamSource getStreamSource() {
return streamSource;
}
public int getNumParams() {
if (params == null) {
return 0;
}
return params.size();
}
public XmlParam getParam(int index) {
return params.get(index);
}
public XmlParam getParam(String name) {
return params.getByKey1(name);
}
public Object getParamValue(int index) {
return params.get(index).getValue();
}
public Object getParamValue(String name) {
return params.getByKey1(name).getValue();
}
public void addParam(String name, Object value) {
XmlParam param = new XmlParam(name, value);
params.add(param);
}
public void putParam(String name, Object value) {
XmlParam param = new XmlParam(name, value);
params.putByKey1(param);
}
}