From 8daf40d0ce102c7e76da74c7cecf19fd05eb0377 Mon Sep 17 00:00:00 2001 From: Thomas Andraschko Date: Thu, 27 Jul 2023 13:41:04 +0200 Subject: [PATCH] unused classes --- .../view/HttpServletResponseSwitch.java | 151 ---------- .../apache/myfaces/view/ResponseSwitch.java | 39 --- .../myfaces/view/ServletResponseSwitch.java | 149 ---------- .../view/ServletViewResponseWrapper.java | 265 ------------------ .../myfaces/view/SwitchableOutputStream.java | 107 ------- .../apache/myfaces/view/SwitchableWriter.java | 131 --------- 6 files changed, 842 deletions(-) delete mode 100644 impl/src/main/java/org/apache/myfaces/view/HttpServletResponseSwitch.java delete mode 100644 impl/src/main/java/org/apache/myfaces/view/ResponseSwitch.java delete mode 100644 impl/src/main/java/org/apache/myfaces/view/ServletResponseSwitch.java delete mode 100644 impl/src/main/java/org/apache/myfaces/view/ServletViewResponseWrapper.java delete mode 100644 impl/src/main/java/org/apache/myfaces/view/SwitchableOutputStream.java delete mode 100644 impl/src/main/java/org/apache/myfaces/view/SwitchableWriter.java diff --git a/impl/src/main/java/org/apache/myfaces/view/HttpServletResponseSwitch.java b/impl/src/main/java/org/apache/myfaces/view/HttpServletResponseSwitch.java deleted file mode 100644 index c09a92b148..0000000000 --- a/impl/src/main/java/org/apache/myfaces/view/HttpServletResponseSwitch.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.myfaces.view; - -import java.io.IOException; -import java.io.PrintWriter; - -import jakarta.servlet.ServletOutputStream; -import jakarta.servlet.ServletResponse; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.servlet.http.HttpServletResponseWrapper; - -/** - * Implementation of a switching response wrapper to turn - * output on and off according to the Faces spec 2.0. - *

- * Implemented as HttpServletResponseWrapper, - * so that the switching does not interfere with methods that - * expect a HttpServletResponse when invoking ExternalContext.getResponse().

- */ -public class HttpServletResponseSwitch extends HttpServletResponseWrapper implements ResponseSwitch -{ - private PrintWriter _switchableWriter; - private SwitchableOutputStream _switchableOutputStream; - private boolean _enabled = true; - - public HttpServletResponseSwitch(HttpServletResponse response) - { - super(response); - } - - /** - * Enables or disables the Response's Writer and OutputStream. - * @param enabled - */ - @Override - public void setEnabled(boolean enabled) - { - _enabled = enabled; - } - - /** - * Are the Response's Writer and OutputStream currently enabled? - * @return - */ - @Override - public boolean isEnabled() - { - return _enabled; - } - - - @Override - public int getBufferSize() - { - if (isEnabled()) - { - return super.getBufferSize(); - } - return 0; - } - - @Override - public boolean isCommitted() - { - if (isEnabled()) - { - return super.isCommitted(); - } - return false; - } - - @Override - public void reset() - { - if (isEnabled()) - { - super.reset(); - } - } - - @Override - public void resetBuffer() - { - if (isEnabled()) - { - super.resetBuffer(); - } - } - - @Override - public void flushBuffer() throws IOException - { - if (isEnabled()) - { - super.flushBuffer(); - } - } - - @Override - public void setResponse(ServletResponse response) - { - // only change the response if it is not the same object - if (response instanceof HttpServletResponse && response != getResponse()) - { - // our OutputStream and our Writer are not valid for the new response - _switchableOutputStream = null; - _switchableWriter = null; - - // set the new response - super.setResponse(response); - } - } - - @Override - public ServletOutputStream getOutputStream() throws IOException - { - if (_switchableOutputStream == null) - { - _switchableOutputStream = new SwitchableOutputStream(super.getOutputStream(), this); - } - return _switchableOutputStream; - } - - @Override - public PrintWriter getWriter() throws IOException - { - if (_switchableWriter == null) - { - _switchableWriter = new PrintWriter(new SwitchableWriter(super.getWriter(), this)); - } - return _switchableWriter; - } - -} diff --git a/impl/src/main/java/org/apache/myfaces/view/ResponseSwitch.java b/impl/src/main/java/org/apache/myfaces/view/ResponseSwitch.java deleted file mode 100644 index e2f2a1bf73..0000000000 --- a/impl/src/main/java/org/apache/myfaces/view/ResponseSwitch.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.myfaces.view; - -/** - * Responses which can be enabled or disabled implement this interface. - */ -public interface ResponseSwitch -{ - - /** - * Enables or disables the Response's Writer and OutputStream. - * @param enabled - */ - public void setEnabled(boolean enabled); - - /** - * Are the Response's Writer and OutputStream currently enabled? - * @return - */ - public boolean isEnabled(); - -} diff --git a/impl/src/main/java/org/apache/myfaces/view/ServletResponseSwitch.java b/impl/src/main/java/org/apache/myfaces/view/ServletResponseSwitch.java deleted file mode 100644 index 434742a73f..0000000000 --- a/impl/src/main/java/org/apache/myfaces/view/ServletResponseSwitch.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.myfaces.view; - -import java.io.IOException; -import java.io.PrintWriter; - -import jakarta.servlet.ServletOutputStream; -import jakarta.servlet.ServletResponse; -import jakarta.servlet.ServletResponseWrapper; - -/** - * Implementation of a switching response wrapper to turn - * output on and off according to the Faces spec 2.0. - *

- * Fall-back implementation of HttpServletResponseSwitch - * for non HttpServletResponses.

- */ -public class ServletResponseSwitch extends ServletResponseWrapper implements ResponseSwitch -{ - - private PrintWriter _switchableWriter; - private SwitchableOutputStream _switchableOutputStream; - private boolean _enabled = true; - - public ServletResponseSwitch(ServletResponse response) - { - super(response); - } - - /** - * Enables or disables the Response's Writer and OutputStream. - * @param enabled - */ - @Override - public void setEnabled(boolean enabled) - { - _enabled = enabled; - } - - /** - * Are the Response's Writer and OutputStream currently enabled? - * @return - */ - @Override - public boolean isEnabled() - { - return _enabled; - } - - @Override - public int getBufferSize() - { - if (isEnabled()) - { - return super.getBufferSize(); - } - return 0; - } - - @Override - public boolean isCommitted() - { - if (isEnabled()) - { - return super.isCommitted(); - } - return false; - } - - @Override - public void reset() - { - if (isEnabled()) - { - super.reset(); - } - } - - @Override - public void resetBuffer() - { - if (isEnabled()) - { - super.resetBuffer(); - } - } - - @Override - public void flushBuffer() throws IOException - { - if (isEnabled()) - { - super.flushBuffer(); - } - } - - @Override - public void setResponse(ServletResponse response) - { - // only change the response if it is not the same object - if (response != getResponse()) - { - // our OutputStream and our Writer are not valid for the new response - _switchableOutputStream = null; - _switchableWriter = null; - - // set the new response - super.setResponse(response); - } - } - - @Override - public ServletOutputStream getOutputStream() throws IOException - { - if (_switchableOutputStream == null) - { - _switchableOutputStream = new SwitchableOutputStream(super.getOutputStream(), this); - } - return _switchableOutputStream; - } - - @Override - public PrintWriter getWriter() throws IOException - { - if (_switchableWriter == null) - { - _switchableWriter = new PrintWriter(new SwitchableWriter(super.getWriter(), this)); - } - return _switchableWriter; - } - -} diff --git a/impl/src/main/java/org/apache/myfaces/view/ServletViewResponseWrapper.java b/impl/src/main/java/org/apache/myfaces/view/ServletViewResponseWrapper.java deleted file mode 100644 index b875f78b89..0000000000 --- a/impl/src/main/java/org/apache/myfaces/view/ServletViewResponseWrapper.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.myfaces.view; - -import jakarta.servlet.ServletOutputStream; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.servlet.http.HttpServletResponseWrapper; -import java.io.ByteArrayOutputStream; -import java.io.CharArrayWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.Writer; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import jakarta.servlet.WriteListener; - -/** - * @author Bruno Aranda (latest modification by $Author$) - * @version $Revision$ $Date$ - */ -public class ServletViewResponseWrapper extends HttpServletResponseWrapper implements ViewResponseWrapper -{ - private PrintWriter _writer; - private CharArrayWriter _charArrayWriter; - private int _status = HttpServletResponse.SC_OK; - private WrappedServletOutputStream _byteArrayWriter; - - public ServletViewResponseWrapper(HttpServletResponse httpServletResponse) - { - super(httpServletResponse); - } - - @Override - public void sendError(int status) throws IOException - { - super.sendError(status); - _status = status; - } - - @Override - public void sendError(int status, String errorMessage) throws IOException - { - super.sendError(status, errorMessage); - _status = status; - } - - @Override - public void setStatus(int status) - { - super.setStatus(status); - _status = status; - } - - @Override - public int getStatus() - { - return _status; - } - - public void flushToWrappedResponse() throws IOException - { - if (_charArrayWriter != null) - { - _charArrayWriter.writeTo(getResponse().getWriter()); - _charArrayWriter.reset(); - _writer.flush(); - } - else if (_byteArrayWriter != null) - { - // MYFACES-1955 cannot call getWriter() after getOutputStream() - // _byteArrayWriter is not null only if getOutputStream() was called - // before. This method is called from f:view to flush data before tag - // start, or if an error page is flushed after dispatch. - // A resource inside /faces/* (see MYFACES-1815) is handled on flushToWriter. - // If response.getOuputStream() was called before, an IllegalStateException - // is raised on response.getWriter(), so we should try through stream. - try - { - _byteArrayWriter.writeTo(getResponse().getWriter(), getResponse().getCharacterEncoding()); - } - catch (IllegalStateException e) - { - getResponse().getOutputStream().write(_byteArrayWriter.toByteArray()); - } - _byteArrayWriter.reset(); - _byteArrayWriter.flush(); - } - } - - @Override - public void flushToWriter(Writer writer,String encoding) throws IOException - { - if (_charArrayWriter != null) - { - _charArrayWriter.writeTo(writer); - _charArrayWriter.reset(); - _writer.flush(); - } - else if (_byteArrayWriter != null) - { - _byteArrayWriter.writeTo(writer,encoding); - _byteArrayWriter.reset(); - _byteArrayWriter.flush(); - } - writer.flush(); - } - - @Override - public ServletOutputStream getOutputStream() throws IOException - { - if (_charArrayWriter != null) - { - throw new IllegalStateException(); - } - if (_byteArrayWriter == null) - { - _byteArrayWriter = new WrappedServletOutputStream(); - } - return _byteArrayWriter; - } - - @Override - public PrintWriter getWriter() throws IOException - { - if (_byteArrayWriter != null) - { - throw new IllegalStateException(); - } - if (_writer == null) - { - _charArrayWriter = new CharArrayWriter(4096); - _writer = new PrintWriter(_charArrayWriter); - } - return _writer; - } - - @Override - public void reset() - { - if (_charArrayWriter != null) - { - _charArrayWriter.reset(); - } - } - - @Override - public String toString() - { - if (_charArrayWriter != null) - { - return _charArrayWriter.toString(); - } - return null; - } - - static class WrappedServletOutputStream extends ServletOutputStream - { - private WrappedByteArrayOutputStream baos; - - public WrappedServletOutputStream() - { - baos = new WrappedByteArrayOutputStream(1024); - } - - @Override - public void write(int i) throws IOException - { - baos.write(i); - } - - public byte[] toByteArray() - { - return baos.toByteArray(); - } - - /** - * Write the data of this stream to the writer, using - * the charset encoding supplied or if null the default charset. - * - * @param out - * @param encoding - * @throws IOException - */ - private void writeTo(Writer out, String encoding) throws IOException - { - //Get the charset based on the encoding or return the default if encoding == null - Charset charset = encoding == null - ? Charset.defaultCharset() - : Charset.forName(encoding); - - CharsetDecoder decoder = charset.newDecoder(); - CharBuffer decodedBuffer = decoder.decode( - ByteBuffer.wrap(baos.getInnerArray(), 0, baos.getInnerCount())); - if (decodedBuffer.hasArray()) - { - out.write(decodedBuffer.array()); - } - } - - public void reset() - { - baos.reset(); - } - - @Override - public boolean isReady() - { - return true; - } - - @Override - public void setWriteListener(WriteListener wl) - { - - } - - /** - * This Wrapper is used to provide additional methods to - * get the buf and count variables, to use it to decode - * in WrappedServletOutputStream.writeTo and avoid buffer - * duplication. - */ - static class WrappedByteArrayOutputStream extends ByteArrayOutputStream - { - public WrappedByteArrayOutputStream() - { - super(); - } - - public WrappedByteArrayOutputStream(int size) - { - super(size); - } - - private byte[] getInnerArray() - { - return buf; - } - - private int getInnerCount() - { - return count; - } - } - - } -} diff --git a/impl/src/main/java/org/apache/myfaces/view/SwitchableOutputStream.java b/impl/src/main/java/org/apache/myfaces/view/SwitchableOutputStream.java deleted file mode 100644 index 03ae397626..0000000000 --- a/impl/src/main/java/org/apache/myfaces/view/SwitchableOutputStream.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.myfaces.view; - -import java.io.IOException; - -import jakarta.servlet.ServletOutputStream; -import jakarta.servlet.WriteListener; - -/** - * Delegates the standard OutputStream-methods (close, flush, write) - * to the given ServletOutputStream, if the ResponseSwitch is enabled - */ -class SwitchableOutputStream extends ServletOutputStream -{ - - ServletOutputStream _delegate = null; - ResponseSwitch _responseSwitch = null; - - public SwitchableOutputStream(ServletOutputStream delegate, ResponseSwitch responseSwitch) - { - _delegate = delegate; - _responseSwitch = responseSwitch; - } - - @Override - public void close() throws IOException - { - if (_responseSwitch.isEnabled()) - { - _delegate.close(); - } - } - - @Override - public void flush() throws IOException - { - if (_responseSwitch.isEnabled()) - { - _delegate.flush(); - } - } - - @Override - public void write(byte[] b, int off, int len) throws IOException - { - if (_responseSwitch.isEnabled()) - { - _delegate.write(b, off, len); - } - } - - @Override - public void write(byte[] b) throws IOException - { - if (_responseSwitch.isEnabled()) - { - _delegate.write(b); - } - } - - @Override - public void write(int b) throws IOException - { - if (_responseSwitch.isEnabled()) - { - _delegate.write(b); - } - } - - @Override - public boolean isReady() - { - if (_responseSwitch.isEnabled()) - { - return _delegate.isReady(); - } - - return true; - } - - @Override - public void setWriteListener(WriteListener wl) - { - if (_responseSwitch.isEnabled()) - { - _delegate.setWriteListener(wl); - } - } - -} diff --git a/impl/src/main/java/org/apache/myfaces/view/SwitchableWriter.java b/impl/src/main/java/org/apache/myfaces/view/SwitchableWriter.java deleted file mode 100644 index cd449428a8..0000000000 --- a/impl/src/main/java/org/apache/myfaces/view/SwitchableWriter.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.myfaces.view; - -import java.io.IOException; -import java.io.Writer; - -/** - * Delegates the standard Writer-methods (append, close, flush, write) - * to the given Writer, if the ResponseSwitch is enabled - */ -class SwitchableWriter extends Writer -{ - Writer _delegate = null; - ResponseSwitch _responseSwitch = null; - - public SwitchableWriter(Writer delegate, ResponseSwitch responseSwitch) - { - _delegate = delegate; - _responseSwitch = responseSwitch; - } - - @Override - public void write(String s, int start, int end) throws IOException - { - if (_responseSwitch.isEnabled()) - { - _delegate.write(s, start, end); - } - } - - @Override - public void write(String s) throws IOException - { - if (_responseSwitch.isEnabled()) - { - _delegate.write(s); - } - } - - @Override - public void write(char[] c, int start, int end) throws IOException - { - if (_responseSwitch.isEnabled()) - { - _delegate.write(c, start, end); - } - } - - @Override - public void write(char[] c) throws IOException - { - if (_responseSwitch.isEnabled()) - { - _delegate.write(c); - } - } - - @Override - public void write(int i) throws IOException - { - if (_responseSwitch.isEnabled()) - { - _delegate.write(i); - } - } - - @Override - public void flush() throws IOException - { - if (_responseSwitch.isEnabled()) - { - _delegate.flush(); - } - } - - @Override - public void close() throws IOException - { - if (_responseSwitch.isEnabled()) - { - _delegate.close(); - } - } - - @Override - public Writer append(char c) throws IOException - { - if (_responseSwitch.isEnabled()) - { - return _delegate.append(c); - } - return this; - } - - @Override - public Writer append(CharSequence csq, int start, int end) throws IOException - { - if (_responseSwitch.isEnabled()) - { - return _delegate.append(csq, start, end); - } - return this; - } - - @Override - public Writer append(CharSequence csq) throws IOException - { - if (_responseSwitch.isEnabled()) - { - return _delegate.append(csq); - } - return this; - } -}