Apache Nutch is an extensible and scalable web crawler
parse-mspowerpoint plugin uses the generic outlink extractor instead of its own (Stephan Strittmatter)
Jerome Charroned0feca27cc0
diff --git a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/ContentReaderListener.java b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/ContentReaderListener.javaindex e893b8816..ad3d94be1 100644--- a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/ContentReaderListener.java+++ b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/ContentReaderListener.java@@ -25,7 +25,6 @@ import org.apache.nutch.util.LogFormatter;import org.apache.poi.hdf.extractor.Utils;import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;-import org.apache.poi.poifs.filesystem.DocumentEntry;import org.apache.poi.poifs.filesystem.DocumentInputStream;import org.apache.poi.util.LittleEndian;import org.apache.poi.util.StringUtil;@@ -272,10 +271,9 @@ class ContentReaderListener implements POIFSReaderListener {// TextCharAtom recordfinal String strTempContent = new String(pptdata,- (int) startPos + 6, (int) (nsize) + 2);+ startPos + 6, (int) (nsize) + 2);final byte bytes[] = strTempContent.getBytes();if (true) {- // FIXME my versionoutStream = new FilteredStringWriter();for (int ii = 0; ii < bytes.length - 1; ii += 2) {// For loop to changed to a functiondiff --git a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/MSPowerPointParser.java b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/MSPowerPointParser.javaindex f625bee7e..4274cd6e0 100644--- a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/MSPowerPointParser.java+++ b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/MSPowerPointParser.java@@ -23,6 +23,7 @@ import java.util.Properties;import java.util.logging.Logger;import org.apache.nutch.parse.Outlink;+import org.apache.nutch.parse.OutlinkExtractor;import org.apache.nutch.parse.Parse;import org.apache.nutch.parse.ParseData;import org.apache.nutch.parse.ParseImpl;@@ -55,13 +56,6 @@ public class MSPowerPointParser implements Parser {public MSPowerPointParser() {}- /**- *- */- public MSPowerPointParser(String fileName) {-- }-/*** Main for testing. Pass a ppt-file as argument*@@ -128,7 +122,7 @@ public class MSPowerPointParser implements Parser {plainText = extractor.getText();properties = extractor.getProperties();- outlinks = this.getOutlinks(plainText, content.getUrl());+ outlinks = OutlinkExtractor.getOutlinks(plainText, content.getUrl());} catch (Exception e) {LOG.throwing(this.getClass().getName(), "getParse", e);@@ -159,17 +153,6 @@ public class MSPowerPointParser implements Parser {LOG.finest("PowerPoint file parsed sucessful.");return new ParseImpl(plainText, parseData);}-- /**- * Collect outlinks of document.- *- * @param plainText- *- * @return Array of links within the PowerPoint file- */- protected Outlink[] getOutlinks(String plainText, String anchor) {- return OutlinkExtractor.getOutlinks(plainText, anchor);- }private final static byte[] getRawBytes(File f) {try {diff --git a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/OutlinkExtractor.java b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/OutlinkExtractor.javadeleted file mode 100644index 794ba8d33..000000000--- a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/OutlinkExtractor.java+++ /dev/null@@ -1,228 +0,0 @@-/**- * Copyright 2005 The Apache Software Foundation- *- * 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 org.apache.nutch.parse.mspowerpoint;--import java.util.ArrayList;-import java.util.List;-import java.util.logging.Logger;--import org.apache.nutch.parse.Outlink;-import org.apache.nutch.util.LogFormatter;-import org.apache.oro.text.regex.MatchResult;-import org.apache.oro.text.regex.Pattern;-import org.apache.oro.text.regex.PatternCompiler;-import org.apache.oro.text.regex.PatternMatcher;-import org.apache.oro.text.regex.PatternMatcherInput;-import org.apache.oro.text.regex.Perl5Compiler;-import org.apache.oro.text.regex.Perl5Matcher;--/**- * Extractor to extract {@link org.apache.nutch.parse.Outlink}s- * / URLs from plain text using Regular Expressions.- *- * @see <a- * href="http://wiki.java.net/bin/view/Javapedia/RegularExpressions">Comparison- * of different regexp-Implementations </a>- * @see <a href="http://regex.info/java.html">Overview about Java Regexp APIs- * </a>- *- * @author Stephan Strittmatter - http://www.sybit.de- * @version 1.0- * @since 0.7- */-public class OutlinkExtractor {- private static final Logger LOG = LogFormatter- .getLogger(OutlinkExtractor.class.getName());-- /**- * Regex pattern to get URLs within a plain text.- *- * @see <a- * href="http://www.truerwords.net/articles/ut/urlactivation.html">http://www.truerwords.net/articles/ut/urlactivation.html- * </a>- */- private static final String URL_PATTERN =- "([A-Za-z][A-Za-z0-9+.-]+:[A-Za-z0-9/](([A-Za-z0-9$_.+!*,;/?:@&~=-])|%[A-Fa-f0-9]{2})+(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*,;/?:@&~=%-]*))?)";-- /**- * Extracts <code>Outlink</code> from given plain text.- *- * @param plainText the plain text from wich URLs should be extracted.- *- * @return Array of <code>Outlink</code>s within found in plainText- */- public static Outlink[] getOutlinks(final String plainText) {- return OutlinkExtractor.getOutlinks(plainText, "");- }-- /**- * Extracts <code>Outlink</code> from given plain text and adds anchor- * to the extracted <code>Outlink</code>s- *- * @param plainText the plain text from wich URLs should be extracted.- * @param anchor the anchor of the url- *- * @return Array of <code>Outlink</code>s within found in plainText- */- public static Outlink[] getOutlinks(final String plainText, String anchor) {-- final List outlinks = new ArrayList();-- try {- final PatternCompiler cp = new Perl5Compiler();- final Pattern pattern = cp.compile(URL_PATTERN,- Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK- | Perl5Compiler.MULTILINE_MASK);- final PatternMatcher matcher = new Perl5Matcher();-- final PatternMatcherInput input = new PatternMatcherInput(plainText);-- MatchResult result;- String url;-- //loop the matches- while (matcher.contains(input, pattern)) {- result = matcher.getMatch();- url = result.group(0);- outlinks.add(new Outlink(url, anchor));- }- } catch (Exception ex) {- // if it is a malformed URL we just throw it away and continue with- // extraction.- LOG.throwing(OutlinkExtractor.class.getName(), "getOutlinks", ex);- }-- final Outlink[] retval;-- //create array of the Outlinks- if (outlinks != null && outlinks.size() > 0) {- retval = (Outlink[]) outlinks.toArray(new Outlink[0]);- } else {- retval = new Outlink[0];- }-- return retval;- }--- /**- * Extracts outlinks from a plain text. <br />- * This Method takes the Jakarta Regexp API.- *- * @param plainText- *- * @return Array of <code>Outlink</code> s within found in plainText- * @deprecated only for tests- */- private Outlink[] getOutlinksJakartaRegexpImpl(final String plainText) {-- throw new UnsupportedOperationException(- "Implementation commented out. Please uncomment to use it.");-- // final List outlinks = new ArrayList();- // String url;- // Outlink link;- //- // RE re = new RE(URL_PATTERN);- //- // int pos = 0;- //- // while (re.match(plainText, pos)) {- //- // url = re.getParen(0);- //- // LOG.finest("Extracted url: " + url);- //- // try {- //- // link = new Outlink(url, null);- // outlinks.add(link);- //- // } catch (MalformedURLException ex) {- // // if it is a malformed URL we just throw it away and continue with- // // extraction.- // LOG.throwing(this.getClass().getName(), "getOutlinks", ex);- // }- //- // pos = re.getParenEnd(0);- // }- //- // final Outlink[] retval;- //- // if (pos > 0) {- // retval = (Outlink[]) outlinks.toArray(new Outlink[0]);- // } else {- // retval = new Outlink[0];- // }- //- // return retval;-- }-- /**- * Extracts outlinks from a plain text.- * </p>- * This Method takes the JDK5 Regexp API.- *- * @param plainText- *- * @return Array of <code>Outlink</code> s within found in plainText- * @deprecated only for tests- */- private Outlink[] getOutlinksJDK5Impl(final String plainText) {-- throw new UnsupportedOperationException(- "Implementation commented out. Please uncomment to use it.");-- // final List outlinks = new ArrayList();- // String url;- // Outlink link;- //- // final Pattern urlPattern = Pattern.compile(URL_PATTERN);- // final RE re = new RE(urlPattern);- //- // int pos = 0;- //- // while (re.match(plainText, pos)) {- //- // url = re.getParen(0);- //- // try {- //- // link = new Outlink(url, null);- // outlinks.add(link);- // } catch (MalformedURLException ex) {- // // if it is a malformed URL we just throw it away and continue with- // // extraction.- // LOG.throwing(this.getClass().getName(), "getOutlinks", ex);- // }- //- // pos = re.getParenEnd(0);- // }- //- // final Outlink[] retval;- //- // if (pos > 0) {- // retval = (Outlink[]) outlinks.toArray(new Outlink[0]);- // } else {- // retval = new Outlink[0];- // }- //- // return retval;- }--}diff --git a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PPTConstants.java b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PPTConstants.javaindex 6cbf44260..1df7bf40f 100644--- a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PPTConstants.java+++ b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PPTConstants.java@@ -27,6 +27,7 @@ class PPTConstants {/** ID of master slide */public static final long PPT_MASTERSLIDE = 1024L;+ /** ATOM ID of slide */public static long PPT_ATOM_SLIDE = 1007l;/** ATOM ID of notes */diff --git a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PowerPointDocumentException.java b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PowerPointDocumentException.javaindex f470d0639..67852e061 100644--- a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PowerPointDocumentException.java+++ b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PowerPointDocumentException.java@@ -15,7 +15,6 @@*/package org.apache.nutch.parse.mspowerpoint;-import java.io.IOException;/*** Exception class used for catching the runtime exceptions for the Powerpointdiff --git a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PropertiesReaderListener.java b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PropertiesReaderListener.javaindex bf4a4a085..81f95f1bd 100644--- a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PropertiesReaderListener.java+++ b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PropertiesReaderListener.java@@ -23,7 +23,6 @@ import java.util.logging.Logger;import org.apache.nutch.parse.mspowerpoint.PPTExtractor.PropertiesBroker;import org.apache.nutch.util.LogFormatter;-import org.apache.poi.hpsf.PropertySet;import org.apache.poi.hpsf.PropertySetFactory;import org.apache.poi.hpsf.SummaryInformation;import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;