Skip to Content.
Sympa Menu

idok-commit - [idok-commit] idok commit r74 - in trunk/java/ch/idok: common/impl/repository/svn common/repository qtgui

idok-commit AT lists.psi.ch

Subject: Commit emails of the iDok project

List archive

[idok-commit] idok commit r74 - in trunk/java/ch/idok: common/impl/repository/svn common/repository qtgui


Chronological Thread 
  • From: "Apache" <apache AT savannah.psi.ch>
  • To: idok-commit AT lists.psi.ch
  • Subject: [idok-commit] idok commit r74 - in trunk/java/ch/idok: common/impl/repository/svn common/repository qtgui
  • Date: Tue, 29 Apr 2008 14:06:38 +0200
  • List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
  • List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>

Author: huebner AT PSI.CH
Date: Tue Apr 29 14:06:38 2008
New Revision: 74

Log:
Added feature: Fetching of files via http + kerberos authentication

Modified:
trunk/java/ch/idok/common/impl/repository/svn/SvnRepository.java
trunk/java/ch/idok/common/repository/Repository.java
trunk/java/ch/idok/qtgui/PreviewWidget.java

Modified: trunk/java/ch/idok/common/impl/repository/svn/SvnRepository.java
==============================================================================
--- trunk/java/ch/idok/common/impl/repository/svn/SvnRepository.java
(original)
+++ trunk/java/ch/idok/common/impl/repository/svn/SvnRepository.java Tue
Apr 29 14:06:38 2008
@@ -19,6 +19,7 @@

package ch.idok.common.impl.repository.svn;

+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -53,6 +54,7 @@
import org.tmatesoft.svn.core.SVNLogEntryPath;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.SVNURL;
+import org.tmatesoft.svn.core.internal.io.dav.http.IHTTPConnection;
import org.tmatesoft.svn.core.io.ISVNEditor;
import org.tmatesoft.svn.core.io.ISVNLockHandler;
import org.tmatesoft.svn.core.io.SVNRepository;
@@ -62,6 +64,7 @@
import ch.idok.common.config.Setup;
import ch.idok.common.errorhandling.DmsException;
import ch.idok.common.errorhandling.ErrorType;
+import
ch.idok.common.impl.repository.svn.kerberized.DmsHTTPConnectionFactory;
import ch.idok.common.repository.DocumentId;
import ch.idok.common.repository.DocumentVersion;
import ch.idok.common.repository.PathType;
@@ -109,7 +112,27 @@
SVNRepository getSVNRepository() {
return repository_;
}
-
+
+ /** @see
common.repository.Repository.getFileOverHttp(ch.idok.common.repository.REpository
,java.lang.String) */
+ @Override
+ public ByteArrayOutputStream getFileOverHttp(Repository
currentRepository, RepositoryPath repositoryPath, String HttpRequest)
+ throws DmsException {
+
+ Repository repo = currentRepository;
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ DmsHTTPConnectionFactory f = new DmsHTTPConnectionFactory();
+ IHTTPConnection myHttpConnection;
+ try {
+ myHttpConnection =
f.createHTTPConnection(((SvnRepository)repo).repository_);
+ SVNErrorMessage context =
SVNErrorMessage.create(SVNErrorCode.RA_DAV_REQUEST_FAILED, "GET request
failed for ''{0}''", repositoryPath);
+ myHttpConnection.request("GET", HttpRequest, null,
(StringBuffer) null, 200, 226, outStream, null, context);
+ } catch (SVNException e) {
+ e.printStackTrace();
+ }
+ return outStream;
+ }
+
+
/** @see common.repository.Repository.getPathType() */
public PathType getPathType(DocumentId documentId, DocumentVersion
version)
throws DmsException {
@@ -1142,4 +1165,6 @@
}
}

+
+
}

