/*
 * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you 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 org.wso2.carbon.identity.application.common.util;

/*
 * This class validates special characters to avoid any XSS vulnerabilities.
 */
public class CharacterEncoder {

    private CharacterEncoder(){
    }

    public static String getSafeText(String text) {

        String tmptext1=null;
        String tmptext2=null;
        if (text== null) {
            return text;
        }
        tmptext1 = text.trim();
        if (tmptext1.indexOf('<') > -1) {
            tmptext2 = tmptext1.replaceAll("<", "&lt;");
        }
        if (tmptext1.indexOf('>') > -1) {
            tmptext2 = tmptext1.replaceAll(">", "&gt;");
        }
        return tmptext2;
    }

}

@@ -1,13 +1,13 @@
 /*%0A
- 
 *
+ 
  Copyrig
@@ -72,21 +72,20 @@
 served.%0A
- 
 *%0A
- 
 *
+ 
  WSO2 In
@@ -139,18 +139,18 @@
 icense,%0A
- 
 *
+ 
  Version
@@ -204,18 +204,18 @@
  except%0A
- 
 *
+ 
  in comp
@@ -239,18 +239,18 @@
 icense.%0A
- 
 *
+ 
  You may
@@ -282,21 +282,22 @@
 ense at%0A
- 
 *%0A
- 
 *
+   
  http://
@@ -336,12 +336,10 @@
 2.0%0A
- 
 *%0A
- 
 * Un
@@ -395,17 +395,16 @@
 riting,%0A
- 
 * softwa
@@ -457,17 +457,16 @@
 d on an%0A
- 
 * %22AS IS
@@ -514,17 +514,16 @@
  OF ANY%0A
- 
 * KIND, 
@@ -574,17 +574,16 @@
 for the%0A
- 
 * specif
@@ -632,17 +632,16 @@
 tations%0A
- 
 * under 
@@ -657,13 +657,11 @@
 se.%0A
- 
 */%0A
-%0A
 pack
@@ -862,16 +862,17 @@
 ncoder()
+ 
 %7B%0A    %7D%0A
@@ -927,69 +927,8 @@
 t) %7B
-%0A%0A        String tmptext1=null;%0A        String tmptext2=null;
 %0A   
@@ -940,16 +940,17 @@
 if (text
+ 
 == null)
@@ -995,24 +995,20 @@
         
-tmp
 text
-1
  = text.
@@ -1023,32 +1023,28 @@
         if (
-tmp
 text
-1
 .indexOf('%3C'
@@ -1069,35 +1069,27 @@
     
-tmp
 text
-2
  = 
-tmp
 text
-1
 .replace
 All(
@@ -1084,19 +1084,16 @@
 .replace
-All
 (%22%3C%22, %22&
@@ -1121,24 +1121,20 @@
     if (
-tmp
 text
-1
 .indexOf
@@ -1163,35 +1163,27 @@
     
-tmp
 text
-2
  = 
-tmp
 text
-1
 .replace
 All(
@@ -1178,19 +1178,16 @@
 .replace
-All
 (%22%3E%22, %22&
@@ -1222,16 +1222,12 @@
 urn 
-tmp
 text
-2
 ;%0A  

fix encoder issues