%global cvs_version 2_7_2
%global xalan_data_dir %{buildroot}%{_datadir}/%{name}

Name:           xalan-j2
Version:        2.7.2
Release:        1
Epoch:          0
Summary:        Java XSLT processor
License:        ASL 2.0 and W3C
URL:            http://xalan.apache.org/
Source0:        %{name}-%{version}.tar.gz
Source1:        http://repo1.maven.org/maven2/xalan/xalan/%{version}/xalan-%{version}.pom
Source2:        http://repo1.maven.org/maven2/xalan/serializer/%{version}/serializer-%{version}.pom
Source3:        xsltc-%{version}.pom
Source4:        %{name}-MANIFEST.MF
Source5:        %{name}-serializer-MANIFEST.MF
Source6:        generate-tarball.sh
Patch0:         %{name}-noxsltcdeps.patch


BuildRequires:  ant apache-parent bcel dos2unix glassfish-servlet-api java_cup
BuildRequires:  javapackages-local regexp sed xerces-j2 >= 0:2.7.1
BuildRequires:  xml-commons-apis >= 0:1.3
Requires:       glassfish-servlet-api xerces-j2

BuildArch:      noarch

Provides:       jaxp_transform_impl
Provides:       xalan-j2-demo
Provides:       xalan-j2-javadoc
Provides:       xalan-j2-manual
Obsoletes:      xalan-j2-demo
Obsoletes:      xalan-j2-javadoc
Obsoletes:      xalan-j2-manual

%description
Xalan is an XSLT processor for transforming XML documents into HTML,
text, or other XML document types. It implements the W3C Recommendations
for XSL Transformations (XSLT) and the XML Path Language (XPath). It can
be used from the command line, in an applet or a servlet, or as a module
in other program.


%package        xsltc
Summary:        Java XSLT compiler
License:        ASL 2.0
Requires:       bcel java_cup regexp xerces-j2

%description    xsltc
The XSLT Compiler is a Java-based tool for compiling XSLT stylesheets
into lightweight and portable Java byte codes called translets.


%prep
%autosetup -n xalan-j_%{cvs_version} -p1

find . -name '*.jar' -exec rm -f {} \;
find . -name '*.class' -exec rm -f {} \;

sed -i '/<!-- Expand jaxp sources/,/<delete file="${xml-commons-srcs.tar}"/d' build.xml

sed -i '/class-path/I d' `find -iname '*manifest*'`

dos2unix KEYS LICENSE.txt NOTICE.txt xdocs/style/resources/script.js \
    xdocs/sources/xsltc/README* `find -name '*.sh'`

%mvn_file :xalan %{name} jaxp_transform_impl
%mvn_file :serializer %{name}-serializer
%mvn_file :xsltc xsltc
%mvn_package :xsltc xsltc

%build
pushd lib
ln -sf `build-classpath bcel` BCEL.jar
ln -sf `build-classpath regexp` regexp.jar
ln -sf `build-classpath java_cup-runtime` runtime.jar
ln -sf `build-classpath xerces-j2` xercesImpl.jar
ln -sf `build-classpath xml-commons-apis` xml-apis.jar
popd
pushd tools
ln -sf `build-classpath ant` ant.jar
ln -sf `build-classpath java_cup` java_cup.jar
popd

export CLASSPATH=`build-classpath glassfish-servlet-api`

ant \
  -Djava.awt.headless=true \
  -Dapi.j2se=%{_javadocdir}/java \
  -Dbuild.xalan-interpretive.jar=build/xalan-interpretive.jar \
  xalan-interpretive.jar\
  xsltc.unbundledjar \
  docs \
  javadocs \
  samples \
  servlet

jar ufm build/serializer.jar %{SOURCE5}
jar ufm build/xalan-interpretive.jar %{SOURCE4}

%mvn_artifact %{SOURCE1} build/xalan-interpretive.jar
%mvn_artifact %{SOURCE2} build/serializer.jar
%mvn_artifact %{SOURCE3} build/xsltc.jar

%install
%mvn_install -J build/docs/apidocs
sed -i 's/[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/f2f42549-cfab-4d71-be48-5e9f9a41e5f5/g' `find %{_buildrootdir} -name xalan-j2.xml`

install -D -p -m 644 build/xalansamples.jar %{xalan_data_dir}/%{name}-samples.jar
install -D -p -m 644 build/xalanservlet.war %{xalan_data_dir}/%{name}-servlet.war
cp -pr samples %{xalan_data_dir}

pushd build/docs
ln -sf %{_javadocdir}/%{name} apidocs
popd

%post
mv %{_javadir}/jaxp_transform_impl.jar{,.tmp} || :
update-alternatives --remove jaxp_transform_impl %{_javadir}/%{name}.jar &>/dev/null || :
mv %{_javadir}/jaxp_transform_impl.jar{.tmp,} || :

%files -f .mfiles
%doc KEYS build/docs/* readme.html
%doc %{_javadocdir}/%{name}
%license LICENSE.txt NOTICE.txt
%{_datadir}/%{name}

%files xsltc -f .mfiles-xsltc
%license LICENSE.txt NOTICE.txt


%changelog
* Tue Jul 11 2023 yaoxin <yao_xin001@hoperun.com> - 0:2.7.2-1
- Update to 2.7.2

* Tue Dec 3 2019 huyan <hu.huyan@huawei.com> - 0:2.7.1-39
- Package Initialization