Modified: trunk/java/ch/idok/common/repository/Repository.java
==============================================================================
--- trunk/java/ch/idok/common/repository/Repository.java (original)
+++ trunk/java/ch/idok/common/repository/Repository.java Tue Apr 29
14:06:38 2008
@@ -19,11 +19,18 @@

package ch.idok.common.repository;

+import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.net.URI;
import java.util.Map;

+import org.tmatesoft.svn.core.SVNErrorCode;
+import org.tmatesoft.svn.core.SVNErrorMessage;
+import org.tmatesoft.svn.core.internal.io.dav.http.IHTTPConnection;
+
import ch.idok.common.errorhandling.DmsException;
+import ch.idok.common.impl.repository.svn.SvnRepository;
+import
ch.idok.common.impl.repository.svn.kerberized.DmsHTTPConnectionFactory;

/**
* @brief An object of type Repository encapsulates one document repository.
@@ -39,6 +46,20 @@
public interface Repository {

/**
+ * @brief Retrieve a file from the repository via Http
+ *
+ * @param currentRepository
+ * The repository from which the file is retrieved.
+ * @param HttpRequest
+ * The String representing the get request.
+ * @return The ByteArrayOutputStream of the file. .
+ * @throws DmsException
+ * If the document path cannot be retrieved.
+ */
+ ByteArrayOutputStream getFileOverHttp (Repository currentRepository,
RepositoryPath repositoryPath, String HttpRequest)
+ throws DmsException;
+
+ /**
* @brief Retrieve the repository path for a specific version of a
document.
*
* @param docId

Modified: trunk/java/ch/idok/qtgui/PreviewWidget.java
==============================================================================
--- trunk/java/ch/idok/qtgui/PreviewWidget.java (original)
+++ trunk/java/ch/idok/qtgui/PreviewWidget.java Tue Apr 29 14:06:38 2008
@@ -21,14 +21,19 @@

import java.awt.Rectangle;
import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.RandomAccessFile;
+import java.net.Authenticator;
+import java.net.HttpURLConnection;
+import java.net.PasswordAuthentication;
+import java.net.URL;
+import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
@@ -36,9 +41,17 @@

import javax.imageio.ImageIO;

+import org.tmatesoft.svn.core.SVNErrorCode;
+import org.tmatesoft.svn.core.SVNURL;
+import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
+import org.tmatesoft.svn.core.internal.io.dav.http.IHTTPConnection;
+import org.tmatesoft.svn.core.SVNErrorMessage;
+
import ch.idok.common.errorhandling.DmsException;
+import ch.idok.common.repository.Repository;
import ch.idok.common.repository.RepositoryPath;

+
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
import com.trolltech.qt.core.QByteArray;
@@ -64,6 +77,11 @@
import com.trolltech.qt.gui.QSpinBox;
import com.trolltech.qt.gui.QWidget;

+import
ch.idok.common.impl.repository.svn.kerberized.DmsHTTPConnectionFactory;
+import ch.idok.common.impl.repository.svn.kerberized.HTTPKerb5Authentication;
+import ch.idok.common.impl.repository.svn.SvnRepository;
+//import ch.idok.common.impl.repository.svn.kerberized.HTTPConnection;
+
/**
* Previews contents of a single file, both images and text are supported
*/
@@ -104,6 +122,8 @@
private static List<String> imageFilters_;

private RepositoryPath repPath_;
+
+ private RepositoryController repoCon_;

private File tempPageFile_ = null;

