slub.team team mailing list archive
-
slub.team team
-
Mailing list archive
-
Message #00232
[Merge] lp:~slub.team/goobi-production/integrate-util into lp:goobi-production
Ralf Claussnitzer has proposed merging lp:~slub.team/goobi-production/integrate-util into lp:goobi-production.
Requested reviews:
zeutschel (zeutschel)
Henning Gerhardt (henning-gerhardt)
For more details, see:
https://code.launchpad.net/~slub.team/goobi-production/integrate-util/+merge/105298
- removed util-0.0.1.jar
- integrated util classes in de.sub.commons namespace
--
https://code.launchpad.net/~slub.team/goobi-production/integrate-util/+merge/105298
Your team Saxon State Library Team is subscribed to branch lp:goobi-production.
=== removed file 'lib/util-0.0.1-SNAPSHOT.jar'
Binary files lib/util-0.0.1-SNAPSHOT.jar 2011-07-19 16:50:14 +0000 and lib/util-0.0.1-SNAPSHOT.jar 1970-01-01 00:00:00 +0000 differ
=== added directory 'src/de/unigoettingen/sub/commons'
=== added directory 'src/de/unigoettingen/sub/commons/util'
=== added file 'src/de/unigoettingen/sub/commons/util/ArrayUtils.java'
--- src/de/unigoettingen/sub/commons/util/ArrayUtils.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/ArrayUtils.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,49 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ *
+ * 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 de.unigoettingen.sub.commons.util;
+
+
+/**
+ * The Class ArrayUtils.
+ */
+public class ArrayUtils {
+
+ /**
+ * Checks if a array contains the given obeject
+ *
+ * @param array the array to search
+ * @param search the obeject to look after
+ *
+ * @return true, if successful
+ */
+ public static boolean contains(Object[] array, Object search) {
+ if (array.getClass().isInstance(search)) {
+ throw new IllegalArgumentException();
+ }
+ for (Object o: array) {
+ if (o.equals(search)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
=== added file 'src/de/unigoettingen/sub/commons/util/StringUtils.java'
--- src/de/unigoettingen/sub/commons/util/StringUtils.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/StringUtils.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,164 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ *
+ *
+ * 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 de.unigoettingen.sub.commons.util;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class StringUtils is a simple utility class for advanced (read obscure) string operations
+ */
+public class StringUtils {
+
+ /**
+ * Returns the index within the given String of the first occurrence of the specified regular expression.
+ *
+ * @param str the String to search
+ * @param searchStr the regular expression to search for.
+ *
+ * @return the index of the found expression
+ */
+ public static int indexOfRegex (String str, String searchStr) {
+ Pattern p = Pattern.compile(searchStr);
+ Matcher m = p.matcher(str);
+ if (m.find()) {
+ return m.start();
+ }
+ return -1;
+ }
+
+ /**
+ * Returns List of indexes within the given String of all occurrences of the specified character.
+ *
+ * @param s1 the s1
+ * @param s2 the s2
+ *
+ * @return the List of indexes
+ */
+ public static List<Integer> allIndexOf (String s1, String s2) {
+ List<Integer> al = new ArrayList<Integer>();
+ StringBuffer sb = new StringBuffer(s1);
+ Integer base = 0;
+ while (sb.indexOf(s2) >= 0) {
+ Integer pos = sb.indexOf(s2);
+ al.add(pos + base);
+ base += sb.delete(0, pos + s2.length()).length();
+ }
+ return al;
+ }
+
+ /**
+ * Index of occurance.
+ *
+ * @param s1 the s1
+ * @param s2 the s2
+ * @param i the i
+ *
+ * @return the int
+ */
+ public static int indexOfOccurance (String s1, String s2, Integer i) {
+ ArrayList<Integer> al = new ArrayList<Integer>();
+ al.addAll(allIndexOf(s1, s2));
+ if (al.size() <= i - 1) {
+ return al.get(i - i);
+ } else {
+ return -1;
+ }
+ }
+
+ /**
+ * Tests if the given string starts with the specified prefix or ends with the specified suffix.
+ *
+ * @param in the string to test
+ * @param str the pre- or suffix
+ *
+ * @return true, if successful
+ */
+ public static boolean startsOrEndsWith(String in, String str) {
+ if (in.startsWith(str)) {
+ return true;
+ }
+ if (in.endsWith(str)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Tests if the given string ends with the specified suffix.
+ *
+ * @param in the string to test
+ * @param str the suffix
+ *
+ * @return true, if successful
+ *
+ * @deprecated
+ */
+ @Deprecated
+ public static boolean endsWith(String in, String str) {
+ char[] c = str.toCharArray();
+ for (int i = 0; i < c.length; i++) {
+ if (in.endsWith(String.valueOf(c[i]))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Escape a regular expression.
+ *
+ * @param str the string containing a regular expression
+ *
+ * @return the escaped string
+ */
+ public static String escapeRegex (String str) {
+ str = str.replaceAll("\\*", "\\\\*");
+ str = str.replaceAll("\\.", "\\\\.");
+ str = str.replaceAll("\\?", "\\\\?");
+ str = str.replaceAll("\\+", "\\\\+");
+ //str = str.replaceAll("\\", "\\\\");
+ str = str.replaceAll("\\$", "\\\\$");
+ str = str.replaceAll("\\|", "\\\\|");
+ str = str.replaceAll("\\{", "\\\\{");
+ str = str.replaceAll("\\}", "\\\\}");
+ str = str.replaceAll("\\[", "\\\\[");
+ str = str.replaceAll("\\]", "\\\\]");
+ return str;
+ }
+
+ /**
+ * Returns true if and only if the given string contains the specified string, ignoring the case aof each string.
+ *
+ * @param in the string to test
+ * @param contains the string to search for
+ *
+ * @return true, if successful
+ */
+ public static boolean containsIgnoreCase (String in, String contains) {
+ return in.toLowerCase().contains(contains.toLowerCase());
+
+ }
+
+}
=== added directory 'src/de/unigoettingen/sub/commons/util/datasource'
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/AbstractStructure.java'
--- src/de/unigoettingen/sub/commons/util/datasource/AbstractStructure.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/AbstractStructure.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,131 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ * intranda software.
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+public abstract class AbstractStructure <S extends AbstractStructure<S>> implements Structure {
+ protected List<S> children;
+ protected Integer imagenumber; // imagenumber, integer from imageURLs HashMap
+ protected String content; // content of bookmark
+
+ /**
+ * Instantiates a new abstract structure.
+ */
+ public AbstractStructure() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Instantiates a new abstract structure.
+ *
+ * @param struct the struct
+ */
+ public AbstractStructure(Structure struct) {
+ this(struct.getImageNumber(), struct.getContent());
+ }
+
+
+ /**************************************************************************************
+ * Constructor which create a new bookmark with pagename and content
+ *
+ * @param pagename as Integer
+ * @param content as String
+ **************************************************************************************/
+ public AbstractStructure(Integer pagename, String content) {
+ this.imagenumber = pagename;
+ this.content = content;
+ }
+
+ /*************************************************************************************
+ * Getter for children
+ *
+ * @return the children
+ *************************************************************************************/
+ public List<S> getChildren() {
+ if (children != null) {
+ return children;
+ } else {
+ return new LinkedList<S>();
+ }
+ }
+
+ /**************************************************************************************
+ * Add bookmark to list of children
+ *
+ * @param child the Bookmark to add as child
+ **************************************************************************************/
+ public void addChildBookmark(S child) {
+ if (children == null) { // no list available, create one for all child bookmarks
+ children = new ArrayList<S>();
+ }
+ children.add(child);
+ }
+
+ /**************************************************************************************
+ * Setter for children
+ *
+ * @param children the children to set
+ **************************************************************************************/
+ public void setChildren(List<S> children) {
+ this.children = children;
+ }
+
+
+ /*************************************************************************************
+ * Getter for content
+ *
+ * @return the content
+ *************************************************************************************/
+ public String getContent() {
+ return content;
+ }
+
+ /*************************************************************************************
+ * Getter for imagenumber
+ *
+ * @return the imagenumber
+ *************************************************************************************/
+ public Integer getImageNumber() {
+ return imagenumber;
+ }
+
+ /**************************************************************************************
+ * Setter for content
+ *
+ * @param content the content to set
+ **************************************************************************************/
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ /**************************************************************************************
+ * Setter for imagenumber
+ *
+ * @param imagenumber the imagenumber to set
+ **************************************************************************************/
+ public void setImageNumber(Integer imagenumber) {
+ this.imagenumber = imagenumber;
+ }
+
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/AbstractUrlImage.java'
--- src/de/unigoettingen/sub/commons/util/datasource/AbstractUrlImage.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/AbstractUrlImage.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,91 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ * intranda software.
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.awt.image.RenderedImage;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+public abstract class AbstractUrlImage implements UrlImage {
+
+ protected URL url;
+ protected Integer pagenumber;
+
+ /*************************************************************************************
+ * Getter for pagenumber
+ *
+ * @return the pagenumber
+ *************************************************************************************/
+ public Integer getPageNumber() {
+ return pagenumber;
+ }
+
+ /*************************************************************************************
+ * Getter for url
+ *
+ * @return the url
+ *************************************************************************************/
+ public URL getURL() {
+ return url;
+ }
+
+
+ /**************************************************************************************
+ * Setter for url
+ *
+ * @param url the imageurl to set
+ **************************************************************************************/
+ public void setURL(URL imageurl) {
+ this.url = imageurl;
+ }
+
+ /**************************************************************************************
+ * Setter for pagenumber
+ *
+ * @param pagenumber the pagenumber to set
+ **************************************************************************************/
+ public void setPageNumber(Integer pagenumber) {
+ this.pagenumber = pagenumber;
+ }
+
+ /* (non-Javadoc)
+ * @see de.unigoettingen.commons.util.datasource.Image#openStream()
+ */
+ public InputStream openStream() throws IOException {
+ if (url == null) {
+ throw new IllegalStateException("URL is null");
+ }
+ return url.openStream();
+ }
+
+ /**
+ * Get rendered image. (Throws a UnsupportedOperationException)
+ *
+ * @see de.unigoettingen.sub.commons.util.datasource.Image#getRenderedImage()
+ *
+ * @return the rendered image
+ */
+ public RenderedImage getRenderedImage () {
+ throw new UnsupportedOperationException("Method getRenderedImage() not implemented in AbstractUrlImage!");
+ }
+
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/DataSource.java'
--- src/de/unigoettingen/sub/commons/util/datasource/DataSource.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/DataSource.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,44 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.io.IOException;
+import java.net.URL;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Interface DataSource.
+ */
+public interface DataSource {
+
+ /**
+ * Gets the URL.
+ *
+ * @return the URL
+ */
+ abstract URL getUrl ();
+
+ /**
+ * Close.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ abstract void close () throws IOException;
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/DirectoryListingUrlImageSource.java'
--- src/de/unigoettingen/sub/commons/util/datasource/DirectoryListingUrlImageSource.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/DirectoryListingUrlImageSource.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,132 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ * intranda software.
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class DirectoryListingUrlImageSource.
+ */
+public class DirectoryListingUrlImageSource implements ImageSource {
+
+ /** The dir. */
+ protected File dir = null;
+
+ /** The files. */
+ private List<File> files = null;
+
+ /**
+ * Instantiates a new directory listing url image source.
+ *
+ * @param dir the dir
+ */
+ public DirectoryListingUrlImageSource (File dir) {
+ this.dir = dir;
+ }
+
+ /* (non-Javadoc)
+ * @see de.unigoettingen.sub.commons.util.datasource.ImageSource#getImage(java.lang.Integer)
+ */
+ public Image getImage(Integer pageNr) throws IOException {
+ init();
+ SimpleUrlImage img = new SimpleUrlImage();
+ img.setPageNumber(pageNr);
+ img.setURL(files.get(pageNr).toURI().toURL());
+ return img;
+ }
+
+ /* (non-Javadoc)
+ * @see de.unigoettingen.sub.commons.util.datasource.ImageSource#getImageList()
+ */
+ public List<? extends Image> getImageList() throws IOException {
+ init();
+ List<SimpleUrlImage> images = new ArrayList<SimpleUrlImage>();
+ for (int i = 0; i < files.size(); i++) {
+ SimpleUrlImage img = new SimpleUrlImage();
+ img.setPageNumber(i + 1);
+ img.setURL(files.get(i).toURI().toURL());
+ images.add(img);
+ }
+ return images;
+ }
+
+ /* (non-Javadoc)
+ * @see de.unigoettingen.sub.commons.util.datasource.ImageSource#getImageMap()
+ */
+ public Map<Integer, ? extends Image> getImageMap() throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see de.unigoettingen.sub.commons.util.datasource.ImageSource#getNumberOfPages()
+ */
+ public Integer getNumberOfPages() {
+ try {
+ init();
+ } catch (IOException e) {
+ return 0;
+ }
+ return files.size();
+ }
+
+ /* (non-Javadoc)
+ * @see de.unigoettingen.sub.commons.util.datasource.DataSource#close()
+ */
+ public void close() throws IOException {
+ //Do nothing
+ }
+
+ /* (non-Javadoc)
+ * @see de.unigoettingen.sub.commons.util.datasource.DataSource#getUrl()
+ */
+ public URL getUrl() {
+ try {
+ return dir.toURI().toURL();
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Checks the given directory and add its contens as list
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ private void init () throws IOException {
+ if (files == null) {
+ if (!dir.isDirectory()) {
+ throw new IOException("Given File is not a directory");
+ }
+ files = Arrays.asList(dir.listFiles());
+ //TODO: Filter for supported Filetypes
+ }
+ }
+
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/Image.java'
--- src/de/unigoettingen/sub/commons/util/datasource/Image.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/Image.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,47 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ * intranda software.
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.awt.image.RenderedImage;
+import java.io.IOException;
+
+/**
+ * The Interface Image.
+ */
+public interface Image {
+
+ /**
+ * Gets the rendered image.
+ *
+ * @return the rendered image
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ abstract RenderedImage getRenderedImage () throws IOException;
+
+ /**
+ * Gets the page number.
+ *
+ * @return the page number
+ */
+ abstract Integer getPageNumber ();
+
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/ImageSource.java'
--- src/de/unigoettingen/sub/commons/util/datasource/ImageSource.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/ImageSource.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,67 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The Interface ImageSource.
+ */
+public interface ImageSource extends DataSource {
+
+ /**
+ * Gets the image.
+ *
+ * @param pageNr the page nr
+ *
+ * @return the image
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ abstract Image getImage (Integer pageNr) throws IOException;
+
+ /**
+ * Gets the images.
+ *
+ * @return the images
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ abstract List<? extends Image> getImageList () throws IOException;
+
+ /**
+ * Gets the images.
+ *
+ * @return the images
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ abstract Map<Integer, ? extends Image> getImageMap () throws IOException;
+
+ /**
+ * Gets the number of pages.
+ *
+ * @return the number of pages
+ */
+ abstract Integer getNumberOfPages ();
+
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/ImageSourceIterator.java'
--- src/de/unigoettingen/sub/commons/util/datasource/ImageSourceIterator.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/ImageSourceIterator.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,83 @@
+/*
+ * This file is a contribution to the the ContentServer project, mainly for research purposes.
+ *
+ * Copyright 2009, Christian Mahnke<cmahnke@xxxxxxxxx>.
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+//Avoid logger as external dependency here, try to wrap System.out.* streams
+//import org.apache.log4j.Logger;
+
+public class ImageSourceIterator implements Iterator<Image>, Iterable<Image> {
+ //protected static Logger logger = Logger.getLogger(ImageSourceIterator.class);
+
+ ImageSource is = null;
+ Integer pageNr = -1;
+
+ /**
+ * Instantiates a new image source iterator.
+ *
+ * @param is the ImageSource
+ */
+ public ImageSourceIterator(ImageSource is) {
+ this.is = is;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (pageNr < is.getNumberOfPages()) {
+ return true;
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Iterator#next()
+ */
+ public Image next() {
+ pageNr++;
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+
+ try {
+ return is.getImage(pageNr);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<Image> iterator() {
+ return this;
+ }
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/Metadata.java'
--- src/de/unigoettingen/sub/commons/util/datasource/Metadata.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/Metadata.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Interface Metadata.
+ */
+public interface Metadata {
+
+ /**
+ * Gets the title.
+ *
+ * @return the title
+ */
+ abstract String getTitle();
+
+ /**
+ * Gets the creator.
+ *
+ * @return the creator
+ */
+ abstract String getCreator();
+
+ /**
+ * Gets the keywords.
+ *
+ * @return the keywords
+ */
+ abstract String getKeywords();
+
+ /**
+ * Gets the subject.
+ *
+ * @return the subject
+ */
+ abstract String getSubject();
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/MetadataSource.java'
--- src/de/unigoettingen/sub/commons/util/datasource/MetadataSource.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/MetadataSource.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,38 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.util.List;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Interface MetadataSource.
+ */
+public interface MetadataSource extends DataSource {
+
+ /**
+ * Gets the metadata.
+ *
+ * @return the metadata
+ */
+ abstract List<Metadata> getMetadata ();
+
+
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/SimpleStructure.java'
--- src/de/unigoettingen/sub/commons/util/datasource/SimpleStructure.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/SimpleStructure.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,41 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+public class SimpleStructure extends AbstractStructure<SimpleStructure> {
+
+ /**
+ * Instantiates a new simple structure.
+ */
+ public SimpleStructure() {
+
+ }
+
+ /**************************************************************************************
+ * Constructor which create a new bookmark with pagename and content
+ *
+ * @param pagename as Integer
+ * @param content as String
+ **************************************************************************************/
+ public SimpleStructure(Integer pagename, String content) {
+ super(pagename, content);
+ }
+
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/SimpleUrlImage.java'
--- src/de/unigoettingen/sub/commons/util/datasource/SimpleUrlImage.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/SimpleUrlImage.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,63 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.net.URL;
+
+public class SimpleUrlImage extends AbstractUrlImage implements UrlImage {
+
+ /**
+ * Instantiates a new simple url image.
+ *
+ * @param pageNumber the page number
+ * @param url the url
+ */
+ public SimpleUrlImage (Integer pageNumber, URL url) {
+ this.pagenumber = pageNumber;
+ this.url = url;
+ }
+
+ /**
+ * Instantiates a new simple url image.
+ */
+ public SimpleUrlImage () {
+
+ }
+
+ /**************************************************************************************
+ * Setter for url
+ *
+ * @param url the imageurl to set
+ **************************************************************************************/
+ public void setURL(URL imageurl) {
+ this.url = imageurl;
+ }
+
+ /**************************************************************************************
+ * Setter for pdfpagenumber
+ *
+ * @param pagenumber the pdfpagenumber to set
+ **************************************************************************************/
+ public void setPageNumber(Integer pagenumber) {
+ this.pagenumber = pagenumber;
+ }
+
+
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/Structure.java'
--- src/de/unigoettingen/sub/commons/util/datasource/Structure.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/Structure.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,51 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ * intranda software.
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.util.List;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Interface Structure.
+ */
+public interface Structure {
+
+ /**
+ * Gets the image number.
+ *
+ * @return the image number
+ */
+ abstract Integer getImageNumber ();
+
+ /**
+ * Gets the content.
+ *
+ * @return the content
+ */
+ abstract String getContent ();
+
+ /**
+ * Gets the children.
+ *
+ * @return the children
+ */
+ abstract List<? extends Structure> getChildren ();
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/StructureDumper.java'
--- src/de/unigoettingen/sub/commons/util/datasource/StructureDumper.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/StructureDumper.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,74 @@
+/*
+ * This file is a contribution to the the ContentServer project, mainly for research purposes.
+ *
+ * Copyright 2009, Christian Mahnke<cmahnke@xxxxxxxxx>.
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The Class StructureDumper. A simple class for tests and debugging.
+ */
+public class StructureDumper {
+
+ /** The struct. */
+ List<Structure> structList = null;
+
+
+ public StructureDumper (Structure struct) {
+ structList = new ArrayList<Structure>();
+ structList.add(struct);
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public StructureDumper (StructureSource structSource) {
+ this.structList = (List<Structure>) structSource.getStructureList();
+ }
+
+
+ /**
+ * Dump.
+ */
+ public void dump () {
+ for (Structure struct: structList) {
+ System.out.println("ROOT: " + struct.getContent());
+ dump(struct, 1);
+ }
+ }
+
+ /**
+ * Dump.
+ *
+ * @param struct the struct
+ * @param level the level
+ */
+ protected void dump (Structure struct, Integer level) {
+ for (Structure child: struct.getChildren()) {
+ StringBuffer ident = new StringBuffer();
+ for (int i = 0; i < level; i++) {
+ ident.append(" ");
+ }
+ System.out.println(ident.toString() + "+ " + child.getContent());
+ if (struct.getChildren().size() != 0) {
+ dump(struct, level + 1);
+ }
+ }
+ }
+
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/StructureSource.java'
--- src/de/unigoettingen/sub/commons/util/datasource/StructureSource.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/StructureSource.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,37 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.util.List;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Interface StructureSource.
+ */
+public interface StructureSource extends DataSource {
+
+
+ /**
+ * Gets the structure list.
+ *
+ * @return the structure list
+ */
+ abstract List<? extends Structure> getStructureList ();
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/TextSource.java'
--- src/de/unigoettingen/sub/commons/util/datasource/TextSource.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/TextSource.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,24 @@
+/*
+ * This file is a contribution to the the ContentServer project, mainly for research purposes.
+ *
+ * Copyright 2009, Christian Mahnke<cmahnke@xxxxxxxxx>.
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+public interface TextSource extends DataSource {
+
+ //TODO: for now just a marker interface, needed later for fulltext handling
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/UrlImage.java'
--- src/de/unigoettingen/sub/commons/util/datasource/UrlImage.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/UrlImage.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,51 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ * intranda software.
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+public interface UrlImage extends Image {
+ /**
+ * Gets the URL.
+ *
+ * @return the URL
+ */
+ abstract URL getURL ();
+
+
+ /**
+ * Setter for url
+ *
+ * @param url the imageurl to set
+ */
+ public void setURL(URL url);
+
+ /**
+ * Open stream.
+ *
+ * @return the input stream
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ abstract InputStream openStream() throws IOException;
+}
=== added file 'src/de/unigoettingen/sub/commons/util/datasource/WrappedImage.java'
--- src/de/unigoettingen/sub/commons/util/datasource/WrappedImage.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/datasource/WrappedImage.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,61 @@
+/*
+ * This file is a contribution to the the ContentServer project, mainly for research purposes.
+ *
+ * Copyright 2009, Christian Mahnke<cmahnke@xxxxxxxxx>.
+ *
+ * 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 de.unigoettingen.sub.commons.util.datasource;
+
+import java.awt.image.RenderedImage;
+import java.io.IOException;
+
+/**
+ * The Class WrappedImage is a simple wrapper for java.awt.image.RenderedImage instances.
+ */
+public class WrappedImage implements Image {
+
+ /** The page nr. */
+ protected Integer pageNr = -1;
+
+ /** The image. */
+ protected RenderedImage image = null;
+
+ /**
+ * Instantiates a new wrapped image.
+ *
+ * @param pagenr the page number
+ * @param image the RenderedImage
+ */
+ public WrappedImage (Integer pagenr, RenderedImage image) {
+ this.pageNr = pagenr;
+ this.image = image;
+ }
+
+ /* (non-Javadoc)
+ * @see de.unigoettingen.sub.commons.util.datasource.Image#getPageNumber()
+ */
+ public Integer getPageNumber() {
+ return pageNr;
+ }
+
+ /* (non-Javadoc)
+ * @see de.unigoettingen.sub.commons.util.datasource.Image#getRenderedImage()
+ */
+ public RenderedImage getRenderedImage() throws IOException {
+ return image;
+ }
+
+}
=== added directory 'src/de/unigoettingen/sub/commons/util/file'
=== added file 'src/de/unigoettingen/sub/commons/util/file/FileExtensionsFilter.java'
--- src/de/unigoettingen/sub/commons/util/file/FileExtensionsFilter.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/file/FileExtensionsFilter.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,114 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ *
+ * 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 de.unigoettingen.sub.commons.util.file;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.ArrayList;
+import java.util.List;
+
+
+//TODO: This is guaranted to work case insensive only if you add extensions as String
+/**
+ * The Class FileExtensionsFilter implements a FileFilter. It can be used to filter files based on their extensions.
+ */
+public class FileExtensionsFilter implements FileFilter {
+
+ /** The extension. */
+ protected List<String> extensions = new ArrayList<String>();
+
+ /**
+ * Instantiates a new file extensions filter.
+ *
+ * @param extension the extension
+ */
+ public FileExtensionsFilter (String extension) {
+ this.extensions.add(extension.toLowerCase());
+ }
+
+ /**
+ * Instantiates a new file extensions filter.
+ *
+ * @param extensions the extensions
+ */
+ public FileExtensionsFilter (List<String> extensions) {
+ this.extensions = extensions;
+ };
+
+ /**
+ * Adds the extension.
+ *
+ * @param extension the extension
+ */
+ public void addExtension (String extension) {
+ this.extensions.add(extension.toLowerCase());
+ }
+
+ /**
+ * Sets the extension.
+ *
+ * @param extensions the new extension
+ */
+ public void setExtension (List<String> extensions) {
+ this.extensions = extensions;
+ }
+
+ /**
+ * Gets the extensions.
+ *
+ * @return the extensions
+ */
+ public List<String> getExtensions () {
+ return extensions;
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.FileFilter#accept(java.io.File)
+ */
+ public boolean accept (File pathname) {
+ if (extensions.contains(FileUtils.getFileExtensionFromFile(pathname).toLowerCase())) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Utility Method to get the extension of a file
+ *
+ * @param file the file
+ *
+ * @return the extension
+ */
+ public static String getExtension(String file) {
+ return file.substring(file.lastIndexOf(".") + 1).toLowerCase();
+ }
+
+ /**
+ * Utility Method to get the extension of a file
+ *
+ * @param file the file
+ *
+ * @return the extension
+ */
+ public static String getExtension(File file) {
+ return file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf(".") + 1).toLowerCase();
+ }
+
+}
=== added file 'src/de/unigoettingen/sub/commons/util/file/FileUtils.java'
--- src/de/unigoettingen/sub/commons/util/file/FileUtils.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/file/FileUtils.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,274 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ * - http://www.intranda.com
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ * intranda software.
+ *
+ * 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 de.unigoettingen.sub.commons.util.file;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+
+/**
+ * The Class FileUtils provides some utilities for file handling
+ */
+public class FileUtils {
+
+ protected static Integer copyBufferSize = 4096;
+
+ /**
+ *
+ * Gets the file extension from file name.
+ *
+ * @param inFileName
+ * the file name as String
+ *
+ * @return the file extension from file name as String
+ */
+ public static String getFileExtensionFromFileName(String inFileName) {
+ int dotPos = inFileName.lastIndexOf(".") + 1;
+ String extension = inFileName.substring(dotPos).trim();
+ return extension;
+ }
+
+ /**
+ * Gets the file extension from a File as String.
+ *
+ * @param inFile
+ * the File
+ *
+ * @return the file extension from inFile as String
+ */
+ public static String getFileExtensionFromFile(File inFile) {
+ return getFileExtensionFromFileName(inFile.getAbsolutePath());
+ }
+
+ /**
+ * calculate all files with given file extension at specified directory
+ * recursivly.
+ *
+ * @param inDir
+ * the directory to run through
+ * @param ext
+ * the file extension to use for counting, not case sensitive
+ *
+ * @return number of files as Integer
+ *
+ * @author Steffen Hankiewicz
+ */
+ public static Integer getNumberOfFiles(File inDir, final String ext) {
+ int count = 0;
+ if (inDir.isDirectory()) {
+ // Count the images
+ FilenameFilter filter = new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.toLowerCase().endsWith(ext.toLowerCase());
+ }
+ };
+ count = inDir.list(filter).length;
+
+ // Count the contents of sub directories
+ String[] children = inDir.list();
+ for (int i = 0; i < children.length; i++) {
+ count += getNumberOfFiles(new File(inDir, children[i]), ext);
+ }
+ }
+ return count;
+ }
+
+ /**
+ * calculate all files with given file extension at specified directory
+ * recursivly.
+ *
+ * @param inDir
+ * the directory to run through
+ * @param ext
+ * the file extension to use for counting, not case sensitive
+ *
+ * @return number of files as Integer
+ *
+ * @author Steffen Hankiewicz
+ */
+ public static Integer getNumberOfFiles(String inDir, final String ext) {
+ return getNumberOfFiles(new File(inDir), ext);
+ }
+
+ /**
+ * The Class FileListFilter can be used to filter Files usinf a regular
+ * expression
+ */
+ public static class FileListFilter implements FilenameFilter {
+
+ /** The name. */
+ private String name;
+
+ /**
+ * Instantiates a new file list filter.
+ *
+ * @param name
+ * the name
+ */
+ public FileListFilter(String name) {
+ this.name = name;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
+ */
+ public boolean accept(File directory, String filename) {
+ boolean fileOK = true;
+ if (name != null) {
+ fileOK &= filename.matches(name);
+ }
+ return fileOK;
+ }
+ }
+
+ /**
+ * Deletes all files and subdirectories under dir. Returns true if all
+ * deletions were successful. If a deletion fails, the method stops
+ * attempting to delete and returns false.
+ *
+ * @param dir
+ * the directory to delete
+ *
+ * @return true, if directory deleted or it doesn't exists
+ */
+ public static boolean deleteDir(File dir) {
+ if (!dir.exists()) {
+ return true;
+ }
+ if (!deleteInDir(dir)) {
+ return false;
+ }
+ // The directory is now empty so delete it
+ return dir.delete();
+ }
+
+ /**
+ * Deletes all files and subdirectories under dir. But not the dir itself
+ *
+ * @param dir
+ * the directory, which contents should be deleted
+ *
+ * @return true, if contents directory are deleted
+ */
+ public static boolean deleteInDir(File dir) {
+ if (dir.exists() && dir.isDirectory()) {
+ String[] children = dir.list();
+ for (int i = 0; i < children.length; i++) {
+ if (!deleteDir(new File(dir, children[i]))) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Make a File List for a given File (non recursive).
+ * @author cmahnke
+ * @param inputFile the input file
+ * @param filter the filter
+ * @return the list
+ */
+ public static List<File> makeFileList(File inputFile, String filter) {
+ List<File> fileList;
+ if (inputFile.isDirectory()) {
+
+
+ File files[] = inputFile.listFiles(new FileExtensionsFilter(filter));
+ fileList = Arrays.asList(files);
+ Collections.sort(fileList);
+
+ } else {
+ fileList = new ArrayList<File>();
+ fileList.add(inputFile);
+ }
+ return fileList;
+ }
+
+ /**
+ * Gets the extension of a given file.
+ *
+ * @param file the File
+ * @return the extension
+ * @author cmahnke
+ */
+ public static String getExtension(String file) {
+ if (file.contains(".")) {
+ return file.substring(file.lastIndexOf(".") + 1).toLowerCase();
+ } else {
+ return "";
+ }
+ }
+
+ /**
+ * Copy directory using a simple static method which can copy local directories and files.
+ * Returns true if the file or directory could be copied, returns false if the target directory
+ * doesn't exists and can't be created.
+ *
+ * @param srcPath the src path
+ * @param dstPath the dst path
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ public static boolean copyDirectory (File srcPath, File dstPath) throws IOException {
+ if (srcPath.isDirectory()) {
+ if (!dstPath.exists() && dstPath.mkdir()) {
+ return false;
+ }
+
+ String files[] = srcPath.list();
+ for (int i = 0; i < files.length; i++) {
+ copyDirectory(new File(srcPath, files[i]), new File(dstPath, files[i]));
+ }
+ } else {
+ if (!srcPath.exists()) {
+ System.out.println("File or directory does not exist.");
+ System.exit(0);
+ } else {
+ InputStream in = new FileInputStream(srcPath);
+ OutputStream out = new FileOutputStream(dstPath);
+
+ // Transfer bytes from in to out
+ byte[] buf = new byte[copyBufferSize];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ }
+ }
+ return true;
+ //System.out.println("Directory copied.");
+ }
+
+}
=== added directory 'src/de/unigoettingen/sub/commons/util/stream'
=== added file 'src/de/unigoettingen/sub/commons/util/stream/SimpleInputStreamSaver.java'
--- src/de/unigoettingen/sub/commons/util/stream/SimpleInputStreamSaver.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/stream/SimpleInputStreamSaver.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,123 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ *
+ * 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 de.unigoettingen.sub.commons.util.stream;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+
+/**
+ * The Class SimpleInputStreamSaver provides a simple way to save the contents of an InputSream in a File.
+ */
+public class SimpleInputStreamSaver {
+
+ /** The file. */
+ File file;
+
+ /** The is. */
+ InputStream is;
+
+ /**
+ * Instantiates a new simple input stream saver.
+ */
+ public SimpleInputStreamSaver () {
+
+ }
+
+ /**
+ * Instantiates a new simple input stream saver.
+ *
+ * @param file the file to the the contents to.
+ * @param is the InputStream to save
+ */
+ public SimpleInputStreamSaver (File file, InputStream is) {
+ this.file = file;
+ this.is = is;
+ }
+
+ /**
+ * Safe the contents of the stream
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ public void safe () throws IOException {
+ BufferedInputStream bis = new BufferedInputStream(is);
+ FileOutputStream fos = new FileOutputStream(file);
+ try {
+ int bufSize = 1024 * 8;
+ byte[] bytes = new byte[bufSize];
+ int count = bis.read(bytes);
+ while (count != -1 && count <= bufSize) {
+ fos.write(bytes, 0, count);
+ count = bis.read(bytes);
+ }
+ if (count != -1) {
+ fos.write(bytes, 0, count);
+ }
+ fos.close();
+ } finally {
+ bis.close();
+ fos.close();
+ }
+ }
+
+ /**
+ * Gets the file.
+ *
+ * @return the file
+ */
+ public File getFile() {
+ return file;
+ }
+
+ /**
+ * Sets the file.
+ *
+ * @param file the new file
+ */
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+ /**
+ * Gets the InputStream.
+ *
+ * @return the InputStream.
+ */
+ public InputStream getIs() {
+ return is;
+ }
+
+ /**
+ * Sets the InputStream.
+ *
+ * @param is the InputStream.
+ */
+ public void setIs(InputStream is) {
+ this.is = is;
+ }
+
+
+
+}
=== added file 'src/de/unigoettingen/sub/commons/util/stream/StreamUtils.java'
--- src/de/unigoettingen/sub/commons/util/stream/StreamUtils.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/stream/StreamUtils.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,209 @@
+/*
+ * This file is part of the SUB Commons project.
+ * Visit the websites for more information.
+ * - http://gdz.sub.uni-goettingen.de
+ * - http://www.intranda.com
+ *
+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
+ * intranda software.
+ *
+ * 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 de.unigoettingen.sub.commons.util.stream;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLDecoder;
+import java.util.Properties;
+
+import org.apache.commons.codec.binary.Base64;
+
+
+public class StreamUtils {
+
+ /**
+ * get MimeType as {@link String} from given URL
+ *
+ * @param url
+ * the url from where to get the MimeType
+ * @return MimeType as {@link String}
+ * @throws IOException
+ */
+ public static String getMimeTypeFromUrl(URL url) throws IOException {
+
+ URLConnection con = url.openConnection();
+ return con.getContentType();
+ }
+
+ /**
+ * get MimeType as {@link String} from given URL including proxy details
+ *
+ * @param url
+ * the url from where to get the MimeType
+ * @param httpproxyhost
+ * host of proxy
+ * @param httpproxyport
+ * port of proxy
+ * @param httpproxyusername
+ * username for proxy
+ * @param httpproxypassword
+ * password for proxy
+ * @return MimeType as {@link String}
+ * @throws IOException
+ */
+
+ public static String getMimeTypeFromUrl(URL url, String httpproxyhost,
+ String httpproxyport, String httpproxyusername,
+ String httpproxypassword) throws IOException {
+ if (httpproxyhost != null) {
+ Properties properties = System.getProperties();
+ properties.put("http.proxyHost", httpproxyhost);
+ if (httpproxyport != null) {
+ properties.put("http.proxyPort", httpproxyport);
+ } else {
+ properties.put("http.proxyPort", "80");
+ }
+ }
+ URLConnection con = url.openConnection();
+ if (httpproxyusername != null) {
+ String login = httpproxyusername + ":" + httpproxypassword;
+ String encodedLogin = new String(Base64.encodeBase64(login
+ .getBytes()));
+ con.setRequestProperty("Proxy-Authorization", "Basic "
+ + encodedLogin);
+ }
+ return con.getContentType();
+ }
+
+ /**
+ * get {@link InputStream} from given URL
+ *
+ * @param url
+ * the url from where to get the {@link InputStream}
+ * @return {@link InputStream} for url
+ * @throws IOException
+ */
+ public static InputStream getInputStreamFromUrl(URL url) throws IOException {
+ return StreamUtils.getInputStreamFromUrl(url, null);
+ }
+
+ /**
+ * get {@link InputStream} from given URL using a basis path and proxy informations
+ *
+ * @param url
+ * the url from where to get the {@link InputStream}
+ * @param basepath the basispath
+ * @param httpproxyhost the host for proxy
+ * @param httpproxyport the port for proxy
+ * @param httpproxyusername the username for the proxy
+ * @param httpproxypassword the password for the proxy
+ * @return {@link InputStream} for url
+ * @throws IOException
+ */
+ public static InputStream getInputStreamFromUrl(URL url, String basepath,
+ String httpproxyhost, String httpproxyport,
+ String httpproxyusername, String httpproxypassword)
+ throws IOException {
+ InputStream inStream = null;
+
+ if (url.getProtocol().equalsIgnoreCase("http")) {
+ if (httpproxyhost != null) {
+ Properties properties = System.getProperties();
+ properties.put("http.proxyHost", httpproxyhost);
+ if (httpproxyport != null) {
+ properties.put("http.proxyPort", httpproxyport);
+ } else {
+ properties.put("http.proxyPort", "80");
+ }
+ }
+ URLConnection con = url.openConnection();
+ if (httpproxyusername != null) {
+ String login = httpproxyusername + ":" + httpproxypassword;
+ String encodedLogin = new String(Base64.encodeBase64(login
+ .getBytes()));
+ con.setRequestProperty("Proxy-Authorization", "Basic "
+ + encodedLogin);
+ }
+ inStream = con.getInputStream();
+ } else if (url.getProtocol().equalsIgnoreCase("file")) {
+ String filepath = url.getFile();
+
+ filepath = URLDecoder.decode(filepath, System
+ .getProperty("file.encoding"));
+
+ File f = new File(filepath);
+ inStream = new FileInputStream(f);
+ } else if (url.getProtocol().equalsIgnoreCase("")) {
+ String filepath = url.getFile();
+ // we just have the relative path, need to find the absolute path
+ String path = basepath + filepath;
+
+ // call this method again
+ URL completeurl = new URL(path);
+ inStream = getInputStreamFromUrl(completeurl);
+ }
+
+ return inStream;
+ }
+
+ /**
+ * get {@link InputStream} from given URL using a basis path
+ *
+ * @param url
+ * the url from where to get the {@link InputStream}
+ * @param basepath the basispath
+ * @return {@link InputStream} for url
+ * @throws IOException
+ */
+ public static InputStream getInputStreamFromUrl(URL url, String basepath)
+ throws IOException {
+ return getInputStreamFromUrl(url, basepath, null, null, null, null);
+ }
+
+
+ /**
+ * Dump {@link InputStream} into a String
+ *
+ * @param in the InputStream
+ * @return the String
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ public static String dumpInputStream (InputStream in) throws IOException {
+ if (in != null) {
+ Writer writer = new StringWriter();
+
+ char[] buffer = new char[1024];
+ try {
+ Reader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
+ int n;
+ while ((n = reader.read(buffer)) != -1) {
+ writer.write(buffer, 0, n);
+ }
+ } finally {
+ in.close();
+ }
+ return writer.toString();
+ } else {
+ return "";
+ }
+ }
+}
=== added directory 'src/de/unigoettingen/sub/commons/util/xml'
=== added file 'src/de/unigoettingen/sub/commons/util/xml/XMLDumper.java'
--- src/de/unigoettingen/sub/commons/util/xml/XMLDumper.java 1970-01-01 00:00:00 +0000
+++ src/de/unigoettingen/sub/commons/util/xml/XMLDumper.java 2012-05-10 06:45:23 +0000
@@ -0,0 +1,28 @@
+package de.unigoettingen.sub.commons.util.xml;
+
+import java.io.StringWriter;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Node;
+
+public class XMLDumper {
+
+ public static String NodeToString(Node node) {
+ StringWriter writer = new StringWriter();
+ try {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "true");
+ transformer.transform(new DOMSource(node), new StreamResult(writer));
+ } catch (TransformerException t) {
+ throw new IllegalStateException(t);
+ }
+ return writer.toString();
+ }
+
+}
Follow ups