diff options
Diffstat (limited to 'mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku')
18 files changed, 0 insertions, 1158 deletions
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugOutputStream.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugOutputStream.java deleted file mode 100644 index 8516b76c..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugOutputStream.java +++ /dev/null @@ -1,48 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils; - -import java.io.ByteArrayOutputStream; -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -public class DebugOutputStream extends FilterOutputStream { - - private ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - - public DebugOutputStream(OutputStream out) { - super(out); - } - - @Override - public void write(byte[] b, int off, int len) throws IOException { - buffer.write(b, off, len); - super.write(b, off, len); - } - - @Override - public void write(int b) throws IOException { - buffer.write(b); - super.write(b); - } - - public byte[] getBufferedBytes() { - return buffer.toByteArray(); - } - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugReader.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugReader.java deleted file mode 100644 index cafe4a72..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugReader.java +++ /dev/null @@ -1,58 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils; - -import java.io.FilterReader; -import java.io.IOException; -import java.io.Reader; -import java.io.StringWriter; - -public class DebugReader extends FilterReader { - - private StringWriter buffer = new StringWriter(); - - public DebugReader(Reader in) { - super(in); - } - - public DebugReader(Reader in, String start) { - super(in); - buffer.write(start); - } - - @Override - public int read() throws IOException { - int c = super.read(); - if (c != -1) - buffer.write(c); - return c; - } - - @Override - public int read(char[] cbuf, int off, int len) throws IOException { - int l = super.read(cbuf, off, len); - if (l != -1 ) { - buffer.write(cbuf, off, l); - } - return l; - } - - public String getCachedString() { - return buffer.toString(); - } - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugWriter.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugWriter.java deleted file mode 100644 index 5566f927..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/DebugWriter.java +++ /dev/null @@ -1,55 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils; - -import java.io.FilterWriter; -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; - -public class DebugWriter extends FilterWriter { - - private Writer buffer = new StringWriter(); - - public DebugWriter(Writer out) { - super(out); - } - - @Override - public void write(char[] cbuf, int off, int len) throws IOException { - buffer.write(cbuf, off, len); - super.write(cbuf, off, len); - } - - @Override - public void write(String str, int off, int len) throws IOException { - buffer.write(str, off, len); - super.write(str, off, len); - } - - @Override - public void write(int c) throws IOException { - buffer.write(c); - super.write(c); - } - - public String getBufferedString() { - return buffer.toString(); - } - - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/HexDump.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/HexDump.java deleted file mode 100644 index 88d49bad..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/HexDump.java +++ /dev/null @@ -1,75 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-
-public class HexDump {
-
- public static String hexDump(InputStream is) throws IOException {
- StringWriter writer = new StringWriter();
- hexDump(is, writer);
- return writer.toString();
- }
-
- public static void hexDump(InputStream is, Writer writer) throws IOException {
- hexDump(is, writer, 16);
- }
-
- public static void hexDump(InputStream is, Writer writer, int chunkSize) throws IOException {
-
- byte[] chunk = new byte[chunkSize];
- long adr = 0;
- for (int l; (l = is.read(chunk)) != -1;) {
-
- writer.append(String.format("[%06x]", adr));
- for (int i = 0; i < l; i++) {
- if (i % 8 == 0) {
- writer.append(" ");
- } else {
- writer.append(":");
- }
- writer.append(Integer.toHexString((chunk[i] & 240) >> 4));
- writer.append(Integer.toHexString(chunk[i] & 15));
- }
-
- for (int i = 0; i < (chunkSize - l); i++) {
- writer.append(" ");
- }
-
- for (int i = 0; i < l; i++) {
- if (i % 8 == 0) {
- writer.append(" ");
- }
- if (chunk[i] > 31 && chunk[i] < 127) {
- writer.append((char) chunk[i]);
- } else {
- writer.append(".");
- }
- }
-
- writer.append("\n");
- adr += l;
-
- }
-
- }
-
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/NullOutputStream.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/NullOutputStream.java deleted file mode 100644 index edbd9c01..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/NullOutputStream.java +++ /dev/null @@ -1,10 +0,0 @@ -package at.gv.egiz.bku.utils;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-public class NullOutputStream extends OutputStream {
- @Override
- public void write(int b) throws IOException {
- }
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/StreamUtil.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/StreamUtil.java deleted file mode 100644 index a774df2b..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/StreamUtil.java +++ /dev/null @@ -1,101 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-
-public class StreamUtil {
-
- /**
- * Copies data. None of the streams will be closed.
- *
- * @param is
- * @param os
- * @throws IOException
- */
- public static void copyStream(InputStream is, OutputStream os)
- throws IOException {
- copyStream(is, os, 1024);
- }
-
- /**
- * Copies data. None of the streams will be closed.
- *
- * @param is
- * @param os
- * @throws IOException
- */
- public static void copyStream(InputStream is, OutputStream os, int bufferSize)
- throws IOException {
- byte[] buffer = new byte[bufferSize];
- copyStream(is, os, buffer);
- }
-
- /**
- * Copies data. None of the streams will be closed.
- *
- * @param is
- * @param os
- * @throws IOException
- */
- public static void copyStream(InputStream is, OutputStream os, byte[] buffer)
- throws IOException {
- for (int i = is.read(buffer); i > -1; i = is.read(buffer)) {
- os.write(buffer, 0, i);
- }
- }
-
- /**
- * Copies data. None of the streams will be closed.
- *
- * @param is
- * @param os
- * @throws IOException
- */
- public static void copyStream(Reader is, Writer os)
- throws IOException {
- copyStream(is, os, 1024);
- }
-
- /**
- * Copies data. None of the streams will be closed.
- *
- * @param is
- * @param os
- * @throws IOException
- */
- public static void copyStream(Reader is, Writer os, int bufferSize)
- throws IOException {
- char[] chars = new char[bufferSize];
- for (int i = is.read(chars); i > -1; i = is.read(chars)) {
- os.write(chars, 0, i);
- }
- }
-
-
- public static String asString(InputStream is, String charset)
- throws IOException {
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- copyStream(is, os);
- return new String(os.toByteArray(), charset);
- }
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingInputStream.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingInputStream.java deleted file mode 100644 index 28ef6b88..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingInputStream.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * - */ -package at.gv.egiz.bku.utils; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.CharBuffer; - -/** - * @author mcentner - * - */ -public class URLEncodingInputStream extends InputStream { - - private char[] buffer = new char[1]; - - private CharBuffer charBuffer = CharBuffer.wrap(buffer); - - protected Readable in; - - /** - * @param in - */ - public URLEncodingInputStream(Readable in) { - this.in = in; - } - - /* (non-Javadoc) - * @see java.io.InputStream#read() - */ - @Override - public int read() throws IOException { - charBuffer.rewind(); - if (in.read(charBuffer) == -1) { - return -1; - } - if (buffer[0] == '+') { - return ' '; - } else if (buffer[0] == '%') { - charBuffer.rewind(); - if (in.read(charBuffer) == -1) { - throw new IOException("Invalid URL encoding."); - } - int c1 = Character.digit(buffer[0], 16); - charBuffer.rewind(); - if (in.read(charBuffer) == -1) { - throw new IOException("Invalid URL encoding."); - } - int c2 = Character.digit(buffer[0], 16); - if (c1 == -1 || c2 == -1) { - throw new IOException("Invalid URL encoding."); - } - return ((c1 << 4) | c2); - } else { - return buffer[0]; - } - } - - - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingOutputStream.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingOutputStream.java deleted file mode 100644 index df42df6d..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingOutputStream.java +++ /dev/null @@ -1,134 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils; - -import java.io.IOException; -import java.io.OutputStream; -import java.nio.CharBuffer; -import java.util.BitSet; - -/** - * An URLEncoding <a - * href="http://tools.ietf.org/html/rfc3986#section-2.1">RFC3986, Section 2.1</a> - * OutputStream. - * - * @author mcentner - */ -public class URLEncodingOutputStream extends OutputStream { - - private static final int MAX_BUFFER_SIZE = 512; - - private static final BitSet UNRESERVED = new BitSet(256); - - static { - for (int i = '0'; i <= '9'; i++) { - UNRESERVED.set(i); - } - for (int i = 'a'; i <= 'z'; i++) { - UNRESERVED.set(i); - } - for (int i = 'A'; i <= 'Z'; i++) { - UNRESERVED.set(i); - } - UNRESERVED.set('-'); - UNRESERVED.set('_'); - UNRESERVED.set('.'); - UNRESERVED.set('*'); - UNRESERVED.set(' '); - } - - private static final char[] HEX = new char[] { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' - }; - - private char[] buf; - - protected Appendable out; - - /** - * Creates a new instance of this URLEncodingOutputStream that writes to the - * given Appendable. - * <p> - * Note: According to - * http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars the input - * for the {@link #write()} methods should be the UTF-8. - * </p> - * - * @param out - */ - public URLEncodingOutputStream(Appendable out) { - this.out = out; - } - - /* (non-Javadoc) - * @see java.io.OutputStream#write(int) - */ - @Override - public void write(int b) throws IOException { - b &= 0xFF; - if (UNRESERVED.get(b)) { - if (b == ' ') { - out.append('+'); - } else { - out.append((char) b); - } - } else { - out.append('%').append(HEX[b >>> 4]).append(HEX[b & 0xF]); - } - - } - - /* (non-Javadoc) - * @see java.io.OutputStream#write(byte[], int, int) - */ - @Override - public void write(byte[] b, int off, int len) throws IOException { - - // ensure a buffer at least double the size of end - start + 1 - // but max - int sz = Math.min(len + 1, MAX_BUFFER_SIZE); - if (buf == null || buf.length < sz) { - buf = new char[sz]; - } - - int bPos = 0; - for (int i = 0; i < len; i++) { - if (bPos + 3 > buf.length) { - // flush buffer - out.append(CharBuffer.wrap(buf, 0, bPos)); - bPos = 0; - } - int c = 0xFF & b[off + i]; - if (UNRESERVED.get(c)) { - if (c == ' ') { - buf[bPos++] = '+'; - } else { - buf[bPos++] = (char) c; - } - } else { - buf[bPos++] = '%'; - buf[bPos++] = HEX[c >>> 4]; - buf[bPos++] = HEX[c & 0xF]; - } - } - out.append(CharBuffer.wrap(buf, 0, bPos)); - - } - - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingWriter.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingWriter.java deleted file mode 100644 index 3ba90265..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/URLEncodingWriter.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed 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 at.gv.egiz.bku.utils; - -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.nio.charset.Charset; - -/** - * An URLEncoding <a - * href="http://tools.ietf.org/html/rfc3986#section-2.1">RFC3986, Section - * 2.1</a> Writer, that uses an UTF-8 encoding according to <a href - * ="http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars" - * >http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars</a> for - * writing non-ASCII characters. - * - * @author mcentner - */ -public class URLEncodingWriter extends Writer { - - protected OutputStreamWriter osw; - - public URLEncodingWriter(Appendable out) { - URLEncodingOutputStream urlEnc = new URLEncodingOutputStream(out); - osw = new OutputStreamWriter(urlEnc, Charset.forName("UTF-8")); - } - - @Override - public void close() throws IOException { - osw.close(); - } - - @Override - public void flush() throws IOException { - osw.flush(); - } - - @Override - public void write(char[] cbuf, int off, int len) throws IOException { - osw.write(cbuf, off, len); - } - -} diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/binding/Protocol.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/binding/Protocol.java deleted file mode 100644 index f0504697..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/binding/Protocol.java +++ /dev/null @@ -1,41 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils.binding;
-
-public enum Protocol {
- HTTP("http"), HTTPS("https");
-
- private String name;
-
- Protocol(String s) {
- name = s;
- }
-
- public String toString() {
- return name;
- }
-
- public static Protocol fromString(String protocol) {
- if (HTTP.toString().equalsIgnoreCase(protocol)) {
- return HTTP;
- }
- if (HTTPS.toString().equalsIgnoreCase(protocol)) {
- return HTTPS;
- }
- return null;
- }
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/FormDataURLSupplier.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/FormDataURLSupplier.java deleted file mode 100644 index 7272f1bb..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/FormDataURLSupplier.java +++ /dev/null @@ -1,26 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils.urldereferencer;
-
-import java.io.InputStream;
-
-public interface FormDataURLSupplier {
- public static final String PROPERTY_KEY_NAME = "at.gv.egiz.bku.util.urldereferencer.FormDataURLSupplier";
-
- public InputStream getFormData(String aParameterName);
- public String getFormDataContentType(String aParameterName);
-}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/HTTPURLProtocolHandlerImpl.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/HTTPURLProtocolHandlerImpl.java deleted file mode 100644 index dfe7d5e6..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/HTTPURLProtocolHandlerImpl.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed 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 at.gv.egiz.bku.utils.urldereferencer; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.security.InvalidParameterException; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSocketFactory; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -public class HTTPURLProtocolHandlerImpl implements URLProtocolHandler { - - private static Log log = LogFactory.getLog(HTTPURLProtocolHandlerImpl.class); - - public final static String HTTP = "http"; - public final static String HTTPS = "https"; - public final static String FORMDATA = "formdata"; - public final static String[] PROTOCOLS = { HTTP, HTTPS, FORMDATA }; - - private HostnameVerifier hostnameVerifier; - private SSLSocketFactory sslSocketFactory; - - public StreamData dereference(String aUrl, URLDereferencerContext aContext) - throws IOException { - String urlString = aUrl.toLowerCase().trim(); - if (urlString.startsWith(FORMDATA)) { - log.debug("Requested to dereference a formdata url"); - return dereferenceFormData(aUrl, aContext); - } - - URL url = new URL(aUrl); - if ((!HTTP.equalsIgnoreCase(url.getProtocol()) && (!HTTPS - .equalsIgnoreCase(url.getProtocol())))) { - throw new InvalidParameterException("Url " + aUrl + " not supported"); - } - return dereferenceHTTP(url); - } - - protected StreamData dereferenceHTTP(URL url) throws IOException { - log.debug("Dereferencing url: " + url); - HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); - if (httpConn instanceof HttpsURLConnection) { - log.trace("Detected ssl connection"); - HttpsURLConnection https = (HttpsURLConnection) httpConn; - if (sslSocketFactory != null) { - log.debug("Setting custom ssl socket factory for ssl connection"); - https.setSSLSocketFactory(sslSocketFactory); - } else { - log.trace("No custom socket factory set"); - } - if (hostnameVerifier != null) { - log.debug("Setting custom hostname verifier"); - https.setHostnameVerifier(hostnameVerifier); - } - } else { - log.trace("No secure connection with: "+url+ " class="+httpConn.getClass()); - } - log.trace("Successfully opened connection"); - return new StreamData(url.toString(), httpConn.getContentType(), httpConn - .getInputStream()); - } - - /** - * - * @param aUrl - * @param aContext - * @return - * @throws IOException if the data cannot be found or reading the stream failed. - */ - protected StreamData dereferenceFormData(String aUrl, - URLDereferencerContext aContext) throws IOException { - log.debug("Dereferencing formdata url: " + aUrl); - String[] parts = aUrl.split(":", 2); - FormDataURLSupplier supplier = (FormDataURLSupplier) aContext - .getProperty(FormDataURLSupplier.PROPERTY_KEY_NAME); - if (supplier == null) { - throw new NullPointerException( - "No FormdataUrlSupplier found in provided context"); - } - String contentType = supplier.getFormDataContentType(parts[1]); - InputStream is = supplier.getFormData(parts[1]); - if (is != null) { - return new StreamData(aUrl, contentType, is); - } - throw new IOException("Cannot dereference url: formdata not found"); - } - - @Override - public void setHostnameVerifier(HostnameVerifier hostnameVerifier) { - this.hostnameVerifier = hostnameVerifier; - } - - @Override - public void setSSLSocketFactory(SSLSocketFactory socketFactory) { - this.sslSocketFactory = socketFactory; - } - -}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/SimpleFormDataContextImpl.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/SimpleFormDataContextImpl.java deleted file mode 100644 index e9da9c81..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/SimpleFormDataContextImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils.urldereferencer;
-
-public class SimpleFormDataContextImpl implements URLDereferencerContext {
- protected FormDataURLSupplier formdata;
-
- /**
- *
- * @param formdata must not be null
- */
- public SimpleFormDataContextImpl(FormDataURLSupplier formdata) {
- if (formdata == null) {
- throw new NullPointerException("FormdataURLSupplier must not be null");
- }
- this.formdata = formdata;
- }
-
- @Override
- public Object getProperty(Object key) {
- if (key.equals(FormDataURLSupplier.PROPERTY_KEY_NAME)) {
- return formdata;
- }
- return null;
- }
-
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/StreamData.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/StreamData.java deleted file mode 100644 index 541c6878..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/StreamData.java +++ /dev/null @@ -1,61 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils.urldereferencer;
-
-import java.io.InputStream;
-
-/**
- * This class models the result when dereferencing an URL.
- *
- */
-public class StreamData {
-
- protected InputStream inputStream;
- protected String url;
- protected String contentType;
-
- /**
- *
- * @param url
- * @param contentType
- * @param stream must not be null
- */
- public StreamData(String url, String contentType, InputStream stream) {
- if (stream == null) {
- throw new NullPointerException("Parameter inputstream must not be null");
- }
- inputStream = stream;
- this.contentType = contentType;
- this.url = url;
- }
-
- public String getUrl() {
- return url;
- }
-
- /**
- *
- * @return the returned stream must be closed
- */
- public InputStream getStream() {
- return inputStream;
- }
-
- public String getContentType() {
- return contentType;
- }
-}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URIResolverAdapter.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URIResolverAdapter.java deleted file mode 100644 index 2d11010e..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URIResolverAdapter.java +++ /dev/null @@ -1,96 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils.urldereferencer;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import javax.xml.transform.Source;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.URIResolver;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Adapter to make the Urldereferencer work as URIResolver for
- * Stylesheettransforms.
- *
- * @author wbauer
- *
- */
-public class URIResolverAdapter implements URIResolver {
-
- private static Log log = LogFactory.getLog(URIResolverAdapter.class);
-
- private URLDereferencer urlDereferencer;
- private URLDereferencerContext ctx;
-
- /**
- *
- * @param deferecencer
- * must not be null
- * @param ctx may be null
- */
- public URIResolverAdapter(URLDereferencer deferecencer,
- URLDereferencerContext ctx) {
- if (deferecencer == null) {
- throw new NullPointerException("Urlderefencer must not be set to null");
- }
- this.urlDereferencer = deferecencer;
- this.ctx = ctx;
- }
-
- @Override
- public Source resolve(String href, String base) throws TransformerException {
- log.debug("Resolving href: "+href+" base: "+base);
- try {
- URI baseUri = null;
- URI hrefUri = new URI(href);
- if (base != null) {
- baseUri = new URI(base);
- }
- URI abs;
- if (baseUri != null) {
- abs = baseUri.resolve(hrefUri);
- } else {
- abs = hrefUri;
- }
- if (!abs.isAbsolute()) {
- throw new TransformerException("Only absolute URLs are supported");
- }
- return new StreamSource(urlDereferencer.dereference(abs.toString(), ctx)
- .getStream());
- } catch (URISyntaxException e) {
- throw new TransformerException("Cannot resolve URI: base:" + base
- + " href:" + href, e);
- } catch (IOException iox) {
- throw new TransformerException("Cannot resolve URI: base:" + base
- + " href:" + href, iox);
- }
- }
-
- public URLDereferencerContext getCtx() {
- return ctx;
- }
-
- public void setCtx(URLDereferencerContext ctx) {
- this.ctx = ctx;
- }
-}
diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLDereferencer.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLDereferencer.java deleted file mode 100644 index 7361ec26..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLDereferencer.java +++ /dev/null @@ -1,108 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils.urldereferencer;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.util.HashMap;
-import java.util.Map;
- -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLSocketFactory; -
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Class used to dereference (external URLs).
- *
- * @author wbauer
- *
- */
-public class URLDereferencer {
-
- private static Log log = LogFactory.getLog(URLDereferencer.class);
-
- private static URLDereferencer instance = new URLDereferencer();
-
- private Map<String, URLProtocolHandler> handlerMap = new HashMap<String, URLProtocolHandler>();
- - private HostnameVerifier hostnameVerifier; - private SSLSocketFactory sslSocketFactory; -
- private URLDereferencer() {
- registerHandlers();
- }
-
- /**
- *
- * @param aUrl
- * must not be null
- * @param aContext
- * @throws MalformedURLException
- * if the protocol is not supported - * @throws IOException if the url cannot be dereferenced (e.g. formdata not provided) - *
- */
- public StreamData dereference(String aUrl, URLDereferencerContext aContext)
- throws IOException {
- log.debug("Looking for handler for URL: " + aUrl);
- int i = aUrl.indexOf(":");
- if (i == -1) {
- throw new MalformedURLException("Invalid url: " + aUrl);
- }
- String protocol = aUrl.substring(0, i).toLowerCase().trim();
- URLProtocolHandler handler = handlerMap.get(protocol);
- if (handler == null) {
- throw new MalformedURLException("No handler for protocol: " + protocol
- + " found");
- } - handler.setHostnameVerifier(hostnameVerifier); - handler.setSSLSocketFactory(sslSocketFactory);
- return handler.dereference(aUrl, aContext);
- }
-
- /**
- * Registers a handler for a protocol.
- *
- * @param aProtocol
- * @param aHandler
- * may be set to null to disable this protocol
- */
- public void registerHandler(String aProtocol, URLProtocolHandler aHandler) {
- handlerMap.put(aProtocol.toLowerCase(), aHandler);
- }
-
- public static URLDereferencer getInstance() {
- return instance;
- }
-
- protected void registerHandlers() {
- URLProtocolHandler handler = new HTTPURLProtocolHandlerImpl();
- for (String proto : HTTPURLProtocolHandlerImpl.PROTOCOLS) {
- handlerMap.put(proto, handler);
- }
- } - - public void setHostnameVerifier(HostnameVerifier hostnameVerifier) { - this.hostnameVerifier = hostnameVerifier; - } - - public void setSSLSocketFactory(SSLSocketFactory socketFactory) { - this.sslSocketFactory = socketFactory; - }
-}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLDereferencerContext.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLDereferencerContext.java deleted file mode 100644 index 6befd5b3..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLDereferencerContext.java +++ /dev/null @@ -1,27 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils.urldereferencer;
-
-public interface URLDereferencerContext {
-
- /**
- *
- * @param key
- * @return may return null
- */
- public Object getProperty(Object key);
-}
\ No newline at end of file diff --git a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLProtocolHandler.java b/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLProtocolHandler.java deleted file mode 100644 index f886bd4e..00000000 --- a/mocca-1.2.11/utils/src/main/java/at/gv/egiz/bku/utils/urldereferencer/URLProtocolHandler.java +++ /dev/null @@ -1,39 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed 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 at.gv.egiz.bku.utils.urldereferencer;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
- -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLSocketFactory; -
-
-public interface URLProtocolHandler {
- /**
- *
- * @param aUrl
- * @param aContext
- * @return the streamdata of this url or null if the url cannot be resolved.
- * @throws IOException
- */
- public StreamData dereference(String aUrl, URLDereferencerContext aContext) throws IOException; - - public void setSSLSocketFactory(SSLSocketFactory socketFactory); - - public void setHostnameVerifier(HostnameVerifier hostnameVerifier);
-}
\ No newline at end of file |