/**
 * Copyright (C) 2009-2017 Simonsoft Nordic AB
 *
 * 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.
 */
package se.simonsoft.cms.indexing.xml.testconfig;

import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;

import com.google.inject.AbstractModule;
import com.google.inject.multibindings.MapBinder;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Names;

import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.s9api.Processor;
import se.simonsoft.cms.xmlsource.SaxonConfiguration;
import se.simonsoft.cms.xmlsource.handler.XmlSourceReader;
import se.simonsoft.cms.xmlsource.handler.s9api.XmlSourceReaderS9api;
import se.simonsoft.cms.xmlsource.transform.function.GetChecksum;
import se.simonsoft.cms.xmlsource.transform.function.GetLogicalId;
import se.simonsoft.cms.xmlsource.transform.function.GetPegRev;
import se.simonsoft.cms.xmlsource.transform.function.WithPegRev;

public class IndexingConfigXmlBase extends AbstractModule {

	@Override
	protected void configure() {
		bind(Processor.class).toProvider(SaxonConfiguration.class);
		Multibinder<ExtensionFunctionDefinition> transformerFunctions = Multibinder.newSetBinder(binder(), ExtensionFunctionDefinition.class);
		transformerFunctions.addBinding().to(GetChecksum.class);
		transformerFunctions.addBinding().to(GetPegRev.class);
		transformerFunctions.addBinding().to(WithPegRev.class);
		transformerFunctions.addBinding().to(GetLogicalId.class);
		bind(XmlSourceReader.class).to(XmlSourceReaderS9api.class);

		MapBinder<String, Source> sourceBinder = MapBinder.newMapBinder(binder(), String.class, Source.class);
		sourceBinder.addBinding("identity.xsl").toInstance(new StreamSource(this.getClass().getClassLoader().getResourceAsStream("se/simonsoft/cms/xmlsource/transform/identity.xsl")));
		sourceBinder.addBinding("reuse-normalize.xsl").toInstance(new StreamSource(this.getClass().getClassLoader().getResourceAsStream("se/simonsoft/cms/xmlsource/transform/reuse-normalize.xsl")));
		sourceBinder.addBinding("itemid-normalize.xsl").toInstance(new StreamSource(this.getClass().getClassLoader().getResourceAsStream("se/simonsoft/cms/xmlsource/transform/itemid-normalize.xsl")));
	
		sourceBinder.addBinding("xml-indexing-repositem.xsl").toInstance(new StreamSource(this.getClass().getClassLoader().getResourceAsStream("se/simonsoft/cms/indexing/xml/source/xml-indexing-repositem.xsl")));
		sourceBinder.addBinding("xml-indexing-reposxml.xsl").toInstance(new StreamSource(this.getClass().getClassLoader().getResourceAsStream("se/simonsoft/cms/indexing/xml/source/xml-indexing-reposxml.xsl")));

		
		// Set up test config defaults.
		bind(Integer.class).annotatedWith(Names.named("se.simonsoft.cms.indexing.xml.maxFilesize")).toInstance(new Integer(10 * 1048576));
		bind(String.class).annotatedWith(Names.named("se.simonsoft.cms.indexing.xml.suppressRidBefore")).toInstance(new String(""));
	}

}

@@ -676,170 +676,59 @@
 java
-x.xml.transform.Source;%0Aimport javax.xml.transform.stream.StreamSource;%0A%0Aimport com.google.inject.AbstractModule;%0Aimport com.google.inject.multibindings.MapBinder
+.util.Map;%0A%0Aimport com.google.inject.AbstractModule
 ;%0Aim
@@ -1088,16 +1088,235 @@
 rS9api;%0A
+import se.simonsoft.cms.xmlsource.transform.TransformStylesheetSource;%0Aimport se.simonsoft.cms.xmlsource.transform.TransformStylesheetSourceConfig;%0Aimport se.simonsoft.cms.xmlsource.transform.TransformerServiceFactory;%0A
 import s
@@ -2173,22 +2173,16 @@
 ;%0A%0A%09%09Map
-Binder
 %3CString,
@@ -2187,595 +2187,134 @@
 g, S
-ource%3E sourceBinder = MapBinder.newMapBinder(binder(), String.class, Source.class);%0A%09%09sourceBinder.addBinding(%22identity.xsl%22).toInstance(new StreamSource(this.getClass().getClassLoader().getResourceAsStream(%22se/simonsoft/cms/xmlsource/transform/identity.xsl%22)));%0A%09%09sourceBinder.addBinding(%22reuse-normalize.xsl%22).toInstance(new StreamSource(this.getClass().getClassLoader().getResourceAsStream(%22se/simonsoft/cms/xmlsource/transform/reuse-normalize.xsl%22)));%0A%09%09sourceBinder.addBinding(%22itemid-normalize.xsl%22).toInstance(new StreamSource(this.getClass().getClassLoader().getResourceAsStream(
+tring%3E stylesheets = TransformerServiceFactory.getStylesheetsForTestingMap();%0A%09%09stylesheets.put(%22xml-indexing-repositem.xsl%22, 
 %22se/
@@ -2331,81 +2331,75 @@
 cms/
+indexing/
 xml
+/
 source/
-transform/itemid-normalize
+xml-indexing-repositem
 .xsl%22)
-))
 ;%0A%09
-%0A%09%09sourceBinder.addBinding
+%09stylesheets.put
 (%22xm
@@ -2418,100 +2418,18 @@
 epos
-item
+xml
 .xsl%22
-).toInstance(new StreamSource(this.getClass().getClassLoader().getResourceAsStream(
+, 
 %22se/
@@ -2484,228 +2484,121 @@
 epos
-item
+xml
 .xsl%22)
-))
 ;%0A%09%09
-sourceBinder.addBinding(%22xml-indexing-reposxml.xsl%22).toInstance(new StreamSource(this.getClass().getClassLoader().getResourceAsStream(%22se/simonsoft/cms/indexing/xml/source/xml-indexing-reposxml.xsl%22)
+bind(TransformStylesheetSource.class).toInstance(new TransformStylesheetSourceConfig(stylesheets
 ));%0A
-%0A
 %09%09%0A%09

Update inject for cms-xmlsource 0.21.0-SNAPSHOT.