/*
 * oxAuth is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.xdi.oxauth.service;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.web.ServletContexts;
import org.xdi.oxauth.model.config.ConfigurationFactory;
import org.xdi.util.StringHelper;

/**
 * OxAuthConfigurationService
 *
 * @author Oleksiy Tataryn Date: 08.07.2014
 */
@Scope(ScopeType.STATELESS)
@Name("oxAuthConfigurationService")
@AutoCreate
public class OxAuthConfigurationService {

	public String getCssLocation(){
		if(StringHelper.isEmpty(ConfigurationFactory.instance().getConfiguration().getCssLocation())){
			String contextPath = ServletContexts.instance().getRequest().getContextPath();
			return contextPath + "/stylesheet";
		}else{
			return ConfigurationFactory.instance().getConfiguration().getCssLocation();
		}	
	}
	
	public String getJsLocation(){
		if(StringHelper.isEmpty(ConfigurationFactory.instance().getConfiguration().getJsLocation())){
			String contextPath = ServletContexts.instance().getRequest().getContextPath();
			return contextPath + "/js";
		}else{
			return ConfigurationFactory.instance().getConfiguration().getJsLocation();
		}	
	}
	
	public String getImgLocation(){
		if(StringHelper.isEmpty(ConfigurationFactory.instance().getConfiguration().getImgLocation())){
			String contextPath = ServletContexts.instance().getRequest().getContextPath();
			return contextPath + "/img";
		}else{
			return ConfigurationFactory.instance().getConfiguration().getImgLocation();
		}	
	}
	
}


@@ -251,16 +251,54 @@
 Create;%0A
+import org.jboss.seam.annotations.In;%0A
 import o
@@ -470,16 +470,73 @@
 actory;%0A
+import org.xdi.oxauth.model.configuration.Configuration;%0A
 import o
@@ -766,16 +766,109 @@
 vice %7B%0A%0A
+%09@In(value = %22#%7BconfigurationFactory.configuration%7D%22)%0A%09private Configuration configuration;%0A%0A
 %09public 
@@ -882,38 +882,40 @@
 getCssLocation()
+ 
 %7B%0A%09%09if
+ 
 (StringHelper.is
@@ -924,44 +924,9 @@
 pty(
-ConfigurationFactory.instance().getC
+c
 onfi
@@ -925,34 +925,32 @@
 ty(configuration
-()
 .getCssLocation(
@@ -944,32 +944,33 @@
 tCssLocation()))
+ 
 %7B%0A%09%09%09String cont
@@ -1075,28 +1075,30 @@
 esheet%22;%0A%09%09%7D
+ 
 else
+ 
 %7B%0A%09%09%09return 
@@ -1101,44 +1101,9 @@
 urn 
-ConfigurationFactory.instance().getC
+c
 onfi
@@ -1106,26 +1106,24 @@
 onfiguration
-()
 .getCssLocat
@@ -1124,38 +1124,36 @@
 sLocation();%0A%09%09%7D
-%09
 %0A%09%7D%0A
-%09
 %0A%09public String 
@@ -1159,38 +1159,40 @@
  getJsLocation()
+ 
 %7B%0A%09%09if
+ 
 (StringHelper.is
@@ -1201,44 +1201,9 @@
 pty(
-ConfigurationFactory.instance().getC
+c
 onfi
@@ -1202,34 +1202,32 @@
 ty(configuration
-()
 .getJsLocation()
@@ -1220,32 +1220,33 @@
 etJsLocation()))
+ 
 %7B%0A%09%09%09String cont
@@ -1343,28 +1343,30 @@
 + %22/js%22;%0A%09%09%7D
+ 
 else
+ 
 %7B%0A%09%09%09return 
@@ -1369,44 +1369,9 @@
 urn 
-ConfigurationFactory.instance().getC
+c
 onfi
@@ -1374,26 +1374,24 @@
 onfiguration
-()
 .getJsLocati
@@ -1399,22 +1399,20 @@
 n();%0A%09%09%7D
-%09
 %0A%09%7D%0A
-%09
 %0A%09public
@@ -1435,22 +1435,24 @@
 cation()
+ 
 %7B%0A%09%09if
+ 
 (StringH
@@ -1469,44 +1469,9 @@
 pty(
-ConfigurationFactory.instance().getC
+c
 onfi
@@ -1470,34 +1470,32 @@
 ty(configuration
-()
 .getImgLocation(
@@ -1497,16 +1497,17 @@
 tion()))
+ 
 %7B%0A%09%09%09Str
@@ -1617,20 +1617,22 @@
 mg%22;%0A%09%09%7D
+ 
 else
+ 
 %7B%0A%09%09%09ret
@@ -1639,44 +1639,9 @@
 urn 
-ConfigurationFactory.instance().getC
+c
 onfi
@@ -1648,18 +1648,16 @@
 guration
-()
 .getImgL
@@ -1674,14 +1674,11 @@
 %0A%09%09%7D
-%09
 %0A%09%7D%0A
-%09
 %0A%7D%0A
-%0A

Fix OxAuthConfigurationService