Merge lp:~slub.team/goobi-production/integrate-util into lp:goobi-production/1.7

Proposed by Ralf Claussnitzer
Status: Merged
Merge reported by: Ralf Claussnitzer
Merged at revision: not available
Proposed branch: lp:~slub.team/goobi-production/integrate-util
Merge into: lp:goobi-production/1.7
Diff against target: 2178 lines (+2051/-0)
24 files modified
src/de/unigoettingen/sub/commons/util/ArrayUtils.java (+49/-0)
src/de/unigoettingen/sub/commons/util/StringUtils.java (+164/-0)
src/de/unigoettingen/sub/commons/util/datasource/AbstractStructure.java (+131/-0)
src/de/unigoettingen/sub/commons/util/datasource/AbstractUrlImage.java (+91/-0)
src/de/unigoettingen/sub/commons/util/datasource/DataSource.java (+44/-0)
src/de/unigoettingen/sub/commons/util/datasource/DirectoryListingUrlImageSource.java (+132/-0)
src/de/unigoettingen/sub/commons/util/datasource/Image.java (+47/-0)
src/de/unigoettingen/sub/commons/util/datasource/ImageSource.java (+67/-0)
src/de/unigoettingen/sub/commons/util/datasource/ImageSourceIterator.java (+83/-0)
src/de/unigoettingen/sub/commons/util/datasource/Metadata.java (+55/-0)
src/de/unigoettingen/sub/commons/util/datasource/MetadataSource.java (+38/-0)
src/de/unigoettingen/sub/commons/util/datasource/SimpleStructure.java (+41/-0)
src/de/unigoettingen/sub/commons/util/datasource/SimpleUrlImage.java (+63/-0)
src/de/unigoettingen/sub/commons/util/datasource/Structure.java (+51/-0)
src/de/unigoettingen/sub/commons/util/datasource/StructureDumper.java (+74/-0)
src/de/unigoettingen/sub/commons/util/datasource/StructureSource.java (+37/-0)
src/de/unigoettingen/sub/commons/util/datasource/TextSource.java (+24/-0)
src/de/unigoettingen/sub/commons/util/datasource/UrlImage.java (+51/-0)
src/de/unigoettingen/sub/commons/util/datasource/WrappedImage.java (+61/-0)
src/de/unigoettingen/sub/commons/util/file/FileExtensionsFilter.java (+114/-0)
src/de/unigoettingen/sub/commons/util/file/FileUtils.java (+274/-0)
src/de/unigoettingen/sub/commons/util/stream/SimpleInputStreamSaver.java (+123/-0)
src/de/unigoettingen/sub/commons/util/stream/StreamUtils.java (+209/-0)
src/de/unigoettingen/sub/commons/util/xml/XMLDumper.java (+28/-0)
To merge this branch: bzr merge lp:~slub.team/goobi-production/integrate-util
Reviewer Review Type Date Requested Status
Henning Gerhardt Approve
zeutschel Pending
Review via email: mp+105298@code.launchpad.net

Description of the change

- removed util-0.0.1.jar
- integrated util classes in de.sub.commons namespace