@@ -193,6 +213,7 @@
public void setDmsContents(RepositoryController repoC,
RepositoryPath repPath) {
repPath_ = repPath;
+ repoCon_ = repoC;
try {
FileOutputStream os = null;
File tempFile = File.createTempFile("lastViewedFile", "");
@@ -222,6 +243,7 @@
int pos = name.lastIndexOf(".");
String ext = name.substring(pos + 1, pos + 4).toLowerCase();
if (imageFilters_.contains(ext)) {
+ //Should contain: bmp,pbm,pgm,png,ppm,xbm,xpm
previewImage();
pdfPageSpinBox_.hide();
} else if (ext.equals("txt") | ext.equals("htm") | ext.equals("xml")
@@ -256,45 +278,256 @@
| ext.equals("doc")| ext.equals("wpd")| ext.equals("ods")
| ext.equals("sxc")| ext.equals("xls")| ext.equals("csv")
| ext.equals("tsv")| ext.equals("odp")| ext.equals("sxi")
- | ext.equals("ppt")| ext.equals("jpg")| ext.equals("gif")
- | ext.equals("tif")) {
+ | ext.equals("ppt")) {
try {
QTime time = new QTime();
int convertTime = 0;
int displayTime = 0;
time.start();
- File file = new File(fileName_);
- RandomAccessFile randomInputAccessFile = new
RandomAccessFile(file, "r");
- byte[] byteInputArray = new
byte[(int)randomInputAccessFile.length()];
- randomInputAccessFile.read(byteInputArray);
- InputStream inStream = new
ByteArrayInputStream(byteInputArray);
- ByteArrayOutputStream outStream = new
ByteArrayOutputStream();
- Convert.convert(inStream,ext,outStream);
- convertTime = time.restart();
- System.out.println("Conversion time: "+ convertTime
+ " ms");
- ByteBuffer outBuffer =
ByteBuffer.wrap(outStream.toByteArray());
- pdfFile_ = new PDFFile(outBuffer);
- numPages_ = pdfFile_.getNumPages();
- pictureArray = new QImage[numPages_];
- pdfPageSpinBox_.setRange(1, numPages_);
- previewPdfFile(1);
- pdfPageSpinBox_.show();
- pdfPageSpinBox_.setValue(1);
- displayTime = time.elapsed();
- System.out.println("Display time: "+ displayTime+ "
ms");
- System.out.println("Conversion+Display= "+
(convertTime+displayTime) + " ms");
+ if(fileName_.startsWith("/tmp/lastViewedFile")){
+ ByteArrayOutputStream outStream = new
ByteArrayOutputStream();
+ outStream =
repoCon_.getCurrentRepo().getFileOverHttp(repoCon_.getCurrentRepo(),
repPath_, repPath_.getRelativeFilesystemPath() + "?pdf");
+ ByteBuffer outBuffer =
ByteBuffer.wrap(outStream.toByteArray());
+ pdfFile_ = new PDFFile(outBuffer);
+ numPages_ = pdfFile_.getNumPages();
+ pictureArray = new QImage[numPages_];
+ pdfPageSpinBox_.setRange(1, numPages_);
+ previewPdfFile(1);
+ pdfPageSpinBox_.show();
+ pdfPageSpinBox_.setValue(1);
+ displayTime = time.elapsed();
+ System.out.println("Display time: "+
displayTime+ " ms");
+ System.out.println("Conversion+Display= "+
(convertTime+displayTime) + " ms");
+ }else{
+ textView_.setText("<b> Sorry, preview of this
file type on a local drive is not yet supported </b>");
+ enableTextView();
+ }
} catch (Exception e) {
QMessageBox.warning(null, tr("iDok Warning"),
tr("General PDF decoding problem:") +
e.getMessage());
}

+ } else if (ext.equals("jpg")| ext.equals("gif")| ext.equals("tif")|
ext.equals("svg")) {
+ try {
+ QTime time = new QTime();
+ int convertTime = 0;
+ int displayTime = 0;
+ time.start();
+ if(fileName_.startsWith("/tmp/lastViewedFile")){
+ ByteArrayOutputStream outStream = new
ByteArrayOutputStream();
+ outStream =
repoCon_.getCurrentRepo().getFileOverHttp(repoCon_.getCurrentRepo(),
repPath_, repPath_.getRelativeFilesystemPath() + "?png");
+ byte[] buf = outStream.toByteArray();
+ QPixmap pixMap = new QPixmap();
+ pixMap.loadFromData(buf);
+ QImage image = pixMap.toImage();
+ imageView_.setImage(image);
+ enableImageView();
+ pdfPageSpinBox_.hide();
+ }else{
+ textView_.setText("<b> Sorry, preview of this file
type on a local drive is not yet supported </b>");
+ enableTextView();
+ }
+ } catch (Exception e) {
+ QMessageBox.warning(null, tr("iDok Warning"),
+ tr("General PDF decoding problem:") +
e.getMessage());
+ }
+

- } else {
+ } else if (ext.equals("svg")) {
+ try {
+ QTime time = new QTime();
+ int convertTime = 0;
+ int displayTime = 0;
+ time.start();
+ if(fileName_.startsWith("/tmp/lastViewedFile")){
+ ByteArrayOutputStream outStream = new
ByteArrayOutputStream();
+ outStream =
repoCon_.getCurrentRepo().getFileOverHttp(repoCon_.getCurrentRepo(),
repPath_, repPath_.getRelativeFilesystemPath() + "?png");
+ byte[] buf = outStream.toByteArray();
+ QPixmap pixMap = new QPixmap();
+ pixMap.loadFromData(buf);
+ QImage image = pixMap.toImage();
+ imageView_.setImage(image);
+ enableImageView();
+ pdfPageSpinBox_.hide();
+ }else{
+ textView_.setText("<b> Sorry, preview of this file
type on a local drive is not yet supported </b>");
+ enableTextView();
+ }
+ } catch (Exception e) {
+ QMessageBox.warning(null, tr("iDok Warning"),
+ tr("General PDF decoding problem:") + e.getMessage());
+ }
+
+ }else{
textView_
- .setText("<b> Sorry, preview not yet supported </b> <br>
(Doubleclick on document to start external viewer)");
+ .setText("<b> Sorry, preview of this file type is not
yet supported </b> <br> (Doubleclick on document to start external viewer)");
enableTextView();
}
}
+
+
+ static class MyAuthenticator extends Authenticator {
+
+ static final String kuser =
GuiClientHandler.getInstance().getCredentials().getUsername(); // your
account name
+ static final char[] kpass =
GuiClientHandler.getInstance().getCredentials().getPassword();; // your
password for the account
+ public PasswordAuthentication getPasswordAuthentication() {
+ System.err.println("Feeding username and password for " +
getRequestingScheme());
+ return (new PasswordAuthentication(kuser, kpass));
+ }
+ }
+
+
+ static class HTTPConnection {
+
+
+// public byte[] get(String file) throws IOException {
+// byte[] bytes = null;
+// try {
+// Authenticator.setDefault(new MyAuthenticator());
+// // Put a valid url here
+// URL url = new URL(file);
+// URLConnection con = url.openConnection();
+// InputStream stream = con.getInputStream();
+// final int length = con.getContentLength( );
+// final int buflen = Math.max( 1024, Math.max( length,
stream.available() ) );
+// byte[] buf = new byte[buflen];;
+// for ( int nRead = stream.read(buf); nRead != -1; nRead =
stream.read(buf) ) {
+// if ( bytes == null ) {
+// bytes = buf;
+// buf = new byte[buflen];
+// continue;
+// }
+// final byte[] newBytes = new byte[ bytes.length + nRead ];
+// System.arraycopy( bytes, 0, newBytes, 0, bytes.length );
+// System.arraycopy( buf, 0, newBytes, bytes.length, nRead
);
+// bytes = newBytes;
+// }
+// if ( charset == null )
+// return bytes;
+// try {
+// return new String( bytes, charset );
+// }
+// catch ( java.io.UnsupportedEncodingException e ) { }
+// return bytes;
+//
+// }
+ // Saved response.
+ private java.util.Map<String,java.util.List<String>> responseHeader =
null;
+ private java.net.URL responseURL = null;
+ private int responseCode = -1;
+ private String MIMEtype = null;
+ private String charset = null;
+ private Object content = null;
+
+ /** Open a web file.
+ * @return */
+ public void webFile( String urlString )
+ throws java.net.MalformedURLException, java.io.IOException {
+ Authenticator.setDefault(new MyAuthenticator());
+ // Open a URL connection.
+ final URL url = new java.net.URL(urlString);
+ final URLConnection uconn = url.openConnection();
+ if ( !(uconn instanceof HttpURLConnection) )
+ throw new java.lang.IllegalArgumentException(
+ "URL protocol must be HTTP." );
+ final HttpURLConnection conn = (HttpURLConnection)uconn;
+
+ // Set up a request.
+ conn.setConnectTimeout(10000); // 10 sec
+ conn.setReadTimeout(10000); // 10 sec
+ conn.setInstanceFollowRedirects( true );
+ conn.setRequestProperty( "User-agent", "spider" );
+
+ // Send the request.
+ conn.connect( );
+
+ // Get the response.
+ responseHeader = conn.getHeaderFields();
+ responseCode = conn.getResponseCode();
+ responseURL = conn.getURL();
+ final int length = conn.getContentLength();
+ final String type = conn.getContentType();
+ if ( type != null ) {
+ final String[] parts = type.split(";");
+ MIMEtype = parts[0].trim();
+ for ( int i = 1; i < parts.length && charset == null; i++ ) {
+ final String t = parts[i].trim();
+ final int index = t.toLowerCase().indexOf( "charset=" );
+ if ( index != -1 )
+ charset = t.substring( index+8 );
+ }
+ }
+
+ // Get the content.
+ final InputStream stream = conn.getErrorStream( );
+ if ( stream != null )
+ content = readStream( length, stream );
+ else if ( (content = conn.getContent()) != null &&
+ content instanceof InputStream )
+ content = readStream( length, (InputStream)content );
+ conn.disconnect();
+ }
+
+ /** Read stream bytes and transcode. */
+ private Object readStream( int length, java.io.InputStream stream )
+ throws java.io.IOException {
+ final int buflen = Math.max( 1024, Math.max( length,
stream.available() ) );
+ byte[] buf = new byte[buflen];;
+ byte[] bytes = null;
+
+ for ( int nRead = stream.read(buf); nRead != -1; nRead =
stream.read(buf) ) {
+ if ( bytes == null ) {
+ bytes = buf;
+ buf = new byte[buflen];
+ continue;
+ }
+ final byte[] newBytes = new byte[ bytes.length + nRead ];
+ System.arraycopy( bytes, 0, newBytes, 0, bytes.length );
+ System.arraycopy( buf, 0, newBytes, bytes.length, nRead );
+ bytes = newBytes;
+ }
+
+ if ( charset == null )
+ return bytes;
+ try {
+ return new String( bytes, charset );
+ }
+ catch ( java.io.UnsupportedEncodingException e ) { }
+ return bytes;
+ }
+
+ /** Get the content. */
+ public Object getContent() {
+ return content;
+ }
+
+ /** Get the response code. */
+ public int getResponseCode() {
+ return responseCode;
+ }
+
+ /** Get the response header. */
+ public java.util.Map<String,java.util.List<String>> getHeaderFields( )
{
+ return responseHeader;
+ }
+
+ /** Get the URL of the received page. */
+ public java.net.URL getURL() {
+ return responseURL;
+ }
+
+ /** Get the MIME type. */
+ public String getMIMEType() {
+ return MIMEtype;
+ }
+
+ /** Get the content. */
+ public byte[] getByteArray() {
+ return (byte[])content;
+ }
+
+
+ }

private void previewImage() {
image_ = new QImage(fileName_);



  • [idok-commit] idok commit r74 - in trunk/java/ch/idok: common/impl/repository/svn common/repository qtgui, Apache, 04/29/2008

Archive powered by MHonArc 2.6.19.

Top of Page