View Javadoc
1   /*
2    * #%L
3    * wcm.io
4    * %%
5    * Copyright (C) 2019 wcm.io
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package io.wcm.wcm.ui.granite.pathfield.impl.util;
21  
22  import java.io.IOException;
23  import java.io.PrintWriter;
24  import java.io.Writer;
25  
26  import javax.servlet.jsp.JspWriter;
27  
28  import org.jetbrains.annotations.NotNull;
29  
30  /**
31   * Provide JspWriter wrapper because {@link com.adobe.granite.ui.components.ComponentHelper} tries
32   * to access the JspWriter from the dummy page context.
33   */
34  class JspWriterWrapper extends JspWriter {
35  
36    private final PrintWriter writer;
37  
38    JspWriterWrapper(@NotNull Writer writer) {
39      super(NO_BUFFER, true);
40      this.writer = new PrintWriter(writer);
41    }
42  
43    @Override
44    public void print(boolean value) throws IOException {
45      writer.print(value);
46    }
47  
48    @Override
49    public void print(char value) throws IOException {
50      writer.print(value);
51    }
52  
53    @Override
54    public void print(int value) throws IOException {
55      writer.print(value);
56    }
57  
58    @Override
59    public void print(long value) throws IOException {
60      writer.print(value);
61    }
62  
63    @Override
64    public void print(float value) throws IOException {
65      writer.print(value);
66    }
67  
68    @Override
69    public void print(double value) throws IOException {
70      writer.print(value);
71    }
72  
73    @Override
74    public void print(char[] value) throws IOException {
75      writer.print(value);
76    }
77  
78    @Override
79    public void print(String value) throws IOException {
80      writer.print(value);
81    }
82  
83    @Override
84    public void print(Object value) throws IOException {
85      writer.print(value);
86    }
87  
88    @Override
89    public void println() throws IOException {
90      writer.println();
91    }
92  
93    @Override
94    public void println(boolean value) throws IOException {
95      writer.println(value);
96    }
97  
98    @Override
99    public void println(char value) throws IOException {
100     writer.println(value);
101   }
102 
103   @Override
104   public void println(int value) throws IOException {
105     writer.println(value);
106   }
107 
108   @Override
109   public void println(long value) throws IOException {
110     writer.println(value);
111   }
112 
113   @Override
114   public void println(float value) throws IOException {
115     writer.println(value);
116   }
117 
118   @Override
119   public void println(double value) throws IOException {
120     writer.println(value);
121   }
122 
123   @Override
124   public void println(char[] value) throws IOException {
125     writer.println(value);
126   }
127 
128   @Override
129   public void println(String value) throws IOException {
130     writer.println(value);
131   }
132 
133   @Override
134   public void println(Object value) throws IOException {
135     writer.println(value);
136   }
137 
138   @Override
139   public void flush() throws IOException {
140     writer.flush();
141     throw new UnsupportedOperationException();
142   }
143 
144   @Override
145   public void close() throws IOException {
146     writer.close();
147   }
148 
149   @Override
150   public void write(char[] cbuf, int off, int len) throws IOException {
151     writer.write(cbuf, off, len);
152   }
153 
154   // --- unsupported methods ---
155 
156   @Override
157   public void newLine() throws IOException {
158     throw new UnsupportedOperationException();
159   }
160 
161   @Override
162   public void clear() throws IOException {
163     throw new UnsupportedOperationException();
164   }
165 
166   @Override
167   public void clearBuffer() throws IOException {
168     throw new UnsupportedOperationException();
169   }
170 
171   @Override
172   public int getRemaining() {
173     throw new UnsupportedOperationException();
174   }
175 
176 }