To post a comment you must log in.
Revision history for this message
Henning Gerhardt (henning-gerhardt) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'lib/util-0.0.1-SNAPSHOT.jar'
2Binary 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
3=== added directory 'src/de/unigoettingen/sub/commons'
4=== added directory 'src/de/unigoettingen/sub/commons/util'
5=== added file 'src/de/unigoettingen/sub/commons/util/ArrayUtils.java'
6--- src/de/unigoettingen/sub/commons/util/ArrayUtils.java 1970-01-01 00:00:00 +0000
7+++ src/de/unigoettingen/sub/commons/util/ArrayUtils.java 2012-05-10 06:45:23 +0000
8@@ -0,0 +1,49 @@
9+/*
10+ * This file is part of the SUB Commons project.
11+ * Visit the websites for more information.
12+ * - http://gdz.sub.uni-goettingen.de
13+ *
14+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
15+ *
16+ * Licensed under the Apache License, Version 2.0 (the “License”);
17+ * you may not use this file except in compliance with the License.
18+ * You may obtain a copy of the License at
19+ *
20+ * http://www.apache.org/licenses/LICENSE-2.0
21+ *
22+ * Unless required by applicable law or agreed to in writing, software
23+ * distributed under the License is distributed on an “AS IS” BASIS,
24+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+ * See the License for the specific language governing permissions and
26+ * limitations under the License.
27+ */
28+
29+package de.unigoettingen.sub.commons.util;
30+
31+
32+/**
33+ * The Class ArrayUtils.
34+ */
35+public class ArrayUtils {
36+
37+ /**
38+ * Checks if a array contains the given obeject
39+ *
40+ * @param array the array to search
41+ * @param search the obeject to look after
42+ *
43+ * @return true, if successful
44+ */
45+ public static boolean contains(Object[] array, Object search) {
46+ if (array.getClass().isInstance(search)) {
47+ throw new IllegalArgumentException();
48+ }
49+ for (Object o: array) {
50+ if (o.equals(search)) {
51+ return true;
52+ }
53+ }
54+ return false;
55+ }
56+
57+}
58
59=== added file 'src/de/unigoettingen/sub/commons/util/StringUtils.java'
60--- src/de/unigoettingen/sub/commons/util/StringUtils.java 1970-01-01 00:00:00 +0000
61+++ src/de/unigoettingen/sub/commons/util/StringUtils.java 2012-05-10 06:45:23 +0000
62@@ -0,0 +1,164 @@
63+/*
64+ * This file is part of the SUB Commons project.
65+ * Visit the websites for more information.
66+ * - http://gdz.sub.uni-goettingen.de
67+ *
68+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
69+ *
70+ *
71+ * Licensed under the Apache License, Version 2.0 (the “License”);
72+ * you may not use this file except in compliance with the License.
73+ * You may obtain a copy of the License at
74+ *
75+ * http://www.apache.org/licenses/LICENSE-2.0
76+ *
77+ * Unless required by applicable law or agreed to in writing, software
78+ * distributed under the License is distributed on an “AS IS” BASIS,
79+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
80+ * See the License for the specific language governing permissions and
81+ * limitations under the License.
82+ */
83+package de.unigoettingen.sub.commons.util;
84+
85+import java.util.ArrayList;
86+import java.util.List;
87+import java.util.regex.Matcher;
88+import java.util.regex.Pattern;
89+
90+// TODO: Auto-generated Javadoc
91+/**
92+ * The Class StringUtils is a simple utility class for advanced (read obscure) string operations
93+ */
94+public class StringUtils {
95+
96+ /**
97+ * Returns the index within the given String of the first occurrence of the specified regular expression.
98+ *
99+ * @param str the String to search
100+ * @param searchStr the regular expression to search for.
101+ *
102+ * @return the index of the found expression
103+ */
104+ public static int indexOfRegex (String str, String searchStr) {
105+ Pattern p = Pattern.compile(searchStr);
106+ Matcher m = p.matcher(str);
107+ if (m.find()) {
108+ return m.start();
109+ }
110+ return -1;
111+ }
112+
113+ /**
114+ * Returns List of indexes within the given String of all occurrences of the specified character.
115+ *
116+ * @param s1 the s1
117+ * @param s2 the s2
118+ *
119+ * @return the List of indexes
120+ */
121+ public static List<Integer> allIndexOf (String s1, String s2) {
122+ List<Integer> al = new ArrayList<Integer>();
123+ StringBuffer sb = new StringBuffer(s1);
124+ Integer base = 0;
125+ while (sb.indexOf(s2) >= 0) {
126+ Integer pos = sb.indexOf(s2);
127+ al.add(pos + base);
128+ base += sb.delete(0, pos + s2.length()).length();
129+ }
130+ return al;
131+ }
132+
133+ /**
134+ * Index of occurance.
135+ *
136+ * @param s1 the s1
137+ * @param s2 the s2
138+ * @param i the i
139+ *
140+ * @return the int
141+ */
142+ public static int indexOfOccurance (String s1, String s2, Integer i) {
143+ ArrayList<Integer> al = new ArrayList<Integer>();
144+ al.addAll(allIndexOf(s1, s2));
145+ if (al.size() <= i - 1) {
146+ return al.get(i - i);
147+ } else {
148+ return -1;
149+ }
150+ }
151+
152+ /**
153+ * Tests if the given string starts with the specified prefix or ends with the specified suffix.
154+ *
155+ * @param in the string to test
156+ * @param str the pre- or suffix
157+ *
158+ * @return true, if successful
159+ */
160+ public static boolean startsOrEndsWith(String in, String str) {
161+ if (in.startsWith(str)) {
162+ return true;
163+ }
164+ if (in.endsWith(str)) {
165+ return true;
166+ }
167+ return false;
168+ }
169+
170+ /**
171+ * Tests if the given string ends with the specified suffix.
172+ *
173+ * @param in the string to test
174+ * @param str the suffix
175+ *
176+ * @return true, if successful
177+ *
178+ * @deprecated
179+ */
180+ @Deprecated
181+ public static boolean endsWith(String in, String str) {
182+ char[] c = str.toCharArray();
183+ for (int i = 0; i < c.length; i++) {
184+ if (in.endsWith(String.valueOf(c[i]))) {
185+ return true;
186+ }
187+ }
188+ return false;
189+ }
190+
191+ /**
192+ * Escape a regular expression.
193+ *
194+ * @param str the string containing a regular expression
195+ *
196+ * @return the escaped string
197+ */
198+ public static String escapeRegex (String str) {
199+ str = str.replaceAll("\\*", "\\\\*");
200+ str = str.replaceAll("\\.", "\\\\.");
201+ str = str.replaceAll("\\?", "\\\\?");
202+ str = str.replaceAll("\\+", "\\\\+");
203+ //str = str.replaceAll("\\", "\\\\");
204+ str = str.replaceAll("\\$", "\\\\$");
205+ str = str.replaceAll("\\|", "\\\\|");
206+ str = str.replaceAll("\\{", "\\\\{");
207+ str = str.replaceAll("\\}", "\\\\}");
208+ str = str.replaceAll("\\[", "\\\\[");
209+ str = str.replaceAll("\\]", "\\\\]");
210+ return str;
211+ }
212+
213+ /**
214+ * Returns true if and only if the given string contains the specified string, ignoring the case aof each string.
215+ *
216+ * @param in the string to test
217+ * @param contains the string to search for
218+ *
219+ * @return true, if successful
220+ */
221+ public static boolean containsIgnoreCase (String in, String contains) {
222+ return in.toLowerCase().contains(contains.toLowerCase());
223+
224+ }
225+
226+}
227
228=== added directory 'src/de/unigoettingen/sub/commons/util/datasource'
229=== added file 'src/de/unigoettingen/sub/commons/util/datasource/AbstractStructure.java'
230--- src/de/unigoettingen/sub/commons/util/datasource/AbstractStructure.java 1970-01-01 00:00:00 +0000
231+++ src/de/unigoettingen/sub/commons/util/datasource/AbstractStructure.java 2012-05-10 06:45:23 +0000
232@@ -0,0 +1,131 @@
233+/*
234+ * This file is part of the SUB Commons project.
235+ * Visit the websites for more information.
236+ * - http://gdz.sub.uni-goettingen.de
237+ *
238+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
239+ * intranda software.
240+ *
241+ * Licensed under the Apache License, Version 2.0 (the “License”);
242+ * you may not use this file except in compliance with the License.
243+ * You may obtain a copy of the License at
244+ *
245+ * http://www.apache.org/licenses/LICENSE-2.0
246+ *
247+ * Unless required by applicable law or agreed to in writing, software
248+ * distributed under the License is distributed on an “AS IS” BASIS,
249+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
250+ * See the License for the specific language governing permissions and
251+ * limitations under the License.
252+ */
253+package de.unigoettingen.sub.commons.util.datasource;
254+
255+import java.util.ArrayList;
256+import java.util.LinkedList;
257+import java.util.List;
258+
259+public abstract class AbstractStructure <S extends AbstractStructure<S>> implements Structure {
260+ protected List<S> children;
261+ protected Integer imagenumber; // imagenumber, integer from imageURLs HashMap
262+ protected String content; // content of bookmark
263+
264+ /**
265+ * Instantiates a new abstract structure.
266+ */
267+ public AbstractStructure() {
268+ // TODO Auto-generated constructor stub
269+ }
270+
271+ /**
272+ * Instantiates a new abstract structure.
273+ *
274+ * @param struct the struct
275+ */
276+ public AbstractStructure(Structure struct) {
277+ this(struct.getImageNumber(), struct.getContent());
278+ }
279+
280+
281+ /**************************************************************************************
282+ * Constructor which create a new bookmark with pagename and content
283+ *
284+ * @param pagename as Integer
285+ * @param content as String
286+ **************************************************************************************/
287+ public AbstractStructure(Integer pagename, String content) {
288+ this.imagenumber = pagename;
289+ this.content = content;
290+ }
291+
292+ /*************************************************************************************
293+ * Getter for children
294+ *
295+ * @return the children
296+ *************************************************************************************/
297+ public List<S> getChildren() {
298+ if (children != null) {
299+ return children;
300+ } else {
301+ return new LinkedList<S>();
302+ }
303+ }
304+
305+ /**************************************************************************************
306+ * Add bookmark to list of children
307+ *
308+ * @param child the Bookmark to add as child
309+ **************************************************************************************/
310+ public void addChildBookmark(S child) {
311+ if (children == null) { // no list available, create one for all child bookmarks
312+ children = new ArrayList<S>();
313+ }
314+ children.add(child);
315+ }
316+
317+ /**************************************************************************************
318+ * Setter for children
319+ *
320+ * @param children the children to set
321+ **************************************************************************************/
322+ public void setChildren(List<S> children) {
323+ this.children = children;
324+ }
325+
326+
327+ /*************************************************************************************
328+ * Getter for content
329+ *
330+ * @return the content
331+ *************************************************************************************/
332+ public String getContent() {
333+ return content;
334+ }
335+
336+ /*************************************************************************************
337+ * Getter for imagenumber
338+ *
339+ * @return the imagenumber
340+ *************************************************************************************/
341+ public Integer getImageNumber() {
342+ return imagenumber;
343+ }
344+
345+ /**************************************************************************************
346+ * Setter for content
347+ *
348+ * @param content the content to set
349+ **************************************************************************************/
350+ public void setContent(String content) {
351+ this.content = content;
352+ }
353+
354+ /**************************************************************************************
355+ * Setter for imagenumber
356+ *
357+ * @param imagenumber the imagenumber to set
358+ **************************************************************************************/
359+ public void setImageNumber(Integer imagenumber) {
360+ this.imagenumber = imagenumber;
361+ }
362+
363+}
364
365=== added file 'src/de/unigoettingen/sub/commons/util/datasource/AbstractUrlImage.java'
366--- src/de/unigoettingen/sub/commons/util/datasource/AbstractUrlImage.java 1970-01-01 00:00:00 +0000
367+++ src/de/unigoettingen/sub/commons/util/datasource/AbstractUrlImage.java 2012-05-10 06:45:23 +0000
368@@ -0,0 +1,91 @@
369+/*
370+ * This file is part of the SUB Commons project.
371+ * Visit the websites for more information.
372+ * - http://gdz.sub.uni-goettingen.de
373+ *
374+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
375+ * intranda software.
376+ *
377+ * Licensed under the Apache License, Version 2.0 (the “License”);
378+ * you may not use this file except in compliance with the License.
379+ * You may obtain a copy of the License at
380+ *
381+ * http://www.apache.org/licenses/LICENSE-2.0
382+ *
383+ * Unless required by applicable law or agreed to in writing, software
384+ * distributed under the License is distributed on an “AS IS” BASIS,
385+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
386+ * See the License for the specific language governing permissions and
387+ * limitations under the License.
388+ */
389+package de.unigoettingen.sub.commons.util.datasource;
390+
391+import java.awt.image.RenderedImage;
392+import java.io.IOException;
393+import java.io.InputStream;
394+import java.net.URL;
395+
396+public abstract class AbstractUrlImage implements UrlImage {
397+
398+ protected URL url;
399+ protected Integer pagenumber;
400+
401+ /*************************************************************************************
402+ * Getter for pagenumber
403+ *
404+ * @return the pagenumber
405+ *************************************************************************************/
406+ public Integer getPageNumber() {
407+ return pagenumber;
408+ }
409+
410+ /*************************************************************************************
411+ * Getter for url
412+ *
413+ * @return the url
414+ *************************************************************************************/
415+ public URL getURL() {
416+ return url;
417+ }
418+
419+
420+ /**************************************************************************************
421+ * Setter for url
422+ *
423+ * @param url the imageurl to set
424+ **************************************************************************************/
425+ public void setURL(URL imageurl) {
426+ this.url = imageurl;
427+ }
428+
429+ /**************************************************************************************
430+ * Setter for pagenumber
431+ *
432+ * @param pagenumber the pagenumber to set
433+ **************************************************************************************/
434+ public void setPageNumber(Integer pagenumber) {
435+ this.pagenumber = pagenumber;
436+ }
437+
438+ /* (non-Javadoc)
439+ * @see de.unigoettingen.commons.util.datasource.Image#openStream()
440+ */
441+ public InputStream openStream() throws IOException {
442+ if (url == null) {
443+ throw new IllegalStateException("URL is null");
444+ }
445+ return url.openStream();
446+ }
447+
448+ /**
449+ * Get rendered image. (Throws a UnsupportedOperationException)
450+ *
451+ * @see de.unigoettingen.sub.commons.util.datasource.Image#getRenderedImage()
452+ *
453+ * @return the rendered image
454+ */
455+ public RenderedImage getRenderedImage () {
456+ throw new UnsupportedOperationException("Method getRenderedImage() not implemented in AbstractUrlImage!");
457+ }
458+
459+}
460
461=== added file 'src/de/unigoettingen/sub/commons/util/datasource/DataSource.java'
462--- src/de/unigoettingen/sub/commons/util/datasource/DataSource.java 1970-01-01 00:00:00 +0000
463+++ src/de/unigoettingen/sub/commons/util/datasource/DataSource.java 2012-05-10 06:45:23 +0000
464@@ -0,0 +1,44 @@
465+/*
466+ * This file is part of the SUB Commons project.
467+ * Visit the websites for more information.
468+ * - http://gdz.sub.uni-goettingen.de
469+ *
470+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
471+ *
472+ * Licensed under the Apache License, Version 2.0 (the “License”);
473+ * you may not use this file except in compliance with the License.
474+ * You may obtain a copy of the License at
475+ *
476+ * http://www.apache.org/licenses/LICENSE-2.0
477+ *
478+ * Unless required by applicable law or agreed to in writing, software
479+ * distributed under the License is distributed on an “AS IS” BASIS,
480+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
481+ * See the License for the specific language governing permissions and
482+ * limitations under the License.
483+ */
484+package de.unigoettingen.sub.commons.util.datasource;
485+
486+import java.io.IOException;
487+import java.net.URL;
488+
489+// TODO: Auto-generated Javadoc
490+/**
491+ * The Interface DataSource.
492+ */
493+public interface DataSource {
494+
495+ /**
496+ * Gets the URL.
497+ *
498+ * @return the URL
499+ */
500+ abstract URL getUrl ();
501+
502+ /**
503+ * Close.
504+ *
505+ * @throws IOException Signals that an I/O exception has occurred.
506+ */
507+ abstract void close () throws IOException;
508+}
509
510=== added file 'src/de/unigoettingen/sub/commons/util/datasource/DirectoryListingUrlImageSource.java'
511--- src/de/unigoettingen/sub/commons/util/datasource/DirectoryListingUrlImageSource.java 1970-01-01 00:00:00 +0000
512+++ src/de/unigoettingen/sub/commons/util/datasource/DirectoryListingUrlImageSource.java 2012-05-10 06:45:23 +0000
513@@ -0,0 +1,132 @@
514+/*
515+ * This file is part of the SUB Commons project.
516+ * Visit the websites for more information.
517+ * - http://gdz.sub.uni-goettingen.de
518+ *
519+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
520+ * intranda software.
521+ *
522+ * Licensed under the Apache License, Version 2.0 (the “License”);
523+ * you may not use this file except in compliance with the License.
524+ * You may obtain a copy of the License at
525+ *
526+ * http://www.apache.org/licenses/LICENSE-2.0
527+ *
528+ * Unless required by applicable law or agreed to in writing, software
529+ * distributed under the License is distributed on an “AS IS” BASIS,
530+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
531+ * See the License for the specific language governing permissions and
532+ * limitations under the License.
533+ */
534+package de.unigoettingen.sub.commons.util.datasource;
535+
536+import java.io.File;
537+import java.io.IOException;
538+import java.net.MalformedURLException;
539+import java.net.URL;
540+import java.util.ArrayList;
541+import java.util.Arrays;
542+import java.util.List;
543+import java.util.Map;
544+
545+// TODO: Auto-generated Javadoc
546+/**
547+ * The Class DirectoryListingUrlImageSource.
548+ */
549+public class DirectoryListingUrlImageSource implements ImageSource {
550+
551+ /** The dir. */
552+ protected File dir = null;
553+
554+ /** The files. */
555+ private List<File> files = null;
556+
557+ /**
558+ * Instantiates a new directory listing url image source.
559+ *
560+ * @param dir the dir
561+ */
562+ public DirectoryListingUrlImageSource (File dir) {
563+ this.dir = dir;
564+ }
565+
566+ /* (non-Javadoc)
567+ * @see de.unigoettingen.sub.commons.util.datasource.ImageSource#getImage(java.lang.Integer)
568+ */
569+ public Image getImage(Integer pageNr) throws IOException {
570+ init();
571+ SimpleUrlImage img = new SimpleUrlImage();
572+ img.setPageNumber(pageNr);
573+ img.setURL(files.get(pageNr).toURI().toURL());
574+ return img;
575+ }
576+
577+ /* (non-Javadoc)
578+ * @see de.unigoettingen.sub.commons.util.datasource.ImageSource#getImageList()
579+ */
580+ public List<? extends Image> getImageList() throws IOException {
581+ init();
582+ List<SimpleUrlImage> images = new ArrayList<SimpleUrlImage>();
583+ for (int i = 0; i < files.size(); i++) {
584+ SimpleUrlImage img = new SimpleUrlImage();
585+ img.setPageNumber(i + 1);
586+ img.setURL(files.get(i).toURI().toURL());
587+ images.add(img);
588+ }
589+ return images;
590+ }
591+
592+ /* (non-Javadoc)
593+ * @see de.unigoettingen.sub.commons.util.datasource.ImageSource#getImageMap()
594+ */
595+ public Map<Integer, ? extends Image> getImageMap() throws IOException {
596+ // TODO Auto-generated method stub
597+ return null;
598+ }
599+
600+ /* (non-Javadoc)
601+ * @see de.unigoettingen.sub.commons.util.datasource.ImageSource#getNumberOfPages()
602+ */
603+ public Integer getNumberOfPages() {
604+ try {
605+ init();
606+ } catch (IOException e) {
607+ return 0;
608+ }
609+ return files.size();
610+ }
611+
612+ /* (non-Javadoc)
613+ * @see de.unigoettingen.sub.commons.util.datasource.DataSource#close()
614+ */
615+ public void close() throws IOException {
616+ //Do nothing
617+ }
618+
619+ /* (non-Javadoc)
620+ * @see de.unigoettingen.sub.commons.util.datasource.DataSource#getUrl()
621+ */
622+ public URL getUrl() {
623+ try {
624+ return dir.toURI().toURL();
625+ } catch (MalformedURLException e) {
626+ return null;
627+ }
628+ }
629+
630+ /**
631+ * Checks the given directory and add its contens as list
632+ *
633+ * @throws IOException Signals that an I/O exception has occurred.
634+ */
635+ private void init () throws IOException {
636+ if (files == null) {
637+ if (!dir.isDirectory()) {
638+ throw new IOException("Given File is not a directory");
639+ }
640+ files = Arrays.asList(dir.listFiles());
641+ //TODO: Filter for supported Filetypes
642+ }
643+ }
644+
645+}
646
647=== added file 'src/de/unigoettingen/sub/commons/util/datasource/Image.java'
648--- src/de/unigoettingen/sub/commons/util/datasource/Image.java 1970-01-01 00:00:00 +0000
649+++ src/de/unigoettingen/sub/commons/util/datasource/Image.java 2012-05-10 06:45:23 +0000
650@@ -0,0 +1,47 @@
651+/*
652+ * This file is part of the SUB Commons project.
653+ * Visit the websites for more information.
654+ * - http://gdz.sub.uni-goettingen.de
655+ *
656+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
657+ * intranda software.
658+ *
659+ * Licensed under the Apache License, Version 2.0 (the “License”);
660+ * you may not use this file except in compliance with the License.
661+ * You may obtain a copy of the License at
662+ *
663+ * http://www.apache.org/licenses/LICENSE-2.0
664+ *
665+ * Unless required by applicable law or agreed to in writing, software
666+ * distributed under the License is distributed on an “AS IS” BASIS,
667+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
668+ * See the License for the specific language governing permissions and
669+ * limitations under the License.
670+ */
671+package de.unigoettingen.sub.commons.util.datasource;
672+
673+import java.awt.image.RenderedImage;
674+import java.io.IOException;
675+
676+/**
677+ * The Interface Image.
678+ */
679+public interface Image {
680+
681+ /**
682+ * Gets the rendered image.
683+ *
684+ * @return the rendered image
685+ *
686+ * @throws IOException Signals that an I/O exception has occurred.
687+ */
688+ abstract RenderedImage getRenderedImage () throws IOException;
689+
690+ /**
691+ * Gets the page number.
692+ *
693+ * @return the page number
694+ */
695+ abstract Integer getPageNumber ();
696+
697+}
698
699=== added file 'src/de/unigoettingen/sub/commons/util/datasource/ImageSource.java'
700--- src/de/unigoettingen/sub/commons/util/datasource/ImageSource.java 1970-01-01 00:00:00 +0000
701+++ src/de/unigoettingen/sub/commons/util/datasource/ImageSource.java 2012-05-10 06:45:23 +0000
702@@ -0,0 +1,67 @@
703+/*
704+ * This file is part of the SUB Commons project.
705+ * Visit the websites for more information.
706+ * - http://gdz.sub.uni-goettingen.de
707+ *
708+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
709+ *
710+ * Licensed under the Apache License, Version 2.0 (the “License”);
711+ * you may not use this file except in compliance with the License.
712+ * You may obtain a copy of the License at
713+ *
714+ * http://www.apache.org/licenses/LICENSE-2.0
715+ *
716+ * Unless required by applicable law or agreed to in writing, software
717+ * distributed under the License is distributed on an “AS IS” BASIS,
718+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
719+ * See the License for the specific language governing permissions and
720+ * limitations under the License.
721+ */
722+package de.unigoettingen.sub.commons.util.datasource;
723+
724+import java.io.IOException;
725+import java.util.List;
726+import java.util.Map;
727+
728+/**
729+ * The Interface ImageSource.
730+ */
731+public interface ImageSource extends DataSource {
732+
733+ /**
734+ * Gets the image.
735+ *
736+ * @param pageNr the page nr
737+ *
738+ * @return the image
739+ *
740+ * @throws IOException Signals that an I/O exception has occurred.
741+ */
742+ abstract Image getImage (Integer pageNr) throws IOException;
743+
744+ /**
745+ * Gets the images.
746+ *
747+ * @return the images
748+ *
749+ * @throws IOException Signals that an I/O exception has occurred.
750+ */
751+ abstract List<? extends Image> getImageList () throws IOException;
752+
753+ /**
754+ * Gets the images.
755+ *
756+ * @return the images
757+ *
758+ * @throws IOException Signals that an I/O exception has occurred.
759+ */
760+ abstract Map<Integer, ? extends Image> getImageMap () throws IOException;
761+
762+ /**
763+ * Gets the number of pages.
764+ *
765+ * @return the number of pages
766+ */
767+ abstract Integer getNumberOfPages ();
768+
769+}
770
771=== added file 'src/de/unigoettingen/sub/commons/util/datasource/ImageSourceIterator.java'
772--- src/de/unigoettingen/sub/commons/util/datasource/ImageSourceIterator.java 1970-01-01 00:00:00 +0000
773+++ src/de/unigoettingen/sub/commons/util/datasource/ImageSourceIterator.java 2012-05-10 06:45:23 +0000
774@@ -0,0 +1,83 @@
775+/*
776+ * This file is a contribution to the the ContentServer project, mainly for research purposes.
777+ *
778+ * Copyright 2009, Christian Mahnke<cmahnke@gmail.com>.
779+ *
780+ * Licensed under the Apache License, Version 2.0 (the “License”);
781+ * you may not use this file except in compliance with the License.
782+ * You may obtain a copy of the License at
783+ *
784+ * http://www.apache.org/licenses/LICENSE-2.0
785+ *
786+ * Unless required by applicable law or agreed to in writing, software
787+ * distributed under the License is distributed on an “AS IS” BASIS,
788+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
789+ * See the License for the specific language governing permissions and
790+ * limitations under the License.
791+ */
792+
793+package de.unigoettingen.sub.commons.util.datasource;
794+
795+import java.io.IOException;
796+import java.util.Iterator;
797+import java.util.NoSuchElementException;
798+
799+//Avoid logger as external dependency here, try to wrap System.out.* streams
800+//import org.apache.log4j.Logger;
801+
802+public class ImageSourceIterator implements Iterator<Image>, Iterable<Image> {
803+ //protected static Logger logger = Logger.getLogger(ImageSourceIterator.class);
804+
805+ ImageSource is = null;
806+ Integer pageNr = -1;
807+
808+ /**
809+ * Instantiates a new image source iterator.
810+ *
811+ * @param is the ImageSource
812+ */
813+ public ImageSourceIterator(ImageSource is) {
814+ this.is = is;
815+ }
816+
817+ /* (non-Javadoc)
818+ * @see java.util.Iterator#hasNext()
819+ */
820+ public boolean hasNext() {
821+ if (pageNr < is.getNumberOfPages()) {
822+ return true;
823+ }
824+ return false;
825+ }
826+
827+ /* (non-Javadoc)
828+ * @see java.util.Iterator#next()
829+ */
830+ public Image next() {
831+ pageNr++;
832+ if (!hasNext()) {
833+ throw new NoSuchElementException();
834+ }
835+
836+ try {
837+ return is.getImage(pageNr);
838+ } catch (IOException e) {
839+ e.printStackTrace();
840+ return null;
841+ }
842+ }
843+
844+ /* (non-Javadoc)
845+ * @see java.util.Iterator#remove()
846+ */
847+ public void remove() {
848+ throw new UnsupportedOperationException();
849+ }
850+
851+ /* (non-Javadoc)
852+ * @see java.lang.Iterable#iterator()
853+ */
854+ public Iterator<Image> iterator() {
855+ return this;
856+ }
857+}
858
859=== added file 'src/de/unigoettingen/sub/commons/util/datasource/Metadata.java'
860--- src/de/unigoettingen/sub/commons/util/datasource/Metadata.java 1970-01-01 00:00:00 +0000
861+++ src/de/unigoettingen/sub/commons/util/datasource/Metadata.java 2012-05-10 06:45:23 +0000
862@@ -0,0 +1,55 @@
863+/*
864+ * This file is part of the SUB Commons project.
865+ * Visit the websites for more information.
866+ * - http://gdz.sub.uni-goettingen.de
867+ *
868+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
869+ *
870+ * Licensed under the Apache License, Version 2.0 (the “License”);
871+ * you may not use this file except in compliance with the License.
872+ * You may obtain a copy of the License at
873+ *
874+ * http://www.apache.org/licenses/LICENSE-2.0
875+ *
876+ * Unless required by applicable law or agreed to in writing, software
877+ * distributed under the License is distributed on an “AS IS” BASIS,
878+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
879+ * See the License for the specific language governing permissions and
880+ * limitations under the License.
881+ */
882+package de.unigoettingen.sub.commons.util.datasource;
883+
884+// TODO: Auto-generated Javadoc
885+/**
886+ * The Interface Metadata.
887+ */
888+public interface Metadata {
889+
890+ /**
891+ * Gets the title.
892+ *
893+ * @return the title
894+ */
895+ abstract String getTitle();
896+
897+ /**
898+ * Gets the creator.
899+ *
900+ * @return the creator
901+ */
902+ abstract String getCreator();
903+
904+ /**
905+ * Gets the keywords.
906+ *
907+ * @return the keywords
908+ */
909+ abstract String getKeywords();
910+
911+ /**
912+ * Gets the subject.
913+ *
914+ * @return the subject
915+ */
916+ abstract String getSubject();
917+}
918
919=== added file 'src/de/unigoettingen/sub/commons/util/datasource/MetadataSource.java'
920--- src/de/unigoettingen/sub/commons/util/datasource/MetadataSource.java 1970-01-01 00:00:00 +0000
921+++ src/de/unigoettingen/sub/commons/util/datasource/MetadataSource.java 2012-05-10 06:45:23 +0000
922@@ -0,0 +1,38 @@
923+/*
924+ * This file is part of the SUB Commons project.
925+ * Visit the websites for more information.
926+ * - http://gdz.sub.uni-goettingen.de
927+ *
928+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
929+ *
930+ * Licensed under the Apache License, Version 2.0 (the “License”);
931+ * you may not use this file except in compliance with the License.
932+ * You may obtain a copy of the License at
933+ *
934+ * http://www.apache.org/licenses/LICENSE-2.0
935+ *
936+ * Unless required by applicable law or agreed to in writing, software
937+ * distributed under the License is distributed on an “AS IS” BASIS,
938+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
939+ * See the License for the specific language governing permissions and
940+ * limitations under the License.
941+ */
942+package de.unigoettingen.sub.commons.util.datasource;
943+
944+import java.util.List;
945+
946+// TODO: Auto-generated Javadoc
947+/**
948+ * The Interface MetadataSource.
949+ */
950+public interface MetadataSource extends DataSource {
951+
952+ /**
953+ * Gets the metadata.
954+ *
955+ * @return the metadata
956+ */
957+ abstract List<Metadata> getMetadata ();
958+
959+
960+}
961
962=== added file 'src/de/unigoettingen/sub/commons/util/datasource/SimpleStructure.java'
963--- src/de/unigoettingen/sub/commons/util/datasource/SimpleStructure.java 1970-01-01 00:00:00 +0000
964+++ src/de/unigoettingen/sub/commons/util/datasource/SimpleStructure.java 2012-05-10 06:45:23 +0000
965@@ -0,0 +1,41 @@
966+/*
967+ * This file is part of the SUB Commons project.
968+ * Visit the websites for more information.
969+ * - http://gdz.sub.uni-goettingen.de
970+ *
971+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
972+ *
973+ * Licensed under the Apache License, Version 2.0 (the “License”);
974+ * you may not use this file except in compliance with the License.
975+ * You may obtain a copy of the License at
976+ *
977+ * http://www.apache.org/licenses/LICENSE-2.0
978+ *
979+ * Unless required by applicable law or agreed to in writing, software
980+ * distributed under the License is distributed on an “AS IS” BASIS,
981+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
982+ * See the License for the specific language governing permissions and
983+ * limitations under the License.
984+ */
985+package de.unigoettingen.sub.commons.util.datasource;
986+
987+public class SimpleStructure extends AbstractStructure<SimpleStructure> {
988+
989+ /**
990+ * Instantiates a new simple structure.
991+ */
992+ public SimpleStructure() {
993+
994+ }
995+
996+ /**************************************************************************************
997+ * Constructor which create a new bookmark with pagename and content
998+ *
999+ * @param pagename as Integer
1000+ * @param content as String
1001+ **************************************************************************************/
1002+ public SimpleStructure(Integer pagename, String content) {
1003+ super(pagename, content);
1004+ }
1005+
1006+}
1007
1008=== added file 'src/de/unigoettingen/sub/commons/util/datasource/SimpleUrlImage.java'
1009--- src/de/unigoettingen/sub/commons/util/datasource/SimpleUrlImage.java 1970-01-01 00:00:00 +0000
1010+++ src/de/unigoettingen/sub/commons/util/datasource/SimpleUrlImage.java 2012-05-10 06:45:23 +0000
1011@@ -0,0 +1,63 @@
1012+/*
1013+ * This file is part of the SUB Commons project.
1014+ * Visit the websites for more information.
1015+ * - http://gdz.sub.uni-goettingen.de
1016+ *
1017+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
1018+ *
1019+ * Licensed under the Apache License, Version 2.0 (the “License”);
1020+ * you may not use this file except in compliance with the License.
1021+ * You may obtain a copy of the License at
1022+ *
1023+ * http://www.apache.org/licenses/LICENSE-2.0
1024+ *
1025+ * Unless required by applicable law or agreed to in writing, software
1026+ * distributed under the License is distributed on an “AS IS” BASIS,
1027+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1028+ * See the License for the specific language governing permissions and
1029+ * limitations under the License.
1030+ */
1031+package de.unigoettingen.sub.commons.util.datasource;
1032+
1033+import java.net.URL;
1034+
1035+public class SimpleUrlImage extends AbstractUrlImage implements UrlImage {
1036+
1037+ /**
1038+ * Instantiates a new simple url image.
1039+ *
1040+ * @param pageNumber the page number
1041+ * @param url the url
1042+ */
1043+ public SimpleUrlImage (Integer pageNumber, URL url) {
1044+ this.pagenumber = pageNumber;
1045+ this.url = url;
1046+ }
1047+
1048+ /**
1049+ * Instantiates a new simple url image.
1050+ */
1051+ public SimpleUrlImage () {
1052+
1053+ }
1054+
1055+ /**************************************************************************************
1056+ * Setter for url
1057+ *
1058+ * @param url the imageurl to set
1059+ **************************************************************************************/
1060+ public void setURL(URL imageurl) {
1061+ this.url = imageurl;
1062+ }
1063+
1064+ /**************************************************************************************
1065+ * Setter for pdfpagenumber
1066+ *
1067+ * @param pagenumber the pdfpagenumber to set
1068+ **************************************************************************************/
1069+ public void setPageNumber(Integer pagenumber) {
1070+ this.pagenumber = pagenumber;
1071+ }
1072+
1073+
1074+}
1075
1076=== added file 'src/de/unigoettingen/sub/commons/util/datasource/Structure.java'
1077--- src/de/unigoettingen/sub/commons/util/datasource/Structure.java 1970-01-01 00:00:00 +0000
1078+++ src/de/unigoettingen/sub/commons/util/datasource/Structure.java 2012-05-10 06:45:23 +0000
1079@@ -0,0 +1,51 @@
1080+/*
1081+ * This file is part of the SUB Commons project.
1082+ * Visit the websites for more information.
1083+ * - http://gdz.sub.uni-goettingen.de
1084+ *
1085+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
1086+ * intranda software.
1087+ *
1088+ * Licensed under the Apache License, Version 2.0 (the “License”);
1089+ * you may not use this file except in compliance with the License.
1090+ * You may obtain a copy of the License at
1091+ *
1092+ * http://www.apache.org/licenses/LICENSE-2.0
1093+ *
1094+ * Unless required by applicable law or agreed to in writing, software
1095+ * distributed under the License is distributed on an “AS IS” BASIS,
1096+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1097+ * See the License for the specific language governing permissions and
1098+ * limitations under the License.
1099+ */
1100+package de.unigoettingen.sub.commons.util.datasource;
1101+
1102+import java.util.List;
1103+
1104+// TODO: Auto-generated Javadoc
1105+/**
1106+ * The Interface Structure.
1107+ */
1108+public interface Structure {
1109+
1110+ /**
1111+ * Gets the image number.
1112+ *
1113+ * @return the image number
1114+ */
1115+ abstract Integer getImageNumber ();
1116+
1117+ /**
1118+ * Gets the content.
1119+ *
1120+ * @return the content
1121+ */
1122+ abstract String getContent ();
1123+
1124+ /**
1125+ * Gets the children.
1126+ *
1127+ * @return the children
1128+ */
1129+ abstract List<? extends Structure> getChildren ();
1130+}
1131
1132=== added file 'src/de/unigoettingen/sub/commons/util/datasource/StructureDumper.java'
1133--- src/de/unigoettingen/sub/commons/util/datasource/StructureDumper.java 1970-01-01 00:00:00 +0000
1134+++ src/de/unigoettingen/sub/commons/util/datasource/StructureDumper.java 2012-05-10 06:45:23 +0000
1135@@ -0,0 +1,74 @@
1136+/*
1137+ * This file is a contribution to the the ContentServer project, mainly for research purposes.
1138+ *
1139+ * Copyright 2009, Christian Mahnke<cmahnke@gmail.com>.
1140+ *
1141+ * Licensed under the Apache License, Version 2.0 (the “License”);
1142+ * you may not use this file except in compliance with the License.
1143+ * You may obtain a copy of the License at
1144+ *
1145+ * http://www.apache.org/licenses/LICENSE-2.0
1146+ *
1147+ * Unless required by applicable law or agreed to in writing, software
1148+ * distributed under the License is distributed on an “AS IS” BASIS,
1149+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1150+ * See the License for the specific language governing permissions and
1151+ * limitations under the License.
1152+ */
1153+
1154+package de.unigoettingen.sub.commons.util.datasource;
1155+
1156+import java.util.ArrayList;
1157+import java.util.List;
1158+
1159+/**
1160+ * The Class StructureDumper. A simple class for tests and debugging.
1161+ */
1162+public class StructureDumper {
1163+
1164+ /** The struct. */
1165+ List<Structure> structList = null;
1166+
1167+
1168+ public StructureDumper (Structure struct) {
1169+ structList = new ArrayList<Structure>();
1170+ structList.add(struct);
1171+ }
1172+
1173+
1174+ @SuppressWarnings("unchecked")
1175+ public StructureDumper (StructureSource structSource) {
1176+ this.structList = (List<Structure>) structSource.getStructureList();
1177+ }
1178+
1179+
1180+ /**
1181+ * Dump.
1182+ */
1183+ public void dump () {
1184+ for (Structure struct: structList) {
1185+ System.out.println("ROOT: " + struct.getContent());
1186+ dump(struct, 1);
1187+ }
1188+ }
1189+
1190+ /**
1191+ * Dump.
1192+ *
1193+ * @param struct the struct
1194+ * @param level the level
1195+ */
1196+ protected void dump (Structure struct, Integer level) {
1197+ for (Structure child: struct.getChildren()) {
1198+ StringBuffer ident = new StringBuffer();
1199+ for (int i = 0; i < level; i++) {
1200+ ident.append(" ");
1201+ }
1202+ System.out.println(ident.toString() + "+ " + child.getContent());
1203+ if (struct.getChildren().size() != 0) {
1204+ dump(struct, level + 1);
1205+ }
1206+ }
1207+ }
1208+
1209+}
1210
1211=== added file 'src/de/unigoettingen/sub/commons/util/datasource/StructureSource.java'
1212--- src/de/unigoettingen/sub/commons/util/datasource/StructureSource.java 1970-01-01 00:00:00 +0000
1213+++ src/de/unigoettingen/sub/commons/util/datasource/StructureSource.java 2012-05-10 06:45:23 +0000
1214@@ -0,0 +1,37 @@
1215+/*
1216+ * This file is part of the SUB Commons project.
1217+ * Visit the websites for more information.
1218+ * - http://gdz.sub.uni-goettingen.de
1219+ *
1220+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
1221+ *
1222+ * Licensed under the Apache License, Version 2.0 (the “License”);
1223+ * you may not use this file except in compliance with the License.
1224+ * You may obtain a copy of the License at
1225+ *
1226+ * http://www.apache.org/licenses/LICENSE-2.0
1227+ *
1228+ * Unless required by applicable law or agreed to in writing, software
1229+ * distributed under the License is distributed on an “AS IS” BASIS,
1230+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1231+ * See the License for the specific language governing permissions and
1232+ * limitations under the License.
1233+ */
1234+package de.unigoettingen.sub.commons.util.datasource;
1235+
1236+import java.util.List;
1237+
1238+// TODO: Auto-generated Javadoc
1239+/**
1240+ * The Interface StructureSource.
1241+ */
1242+public interface StructureSource extends DataSource {
1243+
1244+
1245+ /**
1246+ * Gets the structure list.
1247+ *
1248+ * @return the structure list
1249+ */
1250+ abstract List<? extends Structure> getStructureList ();
1251+}
1252
1253=== added file 'src/de/unigoettingen/sub/commons/util/datasource/TextSource.java'
1254--- src/de/unigoettingen/sub/commons/util/datasource/TextSource.java 1970-01-01 00:00:00 +0000
1255+++ src/de/unigoettingen/sub/commons/util/datasource/TextSource.java 2012-05-10 06:45:23 +0000
1256@@ -0,0 +1,24 @@
1257+/*
1258+ * This file is a contribution to the the ContentServer project, mainly for research purposes.
1259+ *
1260+ * Copyright 2009, Christian Mahnke<cmahnke@gmail.com>.
1261+ *
1262+ * Licensed under the Apache License, Version 2.0 (the “License”);
1263+ * you may not use this file except in compliance with the License.
1264+ * You may obtain a copy of the License at
1265+ *
1266+ * http://www.apache.org/licenses/LICENSE-2.0
1267+ *
1268+ * Unless required by applicable law or agreed to in writing, software
1269+ * distributed under the License is distributed on an “AS IS” BASIS,
1270+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1271+ * See the License for the specific language governing permissions and
1272+ * limitations under the License.
1273+ */
1274+
1275+package de.unigoettingen.sub.commons.util.datasource;
1276+
1277+public interface TextSource extends DataSource {
1278+
1279+ //TODO: for now just a marker interface, needed later for fulltext handling
1280+}
1281
1282=== added file 'src/de/unigoettingen/sub/commons/util/datasource/UrlImage.java'
1283--- src/de/unigoettingen/sub/commons/util/datasource/UrlImage.java 1970-01-01 00:00:00 +0000
1284+++ src/de/unigoettingen/sub/commons/util/datasource/UrlImage.java 2012-05-10 06:45:23 +0000
1285@@ -0,0 +1,51 @@
1286+/*
1287+ * This file is part of the SUB Commons project.
1288+ * Visit the websites for more information.
1289+ * - http://gdz.sub.uni-goettingen.de
1290+ *
1291+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
1292+ * intranda software.
1293+ *
1294+ * Licensed under the Apache License, Version 2.0 (the “License”);
1295+ * you may not use this file except in compliance with the License.
1296+ * You may obtain a copy of the License at
1297+ *
1298+ * http://www.apache.org/licenses/LICENSE-2.0
1299+ *
1300+ * Unless required by applicable law or agreed to in writing, software
1301+ * distributed under the License is distributed on an “AS IS” BASIS,
1302+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1303+ * See the License for the specific language governing permissions and
1304+ * limitations under the License.
1305+ */
1306+package de.unigoettingen.sub.commons.util.datasource;
1307+
1308+import java.io.IOException;
1309+import java.io.InputStream;
1310+import java.net.URL;
1311+
1312+public interface UrlImage extends Image {
1313+ /**
1314+ * Gets the URL.
1315+ *
1316+ * @return the URL
1317+ */
1318+ abstract URL getURL ();
1319+
1320+
1321+ /**
1322+ * Setter for url
1323+ *
1324+ * @param url the imageurl to set
1325+ */
1326+ public void setURL(URL url);
1327+
1328+ /**
1329+ * Open stream.
1330+ *
1331+ * @return the input stream
1332+ *
1333+ * @throws IOException Signals that an I/O exception has occurred.
1334+ */
1335+ abstract InputStream openStream() throws IOException;
1336+}
1337
1338=== added file 'src/de/unigoettingen/sub/commons/util/datasource/WrappedImage.java'
1339--- src/de/unigoettingen/sub/commons/util/datasource/WrappedImage.java 1970-01-01 00:00:00 +0000
1340+++ src/de/unigoettingen/sub/commons/util/datasource/WrappedImage.java 2012-05-10 06:45:23 +0000
1341@@ -0,0 +1,61 @@
1342+/*
1343+ * This file is a contribution to the the ContentServer project, mainly for research purposes.
1344+ *
1345+ * Copyright 2009, Christian Mahnke<cmahnke@gmail.com>.
1346+ *
1347+ * Licensed under the Apache License, Version 2.0 (the “License”);
1348+ * you may not use this file except in compliance with the License.
1349+ * You may obtain a copy of the License at
1350+ *
1351+ * http://www.apache.org/licenses/LICENSE-2.0
1352+ *
1353+ * Unless required by applicable law or agreed to in writing, software
1354+ * distributed under the License is distributed on an “AS IS” BASIS,
1355+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1356+ * See the License for the specific language governing permissions and
1357+ * limitations under the License.
1358+ */
1359+
1360+
1361+package de.unigoettingen.sub.commons.util.datasource;
1362+
1363+import java.awt.image.RenderedImage;
1364+import java.io.IOException;
1365+
1366+/**
1367+ * The Class WrappedImage is a simple wrapper for java.awt.image.RenderedImage instances.
1368+ */
1369+public class WrappedImage implements Image {
1370+
1371+ /** The page nr. */
1372+ protected Integer pageNr = -1;
1373+
1374+ /** The image. */
1375+ protected RenderedImage image = null;
1376+
1377+ /**
1378+ * Instantiates a new wrapped image.
1379+ *
1380+ * @param pagenr the page number
1381+ * @param image the RenderedImage
1382+ */
1383+ public WrappedImage (Integer pagenr, RenderedImage image) {
1384+ this.pageNr = pagenr;
1385+ this.image = image;
1386+ }
1387+
1388+ /* (non-Javadoc)
1389+ * @see de.unigoettingen.sub.commons.util.datasource.Image#getPageNumber()
1390+ */
1391+ public Integer getPageNumber() {
1392+ return pageNr;
1393+ }
1394+
1395+ /* (non-Javadoc)
1396+ * @see de.unigoettingen.sub.commons.util.datasource.Image#getRenderedImage()
1397+ */
1398+ public RenderedImage getRenderedImage() throws IOException {
1399+ return image;
1400+ }
1401+
1402+}
1403
1404=== added directory 'src/de/unigoettingen/sub/commons/util/file'
1405=== added file 'src/de/unigoettingen/sub/commons/util/file/FileExtensionsFilter.java'
1406--- src/de/unigoettingen/sub/commons/util/file/FileExtensionsFilter.java 1970-01-01 00:00:00 +0000
1407+++ src/de/unigoettingen/sub/commons/util/file/FileExtensionsFilter.java 2012-05-10 06:45:23 +0000
1408@@ -0,0 +1,114 @@
1409+/*
1410+ * This file is part of the SUB Commons project.
1411+ * Visit the websites for more information.
1412+ * - http://gdz.sub.uni-goettingen.de
1413+ *
1414+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
1415+ *
1416+ * Licensed under the Apache License, Version 2.0 (the “License”);
1417+ * you may not use this file except in compliance with the License.
1418+ * You may obtain a copy of the License at
1419+ *
1420+ * http://www.apache.org/licenses/LICENSE-2.0
1421+ *
1422+ * Unless required by applicable law or agreed to in writing, software
1423+ * distributed under the License is distributed on an “AS IS” BASIS,
1424+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1425+ * See the License for the specific language governing permissions and
1426+ * limitations under the License.
1427+ */
1428+package de.unigoettingen.sub.commons.util.file;
1429+
1430+import java.io.File;
1431+import java.io.FileFilter;
1432+import java.util.ArrayList;
1433+import java.util.List;
1434+
1435+
1436+//TODO: This is guaranted to work case insensive only if you add extensions as String
1437+/**
1438+ * The Class FileExtensionsFilter implements a FileFilter. It can be used to filter files based on their extensions.
1439+ */
1440+public class FileExtensionsFilter implements FileFilter {
1441+
1442+ /** The extension. */
1443+ protected List<String> extensions = new ArrayList<String>();
1444+
1445+ /**
1446+ * Instantiates a new file extensions filter.
1447+ *
1448+ * @param extension the extension
1449+ */
1450+ public FileExtensionsFilter (String extension) {
1451+ this.extensions.add(extension.toLowerCase());
1452+ }
1453+
1454+ /**
1455+ * Instantiates a new file extensions filter.
1456+ *
1457+ * @param extensions the extensions
1458+ */
1459+ public FileExtensionsFilter (List<String> extensions) {
1460+ this.extensions = extensions;
1461+ };
1462+
1463+ /**
1464+ * Adds the extension.
1465+ *
1466+ * @param extension the extension
1467+ */
1468+ public void addExtension (String extension) {
1469+ this.extensions.add(extension.toLowerCase());
1470+ }
1471+
1472+ /**
1473+ * Sets the extension.
1474+ *
1475+ * @param extensions the new extension
1476+ */
1477+ public void setExtension (List<String> extensions) {
1478+ this.extensions = extensions;
1479+ }
1480+
1481+ /**
1482+ * Gets the extensions.
1483+ *
1484+ * @return the extensions
1485+ */
1486+ public List<String> getExtensions () {
1487+ return extensions;
1488+ }
1489+
1490+ /* (non-Javadoc)
1491+ * @see java.io.FileFilter#accept(java.io.File)
1492+ */
1493+ public boolean accept (File pathname) {
1494+ if (extensions.contains(FileUtils.getFileExtensionFromFile(pathname).toLowerCase())) {
1495+ return true;
1496+ }
1497+ return false;
1498+ }
1499+
1500+ /**
1501+ * Utility Method to get the extension of a file
1502+ *
1503+ * @param file the file
1504+ *
1505+ * @return the extension
1506+ */
1507+ public static String getExtension(String file) {
1508+ return file.substring(file.lastIndexOf(".") + 1).toLowerCase();
1509+ }
1510+
1511+ /**
1512+ * Utility Method to get the extension of a file
1513+ *
1514+ * @param file the file
1515+ *
1516+ * @return the extension
1517+ */
1518+ public static String getExtension(File file) {
1519+ return file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf(".") + 1).toLowerCase();
1520+ }
1521+
1522+}
1523
1524=== added file 'src/de/unigoettingen/sub/commons/util/file/FileUtils.java'
1525--- src/de/unigoettingen/sub/commons/util/file/FileUtils.java 1970-01-01 00:00:00 +0000
1526+++ src/de/unigoettingen/sub/commons/util/file/FileUtils.java 2012-05-10 06:45:23 +0000
1527@@ -0,0 +1,274 @@
1528+/*
1529+ * This file is part of the SUB Commons project.
1530+ * Visit the websites for more information.
1531+ * - http://gdz.sub.uni-goettingen.de
1532+ * - http://www.intranda.com
1533+ *
1534+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
1535+ * intranda software.
1536+ *
1537+ * Licensed under the Apache License, Version 2.0 (the “License”);
1538+ * you may not use this file except in compliance with the License.
1539+ * You may obtain a copy of the License at
1540+ *
1541+ * http://www.apache.org/licenses/LICENSE-2.0
1542+ *
1543+ * Unless required by applicable law or agreed to in writing, software
1544+ * distributed under the License is distributed on an “AS IS” BASIS,
1545+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1546+ * See the License for the specific language governing permissions and
1547+ * limitations under the License.
1548+ */
1549+package de.unigoettingen.sub.commons.util.file;
1550+
1551+import java.io.File;
1552+import java.io.FileInputStream;
1553+import java.io.FileOutputStream;
1554+import java.io.FilenameFilter;
1555+import java.io.IOException;
1556+import java.io.InputStream;
1557+import java.io.OutputStream;
1558+import java.util.ArrayList;
1559+import java.util.Arrays;
1560+import java.util.Collections;
1561+import java.util.List;
1562+
1563+
1564+/**
1565+ * The Class FileUtils provides some utilities for file handling
1566+ */
1567+public class FileUtils {
1568+
1569+ protected static Integer copyBufferSize = 4096;
1570+
1571+ /**
1572+ *
1573+ * Gets the file extension from file name.
1574+ *
1575+ * @param inFileName
1576+ * the file name as String
1577+ *
1578+ * @return the file extension from file name as String
1579+ */
1580+ public static String getFileExtensionFromFileName(String inFileName) {
1581+ int dotPos = inFileName.lastIndexOf(".") + 1;
1582+ String extension = inFileName.substring(dotPos).trim();
1583+ return extension;
1584+ }
1585+
1586+ /**
1587+ * Gets the file extension from a File as String.
1588+ *
1589+ * @param inFile
1590+ * the File
1591+ *
1592+ * @return the file extension from inFile as String
1593+ */
1594+ public static String getFileExtensionFromFile(File inFile) {
1595+ return getFileExtensionFromFileName(inFile.getAbsolutePath());
1596+ }
1597+
1598+ /**
1599+ * calculate all files with given file extension at specified directory
1600+ * recursivly.
1601+ *
1602+ * @param inDir
1603+ * the directory to run through
1604+ * @param ext
1605+ * the file extension to use for counting, not case sensitive
1606+ *
1607+ * @return number of files as Integer
1608+ *
1609+ * @author Steffen Hankiewicz
1610+ */
1611+ public static Integer getNumberOfFiles(File inDir, final String ext) {
1612+ int count = 0;
1613+ if (inDir.isDirectory()) {
1614+ // Count the images
1615+ FilenameFilter filter = new FilenameFilter() {
1616+ public boolean accept(File dir, String name) {
1617+ return name.toLowerCase().endsWith(ext.toLowerCase());
1618+ }
1619+ };
1620+ count = inDir.list(filter).length;
1621+
1622+ // Count the contents of sub directories
1623+ String[] children = inDir.list();
1624+ for (int i = 0; i < children.length; i++) {
1625+ count += getNumberOfFiles(new File(inDir, children[i]), ext);
1626+ }
1627+ }
1628+ return count;
1629+ }
1630+
1631+ /**
1632+ * calculate all files with given file extension at specified directory
1633+ * recursivly.
1634+ *
1635+ * @param inDir
1636+ * the directory to run through
1637+ * @param ext
1638+ * the file extension to use for counting, not case sensitive
1639+ *
1640+ * @return number of files as Integer
1641+ *
1642+ * @author Steffen Hankiewicz
1643+ */
1644+ public static Integer getNumberOfFiles(String inDir, final String ext) {
1645+ return getNumberOfFiles(new File(inDir), ext);
1646+ }
1647+
1648+ /**
1649+ * The Class FileListFilter can be used to filter Files usinf a regular
1650+ * expression
1651+ */
1652+ public static class FileListFilter implements FilenameFilter {
1653+
1654+ /** The name. */
1655+ private String name;
1656+
1657+ /**
1658+ * Instantiates a new file list filter.
1659+ *
1660+ * @param name
1661+ * the name
1662+ */
1663+ public FileListFilter(String name) {
1664+ this.name = name;
1665+ }
1666+
1667+ /*
1668+ * (non-Javadoc)
1669+ *
1670+ * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
1671+ */
1672+ public boolean accept(File directory, String filename) {
1673+ boolean fileOK = true;
1674+ if (name != null) {
1675+ fileOK &= filename.matches(name);
1676+ }
1677+ return fileOK;
1678+ }
1679+ }
1680+
1681+ /**
1682+ * Deletes all files and subdirectories under dir. Returns true if all
1683+ * deletions were successful. If a deletion fails, the method stops
1684+ * attempting to delete and returns false.
1685+ *
1686+ * @param dir
1687+ * the directory to delete
1688+ *
1689+ * @return true, if directory deleted or it doesn't exists
1690+ */
1691+ public static boolean deleteDir(File dir) {
1692+ if (!dir.exists()) {
1693+ return true;
1694+ }
1695+ if (!deleteInDir(dir)) {
1696+ return false;
1697+ }
1698+ // The directory is now empty so delete it
1699+ return dir.delete();
1700+ }
1701+
1702+ /**
1703+ * Deletes all files and subdirectories under dir. But not the dir itself
1704+ *
1705+ * @param dir
1706+ * the directory, which contents should be deleted
1707+ *
1708+ * @return true, if contents directory are deleted
1709+ */
1710+ public static boolean deleteInDir(File dir) {
1711+ if (dir.exists() && dir.isDirectory()) {
1712+ String[] children = dir.list();
1713+ for (int i = 0; i < children.length; i++) {
1714+ if (!deleteDir(new File(dir, children[i]))) {
1715+ return false;
1716+ }
1717+ }
1718+ }
1719+ return true;
1720+ }
1721+
1722+ /**
1723+ * Make a File List for a given File (non recursive).
1724+ * @author cmahnke
1725+ * @param inputFile the input file
1726+ * @param filter the filter
1727+ * @return the list
1728+ */
1729+ public static List<File> makeFileList(File inputFile, String filter) {
1730+ List<File> fileList;
1731+ if (inputFile.isDirectory()) {
1732+
1733+
1734+ File files[] = inputFile.listFiles(new FileExtensionsFilter(filter));
1735+ fileList = Arrays.asList(files);
1736+ Collections.sort(fileList);
1737+
1738+ } else {
1739+ fileList = new ArrayList<File>();
1740+ fileList.add(inputFile);
1741+ }
1742+ return fileList;
1743+ }
1744+
1745+ /**
1746+ * Gets the extension of a given file.
1747+ *
1748+ * @param file the File
1749+ * @return the extension
1750+ * @author cmahnke
1751+ */
1752+ public static String getExtension(String file) {
1753+ if (file.contains(".")) {
1754+ return file.substring(file.lastIndexOf(".") + 1).toLowerCase();
1755+ } else {
1756+ return "";
1757+ }
1758+ }
1759+
1760+ /**
1761+ * Copy directory using a simple static method which can copy local directories and files.
1762+ * Returns true if the file or directory could be copied, returns false if the target directory
1763+ * doesn't exists and can't be created.
1764+ *
1765+ * @param srcPath the src path
1766+ * @param dstPath the dst path
1767+ * @throws IOException Signals that an I/O exception has occurred.
1768+ */
1769+ public static boolean copyDirectory (File srcPath, File dstPath) throws IOException {
1770+ if (srcPath.isDirectory()) {
1771+ if (!dstPath.exists() && dstPath.mkdir()) {
1772+ return false;
1773+ }
1774+
1775+ String files[] = srcPath.list();
1776+ for (int i = 0; i < files.length; i++) {
1777+ copyDirectory(new File(srcPath, files[i]), new File(dstPath, files[i]));
1778+ }
1779+ } else {
1780+ if (!srcPath.exists()) {
1781+ System.out.println("File or directory does not exist.");
1782+ System.exit(0);
1783+ } else {
1784+ InputStream in = new FileInputStream(srcPath);
1785+ OutputStream out = new FileOutputStream(dstPath);
1786+
1787+ // Transfer bytes from in to out
1788+ byte[] buf = new byte[copyBufferSize];
1789+ int len;
1790+ while ((len = in.read(buf)) > 0) {
1791+ out.write(buf, 0, len);
1792+ }
1793+ in.close();
1794+ out.close();
1795+ }
1796+ }
1797+ return true;
1798+ //System.out.println("Directory copied.");
1799+ }
1800+
1801+}
1802
1803=== added directory 'src/de/unigoettingen/sub/commons/util/stream'
1804=== added file 'src/de/unigoettingen/sub/commons/util/stream/SimpleInputStreamSaver.java'
1805--- src/de/unigoettingen/sub/commons/util/stream/SimpleInputStreamSaver.java 1970-01-01 00:00:00 +0000
1806+++ src/de/unigoettingen/sub/commons/util/stream/SimpleInputStreamSaver.java 2012-05-10 06:45:23 +0000
1807@@ -0,0 +1,123 @@
1808+/*
1809+ * This file is part of the SUB Commons project.
1810+ * Visit the websites for more information.
1811+ * - http://gdz.sub.uni-goettingen.de
1812+ *
1813+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
1814+ *
1815+ * Licensed under the Apache License, Version 2.0 (the “License”);
1816+ * you may not use this file except in compliance with the License.
1817+ * You may obtain a copy of the License at
1818+ *
1819+ * http://www.apache.org/licenses/LICENSE-2.0
1820+ *
1821+ * Unless required by applicable law or agreed to in writing, software
1822+ * distributed under the License is distributed on an “AS IS” BASIS,
1823+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1824+ * See the License for the specific language governing permissions and
1825+ * limitations under the License.
1826+ */
1827+
1828+package de.unigoettingen.sub.commons.util.stream;
1829+
1830+import java.io.BufferedInputStream;
1831+import java.io.File;
1832+import java.io.FileOutputStream;
1833+import java.io.IOException;
1834+import java.io.InputStream;
1835+
1836+
1837+/**
1838+ * The Class SimpleInputStreamSaver provides a simple way to save the contents of an InputSream in a File.
1839+ */
1840+public class SimpleInputStreamSaver {
1841+
1842+ /** The file. */
1843+ File file;
1844+
1845+ /** The is. */
1846+ InputStream is;
1847+
1848+ /**
1849+ * Instantiates a new simple input stream saver.
1850+ */
1851+ public SimpleInputStreamSaver () {
1852+
1853+ }
1854+
1855+ /**
1856+ * Instantiates a new simple input stream saver.
1857+ *
1858+ * @param file the file to the the contents to.
1859+ * @param is the InputStream to save
1860+ */
1861+ public SimpleInputStreamSaver (File file, InputStream is) {
1862+ this.file = file;
1863+ this.is = is;
1864+ }
1865+
1866+ /**
1867+ * Safe the contents of the stream
1868+ *
1869+ * @throws IOException Signals that an I/O exception has occurred.
1870+ */
1871+ public void safe () throws IOException {
1872+ BufferedInputStream bis = new BufferedInputStream(is);
1873+ FileOutputStream fos = new FileOutputStream(file);
1874+ try {
1875+ int bufSize = 1024 * 8;
1876+ byte[] bytes = new byte[bufSize];
1877+ int count = bis.read(bytes);
1878+ while (count != -1 && count <= bufSize) {
1879+ fos.write(bytes, 0, count);
1880+ count = bis.read(bytes);
1881+ }
1882+ if (count != -1) {
1883+ fos.write(bytes, 0, count);
1884+ }
1885+ fos.close();
1886+ } finally {
1887+ bis.close();
1888+ fos.close();
1889+ }
1890+ }
1891+
1892+ /**
1893+ * Gets the file.
1894+ *
1895+ * @return the file
1896+ */
1897+ public File getFile() {
1898+ return file;
1899+ }
1900+
1901+ /**
1902+ * Sets the file.
1903+ *
1904+ * @param file the new file
1905+ */
1906+ public void setFile(File file) {
1907+ this.file = file;
1908+ }
1909+
1910+ /**
1911+ * Gets the InputStream.
1912+ *
1913+ * @return the InputStream.
1914+ */
1915+ public InputStream getIs() {
1916+ return is;
1917+ }
1918+
1919+ /**
1920+ * Sets the InputStream.
1921+ *
1922+ * @param is the InputStream.
1923+ */
1924+ public void setIs(InputStream is) {
1925+ this.is = is;
1926+ }
1927+
1928+
1929+
1930+}
1931
1932=== added file 'src/de/unigoettingen/sub/commons/util/stream/StreamUtils.java'
1933--- src/de/unigoettingen/sub/commons/util/stream/StreamUtils.java 1970-01-01 00:00:00 +0000
1934+++ src/de/unigoettingen/sub/commons/util/stream/StreamUtils.java 2012-05-10 06:45:23 +0000
1935@@ -0,0 +1,209 @@
1936+/*
1937+ * This file is part of the SUB Commons project.
1938+ * Visit the websites for more information.
1939+ * - http://gdz.sub.uni-goettingen.de
1940+ * - http://www.intranda.com
1941+ *
1942+ * Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
1943+ * intranda software.
1944+ *
1945+ * Licensed under the Apache License, Version 2.0 (the “License”);
1946+ * you may not use this file except in compliance with the License.
1947+ * You may obtain a copy of the License at
1948+ *
1949+ * http://www.apache.org/licenses/LICENSE-2.0
1950+ *
1951+ * Unless required by applicable law or agreed to in writing, software
1952+ * distributed under the License is distributed on an “AS IS” BASIS,
1953+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1954+ * See the License for the specific language governing permissions and
1955+ * limitations under the License.
1956+ */
1957+package de.unigoettingen.sub.commons.util.stream;
1958+
1959+import java.io.BufferedReader;
1960+import java.io.File;
1961+import java.io.FileInputStream;
1962+import java.io.IOException;
1963+import java.io.InputStream;
1964+import java.io.InputStreamReader;
1965+import java.io.Reader;
1966+import java.io.StringWriter;
1967+import java.io.Writer;
1968+import java.net.URL;
1969+import java.net.URLConnection;
1970+import java.net.URLDecoder;
1971+import java.util.Properties;
1972+
1973+import org.apache.commons.codec.binary.Base64;
1974+
1975+
1976+public class StreamUtils {
1977+
1978+ /**
1979+ * get MimeType as {@link String} from given URL
1980+ *
1981+ * @param url
1982+ * the url from where to get the MimeType
1983+ * @return MimeType as {@link String}
1984+ * @throws IOException
1985+ */
1986+ public static String getMimeTypeFromUrl(URL url) throws IOException {
1987+
1988+ URLConnection con = url.openConnection();
1989+ return con.getContentType();
1990+ }
1991+
1992+ /**
1993+ * get MimeType as {@link String} from given URL including proxy details
1994+ *
1995+ * @param url
1996+ * the url from where to get the MimeType
1997+ * @param httpproxyhost
1998+ * host of proxy
1999+ * @param httpproxyport
2000+ * port of proxy
2001+ * @param httpproxyusername
2002+ * username for proxy
2003+ * @param httpproxypassword
2004+ * password for proxy
2005+ * @return MimeType as {@link String}
2006+ * @throws IOException
2007+ */
2008+
2009+ public static String getMimeTypeFromUrl(URL url, String httpproxyhost,
2010+ String httpproxyport, String httpproxyusername,
2011+ String httpproxypassword) throws IOException {
2012+ if (httpproxyhost != null) {
2013+ Properties properties = System.getProperties();
2014+ properties.put("http.proxyHost", httpproxyhost);
2015+ if (httpproxyport != null) {
2016+ properties.put("http.proxyPort", httpproxyport);
2017+ } else {
2018+ properties.put("http.proxyPort", "80");
2019+ }
2020+ }
2021+ URLConnection con = url.openConnection();
2022+ if (httpproxyusername != null) {
2023+ String login = httpproxyusername + ":" + httpproxypassword;
2024+ String encodedLogin = new String(Base64.encodeBase64(login
2025+ .getBytes()));
2026+ con.setRequestProperty("Proxy-Authorization", "Basic "
2027+ + encodedLogin);
2028+ }
2029+ return con.getContentType();
2030+ }
2031+
2032+ /**
2033+ * get {@link InputStream} from given URL
2034+ *
2035+ * @param url
2036+ * the url from where to get the {@link InputStream}
2037+ * @return {@link InputStream} for url
2038+ * @throws IOException
2039+ */
2040+ public static InputStream getInputStreamFromUrl(URL url) throws IOException {
2041+ return StreamUtils.getInputStreamFromUrl(url, null);
2042+ }
2043+
2044+ /**
2045+ * get {@link InputStream} from given URL using a basis path and proxy informations
2046+ *
2047+ * @param url
2048+ * the url from where to get the {@link InputStream}
2049+ * @param basepath the basispath
2050+ * @param httpproxyhost the host for proxy
2051+ * @param httpproxyport the port for proxy
2052+ * @param httpproxyusername the username for the proxy
2053+ * @param httpproxypassword the password for the proxy
2054+ * @return {@link InputStream} for url
2055+ * @throws IOException
2056+ */
2057+ public static InputStream getInputStreamFromUrl(URL url, String basepath,
2058+ String httpproxyhost, String httpproxyport,
2059+ String httpproxyusername, String httpproxypassword)
2060+ throws IOException {
2061+ InputStream inStream = null;
2062+
2063+ if (url.getProtocol().equalsIgnoreCase("http")) {
2064+ if (httpproxyhost != null) {
2065+ Properties properties = System.getProperties();
2066+ properties.put("http.proxyHost", httpproxyhost);
2067+ if (httpproxyport != null) {
2068+ properties.put("http.proxyPort", httpproxyport);
2069+ } else {
2070+ properties.put("http.proxyPort", "80");
2071+ }
2072+ }
2073+ URLConnection con = url.openConnection();
2074+ if (httpproxyusername != null) {
2075+ String login = httpproxyusername + ":" + httpproxypassword;
2076+ String encodedLogin = new String(Base64.encodeBase64(login
2077+ .getBytes()));
2078+ con.setRequestProperty("Proxy-Authorization", "Basic "
2079+ + encodedLogin);
2080+ }
2081+ inStream = con.getInputStream();
2082+ } else if (url.getProtocol().equalsIgnoreCase("file")) {
2083+ String filepath = url.getFile();
2084+
2085+ filepath = URLDecoder.decode(filepath, System
2086+ .getProperty("file.encoding"));
2087+
2088+ File f = new File(filepath);
2089+ inStream = new FileInputStream(f);
2090+ } else if (url.getProtocol().equalsIgnoreCase("")) {
2091+ String filepath = url.getFile();
2092+ // we just have the relative path, need to find the absolute path
2093+ String path = basepath + filepath;
2094+
2095+ // call this method again
2096+ URL completeurl = new URL(path);
2097+ inStream = getInputStreamFromUrl(completeurl);
2098+ }
2099+
2100+ return inStream;
2101+ }
2102+
2103+ /**
2104+ * get {@link InputStream} from given URL using a basis path
2105+ *
2106+ * @param url
2107+ * the url from where to get the {@link InputStream}
2108+ * @param basepath the basispath
2109+ * @return {@link InputStream} for url
2110+ * @throws IOException
2111+ */
2112+ public static InputStream getInputStreamFromUrl(URL url, String basepath)
2113+ throws IOException {
2114+ return getInputStreamFromUrl(url, basepath, null, null, null, null);
2115+ }
2116+
2117+
2118+ /**
2119+ * Dump {@link InputStream} into a String
2120+ *
2121+ * @param in the InputStream
2122+ * @return the String
2123+ * @throws IOException Signals that an I/O exception has occurred.
2124+ */
2125+ public static String dumpInputStream (InputStream in) throws IOException {
2126+ if (in != null) {
2127+ Writer writer = new StringWriter();
2128+
2129+ char[] buffer = new char[1024];
2130+ try {
2131+ Reader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
2132+ int n;
2133+ while ((n = reader.read(buffer)) != -1) {
2134+ writer.write(buffer, 0, n);
2135+ }
2136+ } finally {
2137+ in.close();
2138+ }
2139+ return writer.toString();
2140+ } else {
2141+ return "";
2142+ }
2143+ }
2144+}
2145
2146=== added directory 'src/de/unigoettingen/sub/commons/util/xml'
2147=== added file 'src/de/unigoettingen/sub/commons/util/xml/XMLDumper.java'
2148--- src/de/unigoettingen/sub/commons/util/xml/XMLDumper.java 1970-01-01 00:00:00 +0000
2149+++ src/de/unigoettingen/sub/commons/util/xml/XMLDumper.java 2012-05-10 06:45:23 +0000
2150@@ -0,0 +1,28 @@
2151+package de.unigoettingen.sub.commons.util.xml;
2152+
2153+import java.io.StringWriter;
2154+
2155+import javax.xml.transform.OutputKeys;
2156+import javax.xml.transform.Transformer;
2157+import javax.xml.transform.TransformerException;
2158+import javax.xml.transform.TransformerFactory;
2159+import javax.xml.transform.dom.DOMSource;
2160+import javax.xml.transform.stream.StreamResult;
2161+
2162+import org.w3c.dom.Node;
2163+
2164+public class XMLDumper {
2165+
2166+ public static String NodeToString(Node node) {
2167+ StringWriter writer = new StringWriter();
2168+ try {
2169+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
2170+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "true");
2171+ transformer.transform(new DOMSource(node), new StreamResult(writer));
2172+ } catch (TransformerException t) {
2173+ throw new IllegalStateException(t);
2174+ }
2175+ return writer.toString();
2176+ }
2177+
2178+}

Subscribers

People subscribed via source and target branches

to all changes: