summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorguest <guest@f059d3a0-6783-47b7-97ff-1fe0bbf25129>2008-10-15 22:03:14 +0000
committerguest <guest@f059d3a0-6783-47b7-97ff-1fe0bbf25129>2008-10-15 22:03:14 +0000
commit3302ba62a4160ee9a430bb44cadfde44483e572c (patch)
treec38fa74eef6cc83dc5d6bed35d0260aa306dcece
parent08095c0674ceff4c8d1960758cb87a257897a452 (diff)
added unfunctional pgsql indexer files
git-svn-id: http://manut.eu/svn/yalp/trunk@16 f059d3a0-6783-47b7-97ff-1fe0bbf25129
-rwxr-xr-xidlj.sh2
-rw-r--r--src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/Browser.java160
-rw-r--r--src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileBrowser.java175
-rw-r--r--src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileFinder.java110
-rw-r--r--src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileInfoManager.java126
5 files changed, 572 insertions, 1 deletions
diff --git a/idlj.sh b/idlj.sh
index e7f3123..3e9b66c 100755
--- a/idlj.sh
+++ b/idlj.sh
@@ -1,4 +1,4 @@
#!/bin/bash
+# gentoo doesn't export path to idlj :-(
export PATH=$PATH:/opt/sun-jdk-1.6.0.07/bin
idlj -fall $@
-#/opt/ibm-java-i386-60/bin/idlj -fall $@
diff --git a/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/Browser.java b/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/Browser.java
new file mode 100644
index 0000000..2b2e65a
--- /dev/null
+++ b/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/Browser.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2006 Manuel Traut and Volker Dahnke
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors: Manuel Traut and Volker Dahnke
+ */
+
+package YalpClients.SwtClient.GUI;
+
+import YalpClients.*;
+import YalpClients.SwtClient.*;
+
+import YalpInterfaces.*;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+
+import java.util.LinkedList;
+
+/*
+ * Class Browser
+ *
+ * <em></em>
+ *
+ * @author Volker Dahnke / Manuel Traut
+ *
+ * @version 1 02-04-2006<br>
+ */
+public class Browser extends Composite{
+ private Composite parentComposite;
+ private Display display1;
+ private Shell shell;
+ private Model model;
+ private LinkedList<String> alreadyBrowsed;
+ private Tree tree;
+ private Button add;
+ private Button cancel;
+
+ Browser( Composite parent,
+ final Model model,
+ Display display,
+ Composite parentComposite,
+ int style )
+ {
+ super(parent, style);
+ this.parentComposite=parentComposite;
+ this.alreadyBrowsed = new LinkedList<String>();
+ this.model = model;
+ this.display1 = display;
+ this.shell = new Shell(this.display1,SWT.NONE);
+ this.setSize(300,400);
+ GridLayout gridLayout = new GridLayout();
+ this.shell.setLayout(gridLayout);
+ gridLayout.numColumns = 2;
+
+ GridData treeGrid = new GridData();
+ treeGrid.horizontalSpan = 2;
+ treeGrid.widthHint = 300;
+ treeGrid.heightHint = 400;
+ treeGrid.grabExcessHorizontalSpace = true;
+ treeGrid.grabExcessVerticalSpace = true;
+ treeGrid.horizontalAlignment = SWT.FILL;
+ treeGrid.verticalAlignment = SWT.FILL;
+
+ this.tree = new Tree(this.shell, SWT.SINGLE);
+ this.tree.setLayoutData(treeGrid);
+
+ TreeItem tmp;
+ /*
+ for(YalpFile aFile : model.getDir("/")){
+ tmp = new TreeItem(this.tree, SWT.NULL);
+ tmp.setText(aFile.name);
+ if(aFile.isDir) tmp.setImage(new Image(display1, "folder.gif"));
+ else tmp.setImage(new Image(display1, "yalpV2_klein.gif"));
+ }
+ */
+ this.tree.addSelectionListener (
+ new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ String path = getPath();
+ if(!alreadyBrowsed.contains(path)){
+ alreadyBrowsed.add(path);
+ TreeItem tmp;
+ /*
+ for(YalpFile aFile : model.getDir(path)){
+ tmp = new TreeItem(tree.getSelection()[0],SWT.NULL);
+ tmp.setText(aFile.name);
+ if(aFile.isDir) tmp.setImage(new Image(display1, "folder.gif"));
+ else tmp.setImage(new Image(display1, "yalpV2_klein.gif"));
+ tmp.getParentItem().setExpanded(true);
+ }
+ */
+ }
+ }
+ }
+ );
+
+ GridData buttonGrid1 = new GridData();
+ buttonGrid1.horizontalSpan = 1;
+
+ this.add = new Button(this.shell, SWT.PUSH);
+ this.add.setText("Indicate");
+ this.add.setLayoutData(buttonGrid1);
+ this.add.addSelectionListener(new SelectionAdapter(){
+ public void widgetSelected(SelectionEvent e){
+ // model.addDir(getPath());
+ parentEnable(true);
+ shell.setVisible(false);
+ }
+ });
+
+ GridData buttonGrid2 = new GridData();
+ buttonGrid2.horizontalSpan = 1;
+ buttonGrid2.horizontalAlignment = SWT.END;
+
+ this.cancel = new Button(this.shell, SWT.PUSH);
+ this.cancel.setText("Cancel");
+ this.cancel.setLayoutData(buttonGrid2);
+ this.cancel.addSelectionListener(new SelectionAdapter(){
+ public void widgetSelected(SelectionEvent e){
+ parentEnable(true);
+ shell.setVisible(false);
+ }
+ });
+ }
+
+ public void show(){
+ parentEnable(false);
+ Point size=this.getSize();
+ Rectangle parentRec=((Shell)this.parentComposite).getBounds();
+ Rectangle thisRec=this.shell.computeTrim(parentRec.x+(parentRec.width/2)-(size.x/2),parentRec.y+(parentRec.height/2)-(size.y/2),size.x,size.y);
+ shell.setBounds(thisRec);
+ shell.open();
+ while(!shell.isDisposed()){
+ if(!this.display1.readAndDispatch()) this.display1.sleep();
+ }
+ this.display1.dispose();
+ }
+
+ private String getPath(){
+ TreeItem actualItem = tree.getSelection()[0];
+ String path = "/"+tree.getSelection()[0].getText();
+ while(actualItem.getParentItem() != null){
+ actualItem = actualItem.getParentItem();
+ path = "/" + actualItem.getText() + path;
+ }
+ return path;
+ }
+ private void parentEnable(boolean bool){
+ parentComposite.setEnabled(bool);
+ }
+}
diff --git a/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileBrowser.java b/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileBrowser.java
new file mode 100644
index 0000000..2f2a3a5
--- /dev/null
+++ b/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileBrowser.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2006 Manuel Traut and Volker Dahnke
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors: Manuel Traut and Volker Dahnke
+ */
+
+package YalpServer;
+
+import java.util.ArrayList;
+import java.io.File;
+import java.io.Serializable;
+
+import YalpInterfaces.*;
+
+/*
+ * Class FileBrowser
+ *
+ * <em>each Admin Client has his own FileBrowser, to browse through the
+ * subDirectories of the as startDir defined Directory</em>
+ *
+ * @author Volker Dahnke / Manuel Traut
+ *
+ * @version 0.6 14-12-2005<br>
+ *
+ * @see client.GUI.Browser
+ */
+
+public class FileBrowser {
+
+ private File actualFile, startDir;
+ private String owner;
+ private String userName;
+ private ArrayList<YalpFile> fileList;
+
+ /* t.b.d. add some more types */
+ private String[] extensions = {".mp3",".mpg",".mpeg",".avi"};
+
+/*
+ * Constructor starts Browsing in startDir
+ *
+ * @param startdir
+ * directory which could be browser recursively
+ * @param owner
+ * of the Browser (IP of the Client)
+ * @param userName
+ * of the Admin using this browser
+ */
+
+ public FileBrowser(String startdir, String owner,String userName) {
+ this.owner = owner;
+ this.userName=userName;
+ this.actualFile = new File(startdir);
+ this.startDir = new File(startdir);
+ this.fileList = new ArrayList<YalpFile>();
+ }
+
+/*
+ * returns owner of the browser
+ *
+ * @return String
+ * owner
+ */
+
+ public String getOwner(){
+ return this.owner;
+ }
+
+/*
+ * returns user of the browser
+ *
+ * @return String
+ * user
+ */
+
+ public String getUserName(){
+ return this.userName;
+ }
+
+/*
+ * returns list of all files in actual Folder
+ * (none recursive)
+ *
+ * @return ArrayList<YalpFile>
+ * list of all files
+ */
+
+ public ArrayList<YalpFile> getFiles(){
+ return this.fileList;
+ }
+
+/*
+ * returns list of all files in actual Folder
+ * (recursive)
+ *
+ * @return ArrayList<YalpFile>
+ * list of all files
+ */
+
+ public ArrayList<File> findAll() {
+
+ System.out.println( "server.FileBrowser.findAll: lookin in - " +
+ this.actualFile.toString() );
+
+ FileFinder ff = new FileFinder(actualFile.getPath(), extensions);
+ return ff.getFiles();
+ }
+
+/*
+ * change actual Folder
+ *
+ * @param dirName
+ * String dir to change to
+ */
+
+ public void changeDir(String dirName) {
+
+ this.actualFile = new File(this.startDir+dirName);
+ this.fileList.clear();
+
+ if(actualFile.isDirectory()) {
+ for ( File aFile : this.actualFile.listFiles() ) {
+ /* add to fileList if extension is allowed or File is a Directory */
+ if (match(aFile.getName(), extensions) || aFile.isDirectory())
+ {
+ YalpFile tmp = new YalpFile();
+ tmp.name = aFile.getName();
+ tmp.isDir = aFile.isDirectory();
+ tmp.parent = aFile.getParent();
+ this.fileList.add( tmp );
+ }
+ }
+ }
+ }
+
+/*
+ * prints current directory out to console
+ *
+ * (for debugging)
+ */
+
+ public void printActualDir(){
+ for(YalpFile one : this.fileList){
+ if(one.isDir) System.out.print("+");
+ else System.out.print("|");
+ System.out.println(one.name);
+ }
+ }
+
+/*
+ * checks if file extension matches or not
+ *
+ * @param s
+ * fileName including Extension
+ * @param suffixes
+ * Array of allowed Extensions
+ * @return boolean
+ * true if yalp can handle this extension, else false
+ */
+
+ private static boolean match( String s, String suffixes[] ) {
+ for ( String suffix : suffixes ) {
+ int huhu = s.length();
+ int huhu2 = suffix.length();
+ int huhu3 = huhu - huhu2;
+ if ( s.length() >= suffix.length() &&
+ s.substring( huhu3, s.length()).equalsIgnoreCase(suffix) )
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileFinder.java b/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileFinder.java
new file mode 100644
index 0000000..2d6527c
--- /dev/null
+++ b/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileFinder.java
@@ -0,0 +1,110 @@
+/***********************************************************************
+ *
+ * Copyright (c) 2006 Manuel Traut and Volker Dahnke
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors: Manuel Traut and Volker Dahnke
+ *
+ ***********************************************************************/
+package YalpServer;
+
+import java.io.*;
+import java.util.*;
+
+/************************************************************************
+ *
+ * Class FileFinder
+ *
+ * <em>algorithm for scanning files recursively</em>
+ *
+ * @author Volker Dahnke / Manuel Traut
+ *
+ * @version 0.6 14-12-2005<br>
+ *
+ * @see FileBrowser
+ *
+ ************************************************************************/
+
+public class FileFinder
+{
+ private ArrayList<File> files;
+
+ /**
+ * Constructor: scans subdirectories of commited directory
+ * uses only files with allowed extensions
+ * @param start
+ * directory to scan
+ * @param extensions
+ * allowed extensions
+ */
+ public FileFinder( String start, String extensions[] ) {
+
+ this.files = new ArrayList<File>();
+ Stack<File> dirs = new Stack<File>();
+ File startdir = new File(start);
+
+ // push startdir to stack
+ if (startdir.isDirectory()) dirs.push(startdir);
+ // startdir is File
+ else {
+ if (match(startdir.getName(), extensions)) this.files.add(startdir);
+ return;
+ }
+ // for each dir on stack
+ while (dirs.size() > 0) {
+ // contents of dir on stack
+ for (File file : dirs.pop().listFiles()){
+ try {
+ // add subdirectory to stack
+ if (file.isDirectory()) dirs.push(file);
+ // if file is of correct filetype add it to filelist
+ else if (match(file.getName(), extensions)) this.files.add(file);
+ } catch (NullPointerException e) {
+ System.out.println("FileFinder: "+ file.getName() +"Premission denied");
+ }
+ }
+ }
+ }
+
+ /**
+ * returns and prints out all Medias found
+ * @return ArrayList<File>
+ * all found Medias
+ */
+ public ArrayList<File> getFiles(){
+ print();
+ return this.files;
+ }
+
+ /**
+ * prints out found medias
+ *
+ */
+ public void print() {
+ System.out.println( "Found " + files.size() + " file" + (files.size() == 1 ? "." : "s.") );
+ for ( File f : files ) System.out.println( f.getAbsolutePath() );
+ }
+
+ /**
+ * checks if file extension matches or not
+ *
+ * @param s
+ * file to check
+ * @param suffixes
+ * allowed extensions
+ *
+ * @return boolean: true if it's a media, yalp can handle
+ */
+ private static boolean match( String s, String suffixes[] ) {
+ for ( String suffix : suffixes ) {
+ int huhu = s.length();
+ int huhu2 = suffix.length();
+ int huhu3 = huhu - huhu2;
+ if ( s.length() >= suffix.length() && s.substring(huhu3, s.length()).equalsIgnoreCase(suffix) ) return true;
+ }
+ return false;
+ }
+}
diff --git a/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileInfoManager.java b/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileInfoManager.java
new file mode 100644
index 0000000..34fe49b
--- /dev/null
+++ b/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileInfoManager.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2006 Manuel Traut and Volker Dahnke
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors: Manuel Traut and Volker Dahnke
+ */
+
+package YalpServer;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+
+import de.hampelratte.id3.*;
+
+import YalpInterfaces.*;
+
+/*
+ * Class FileInfoManager
+ *
+ * <em>Creates a Result out of FileInformations (ID3, etc)</em>
+ *
+ * @author Volker Dahnke / Manuel Traut
+ *
+ * @version 0.1 14-12-2005<br>
+ *
+ * @see ServerControl
+ */
+
+public class FileInfoManager {
+
+ private Media fileInfo;
+ private EncodingType eType;
+
+/*
+ * Constructor: tries to get all Informations about a file
+ *
+ * @param file
+ */
+
+ public FileInfoManager(File file) {
+
+ this.eType = EncodingType.UNKNOWN;
+ this.fileInfo = new Media();
+ this.fileInfo.path = file.getParent()+file.separator;
+ this.fileInfo.fileName = file.getName();
+
+ /* check extensions is mp3 */
+ if( this.fileInfo.fileName.substring( this.fileInfo.fileName.length() - 3,
+ this.fileInfo.fileName.length()).equalsIgnoreCase( "mp3" ) )
+ {
+ this.eType = EncodingType.MP3;
+ }
+
+ switch(this.eType.value()) {
+ case EncodingType._MP3:
+ try
+ {
+ /* opening mp3 file for reading and writing */
+ MP3File mp3 = new de.hampelratte.id3.MP3File(file.toString(), "r");
+ this.fileInfo.type = MediaType.SOUND;
+
+ if(mp3.hasID3v1Tag){
+ ID3v1Tag tag = mp3.readID3v1Tag();
+ /* t.b.d. create StringProperties
+ this.fileInfo.album = tag.getAlbum();
+ this.fileInfo.author = tag.getArtist();
+ this.fileInfo.category = tag.getGenre();
+ this.fileInfo.name = tag.getTrack() +" - "+tag.getTitle();
+ this.fileInfo.year = tag.getYear();
+ */
+ }
+
+ if(mp3.hasID3v2Tag){
+
+ // reading the ID3v2Tag
+ ID3v2Tag tag = mp3.readID3v2Tag();
+ /* t.b.d. create StringProperties
+ this.fileInfo.album = tag.getAlbum();
+ this.fileInfo.author = tag.getArtist();
+ this.fileInfo.category = tag.getGenre();
+ this.fileInfo.year = tag.getYear();
+ */
+ if( !(tag.getTrack().equals(""))){
+ this.fileInfo.name = tag.getTrack() +" - "+tag.getTitle();
+ } else {
+ this.fileInfo.name = tag.getTitle();
+ }
+ }
+
+ if (this.fileInfo.name.equals("")) {
+
+ this.fileInfo.name =
+ file.getName().substring( 0, file.getName().length() - 4 );
+ }
+
+ mp3.close();
+ } catch (Exception e) {
+
+ this.fileInfo.name =
+ file.getName().substring(0,file.getName().length() - 4);
+ }
+ break;
+
+ default:
+ this.fileInfo.name =
+ file.getName().substring(0,file.getName().length()-4);
+
+ this.fileInfo.type = MediaType.VIDEO;
+ break;
+ }
+ }
+
+/*
+ * returns the information to an media, found
+ * @return MediaChange
+ * Informations about the media
+ */
+
+ public Media getInfo(){
+ return this.fileInfo;
+ }
+}