View Javadoc
1   /***********************************************************
2    * This place transforms \\uxxxx Javascript escape 
3    * stuff into normal unicode (utf-8 characters)
4    **/
5   
6   package emissary.transform;
7   
8   import emissary.core.Form;
9   import emissary.core.IBaseDataObject;
10  import emissary.place.ServiceProviderPlace;
11  import emissary.transform.decode.JavascriptEscape;
12  import emissary.util.DataUtil;
13  
14  import org.apache.commons.lang3.ArrayUtils;
15  
16  import java.io.IOException;
17  
18  import static emissary.core.constants.Configurations.OUTPUT_FORM;
19  
20  @Deprecated
21  public class JavascriptEscapePlace extends ServiceProviderPlace {
22  
23      /**
24       * Can be overridden from config file
25       */
26      private String outputForm = Form.UNKNOWN;
27  
28      /**
29       * Configure one with specified location
30       * 
31       * @param cfgInfo the name of the config file or resource
32       * @param dir the name of the controlling directory
33       * @param placeLoc the string name for this place
34       */
35      public JavascriptEscapePlace(String cfgInfo, String dir, String placeLoc) throws IOException {
36          super(cfgInfo, dir, placeLoc);
37          configurePlace();
38      }
39  
40      /**
41       * Configure one with default location
42       * 
43       * @param cfgInfo the name of the config file or resource
44       */
45      public JavascriptEscapePlace(String cfgInfo) throws IOException {
46          super(cfgInfo, "TestJavascriptEscapePlace.example.com:8001");
47          configurePlace();
48      }
49  
50      /**
51       * Constructor with default config
52       */
53      public JavascriptEscapePlace() throws IOException {
54          super();
55          configurePlace();
56      }
57  
58      /**
59       * Take care of special place configuration
60       */
61      protected void configurePlace() {
62          outputForm = configG.findStringEntry(OUTPUT_FORM, outputForm);
63      }
64  
65      /**
66       * Consume a dataObject and return a modified one.
67       */
68      @Override
69      public void process(IBaseDataObject d) {
70          if (DataUtil.isEmpty(d)) {
71              logger.debug("empty data");
72              return;
73          }
74          String incomingForm = d.currentForm();
75  
76          logger.debug("JavascriptEscapePlace just got a {}", incomingForm);
77  
78          byte[] newData = JavascriptEscape.unescape(d.data());
79  
80          if (ArrayUtils.isNotEmpty(newData)) {
81              d.setData(newData);
82  
83              if (outputForm != null) {
84                  d.setCurrentForm(outputForm);
85              }
86          } else {
87              logger.warn("error doing JavascriptEscape, unable to decode");
88              d.pushCurrentForm(Form.ERROR);
89          }
90      }
91  
92  
93  }