luc 9 years ago
commit 82f4f221e9

@ -23,13 +23,11 @@
<classpathentry kind="lib" path="lib/json-simple-1.1.1.jar"/>
<classpathentry kind="lib" path="lib/xercesImpl.jar"/>
<classpathentry kind="lib" path="lib/xml-apis.jar"/>
<classpathentry kind="lib" path="lib/geronimo-stax-api_1.0_spec-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/commons-compress-1.9.jar"/>
<classpathentry kind="lib" path="lib/commons-lang-2.6.jar"/>
<classpathentry kind="lib" path="lib/jaudiotagger-2.0.4-20111207.115108-15.jar"/>
<classpathentry kind="lib" path="lib/commons-codec-1.10.jar"/>
<classpathentry kind="lib" path="lib/jcl-over-slf4j-1.7.12.jar"/>
<classpathentry kind="lib" path="lib/wstx-asl-3.2.9.jar"/>
<classpathentry kind="lib" path="lib/slf4j-jdk14-1.7.12.jar"/>
<classpathentry kind="lib" path="lib/log4j-over-slf4j-1.7.12.jar"/>
<classpathentry kind="lib" path="lib/httpcore-4.4.1.jar"/>

@ -173,7 +173,6 @@
<pathelement location="${lib}/commons-lang-2.6.jar" />
<pathelement location="${lib}/commons-logging-1.2.jar" />
<pathelement location="${lib}/fontbox-1.8.10.jar" />
<pathelement location="${lib}/geronimo-stax-api_1.0_spec-1.0.1.jar" />
<pathelement location="${lib}/guava-18.0.jar" />
<pathelement location="${lib}/htmllexer.jar" />
<pathelement location="${lib}/httpclient-4.5.jar" />
@ -232,9 +231,10 @@
<pathelement location="${lib}/solr-core-5.2.1.jar" />
<pathelement location="${lib}/solr-solrj-5.2.1.jar" />
<pathelement location="${lib}/spatial4j-0.4.1.jar" />
<pathelement location="${lib}/stax2-api_3.1.4.jar" />
<pathelement location="${lib}/webcat-0.1-swf.jar" />
<pathelement location="${lib}/weupnp-0.1.3.jar" />
<pathelement location="${lib}/wstx-asl-3.2.9.jar" />
<pathelement location="${lib}/woodstox-core-asl-4.4.1.jar" />
<pathelement location="${lib}/xercesImpl.jar" />
<pathelement location="${lib}/xml-apis.jar" />
<pathelement location="${lib}/xmpcore-5.1.2.jar" />

@ -29,7 +29,6 @@ import java.awt.image.Raster;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.Map;
@ -116,42 +115,31 @@ public class ViewImage {
} catch (final IOException e) {
ConcurrentLog.fine("ViewImage", "cannot load: " + e.getMessage());
}
byte[] imgb = null;
boolean okToCache = true;
if (resourceb == null) {
if (urlString.endsWith(".ico")) {
// load default favicon dfltfvcn.ico
if (defaulticonb == null) try {
imgb = FileUtils.read(new File(sb.getAppPath(), defaulticon));
resourceb = FileUtils.read(new File(sb.getAppPath(), defaulticon));
okToCache = false;
} catch (final IOException e) {
return null;
} else {
imgb = defaulticonb;
resourceb = defaulticonb;
okToCache = false;
}
} else {
return null;
}
} else {
final InputStream imgStream = new ByteArrayInputStream(resourceb);
// read image data
try {
imgb = FileUtils.read(imgStream);
} catch (final IOException e) {
return null;
} finally {
try {
imgStream.close();
} catch (final Exception e) {}
}
}
// gif images are not loaded because of an animated gif bug within jvm which sends java into an endless loop with high CPU
if (ext.equals("gif") && "gif".equals(MultiProtocolURL.getFileExtension(url.getFileName()))) {
return new ByteArrayInputStream(imgb);
return new ByteArrayInputStream(resourceb);
}
// read image
image = ImageParser.parse(urlString, imgb);
image = ImageParser.parse(urlString, resourceb);
if (image == null) {
return null;
}
@ -233,7 +221,7 @@ public class ViewImage {
height = h;
}
if ((height == 16) && (width == 16) && (resourceb != null)) {
if ((height == 16) && (width == 16) && okToCache) {
// this might be a favicon, store image to cache for faster re-load later on
iconcache.put(urlString, image);
}

@ -1,4 +1,3 @@
package env;
// style.java
// -----------------------
// (C) 2010 by Michael Peter Christen; mc@yacy.net

File diff suppressed because it is too large Load Diff

Binary file not shown.

@ -83,7 +83,7 @@
<compilation-unit>
<package-root>source</package-root>
<package-root>htroot</package-root>
<classpath mode="compile">lib/J7Zip-modified.jar;lib/apache-mime4j-0.6.jar;lib/bcmail-jdk15-1.46.jar;lib/bcprov-jdk15-1.46.jar;lib/chardet.jar;lib/commons-codec-1.10.jar;lib/commons-compress-1.9.jar;lib/commons-fileupload-1.3.1.jar;lib/commons-io-2.4.jar;lib/commons-jxpath-1.3.jar;lib/commons-lang-2.6.jar;lib/commons-logging-1.2.jar;lib/fontbox-1.8.10.jar;lib/geronimo-stax-api_1.0_spec-1.0.1.jar;lib/guava-18.0.jar;lib/htmllexer.jar;lib/httpclient-4.5.jar;lib/httpcore-4.4.1.jar;lib/httpmime-4.5.jar;lib/icu4j-55_1.jar;lib/jakarta-oro-2.0.8.jar;lib/jaudiotagger-2.0.4-20111207.115108-15.jar;lib/javax.servlet-api-3.1.0.jar;lib/jcifs-1.3.17.jar;lib/jcl-over-slf4j-1.7.12.jar;lib/jempbox-1.8.10.jar;lib/jetty-client-9.2.11.v20150529.jar;lib/jetty-continuation-9.2.11.v20150529.jar;lib/jetty-deploy-9.2.11.v20150529.jar;lib/jetty-http-9.2.11.v20150529.jar;lib/jetty-io-9.2.11.v20150529.jar;lib/jetty-jmx-9.2.11.v20150529.jar;lib/jetty-proxy-9.2.11.v20150529.jar;lib/jetty-security-9.2.11.v20150529.jar;lib/jetty-server-9.2.11.v20150529.jar;lib/jetty-servlet-9.2.11.v20150529.jar;lib/jetty-servlets-9.2.11.v20150529.jar;lib/jetty-util-9.2.11.v20150529.jar;lib/jetty-webapp-9.2.11.v20150529.jar;lib/jetty-xml-9.2.11.v20150529.jar;lib/jsch-0.1.53.jar;lib/json-simple-1.1.1.jar;lib/jsoup-1.8.3.jar;lib/log4j-over-slf4j-1.7.12.jar;lib/lucene-analyzers-common-5.2.1.jar;lib/lucene-analyzers-phonetic-5.2.1.jar;lib/lucene-backward-codecs-5.2.1.jar;lib/lucene-classification-5.2.1.jar;lib/lucene-codecs-5.2.1.jar;lib/lucene-core-5.2.1.jar;lib/lucene-facet-5.2.1.jar;lib/lucene-grouping-5.2.1.jar;lib/lucene-highlighter-5.2.1.jar;lib/lucene-join-5.2.1.jar;lib/lucene-memory-5.2.1.jar;lib/lucene-misc-5.2.1.jar;lib/lucene-queries-5.2.1.jar;lib/lucene-queryparser-5.2.1.jar;lib/lucene-spatial-5.2.1.jar;lib/lucene-suggest-5.2.1.jar;lib/metadata-extractor-2.8.1.jar;lib/noggit-0.6.jar;lib/org.restlet.jar;lib/pdfbox-1.8.10.jar;lib/poi-3.12-20150511.jar;lib/poi-scratchpad-3.12-20150511.jar;lib/slf4j-api-1.7.12.jar;lib/slf4j-jdk14-1.7.12.jar;lib/solr-core-5.2.1.jar;lib/solr-solrj-5.2.1.jar;lib/spatial4j-0.4.1.jar;lib/stax2-api-3.1.4.jar;lib/webcat-0.1-swf.jar;lib/weupnp-0.1.3.jar;lib/woodstox-core-asl-4.4.1.jar;lib/wstx-asl-3.2.9.jar;lib/xercesImpl.jar;lib/xml-apis.jar;lib/xmpcore-5.1.2.jar;lib/zookeeper-3.4.6.jar</classpath>
<classpath mode="compile">lib/J7Zip-modified.jar;lib/apache-mime4j-0.6.jar;lib/bcmail-jdk15-1.46.jar;lib/bcprov-jdk15-1.46.jar;lib/chardet.jar;lib/commons-codec-1.10.jar;lib/commons-compress-1.9.jar;lib/commons-fileupload-1.3.1.jar;lib/commons-io-2.4.jar;lib/commons-jxpath-1.3.jar;lib/commons-lang-2.6.jar;lib/commons-logging-1.2.jar;lib/fontbox-1.8.10.jar;lib/guava-18.0.jar;lib/htmllexer.jar;lib/httpclient-4.5.jar;lib/httpcore-4.4.1.jar;lib/httpmime-4.5.jar;lib/icu4j-55_1.jar;lib/jakarta-oro-2.0.8.jar;lib/jaudiotagger-2.0.4-20111207.115108-15.jar;lib/javax.servlet-api-3.1.0.jar;lib/jcifs-1.3.17.jar;lib/jcl-over-slf4j-1.7.12.jar;lib/jempbox-1.8.10.jar;lib/jetty-client-9.2.11.v20150529.jar;lib/jetty-continuation-9.2.11.v20150529.jar;lib/jetty-deploy-9.2.11.v20150529.jar;lib/jetty-http-9.2.11.v20150529.jar;lib/jetty-io-9.2.11.v20150529.jar;lib/jetty-jmx-9.2.11.v20150529.jar;lib/jetty-proxy-9.2.11.v20150529.jar;lib/jetty-security-9.2.11.v20150529.jar;lib/jetty-server-9.2.11.v20150529.jar;lib/jetty-servlet-9.2.11.v20150529.jar;lib/jetty-servlets-9.2.11.v20150529.jar;lib/jetty-util-9.2.11.v20150529.jar;lib/jetty-webapp-9.2.11.v20150529.jar;lib/jetty-xml-9.2.11.v20150529.jar;lib/jsch-0.1.53.jar;lib/json-simple-1.1.1.jar;lib/jsoup-1.8.3.jar;lib/log4j-over-slf4j-1.7.12.jar;lib/lucene-analyzers-common-5.2.1.jar;lib/lucene-analyzers-phonetic-5.2.1.jar;lib/lucene-backward-codecs-5.2.1.jar;lib/lucene-classification-5.2.1.jar;lib/lucene-codecs-5.2.1.jar;lib/lucene-core-5.2.1.jar;lib/lucene-facet-5.2.1.jar;lib/lucene-grouping-5.2.1.jar;lib/lucene-highlighter-5.2.1.jar;lib/lucene-join-5.2.1.jar;lib/lucene-memory-5.2.1.jar;lib/lucene-misc-5.2.1.jar;lib/lucene-queries-5.2.1.jar;lib/lucene-queryparser-5.2.1.jar;lib/lucene-spatial-5.2.1.jar;lib/lucene-suggest-5.2.1.jar;lib/metadata-extractor-2.8.1.jar;lib/noggit-0.6.jar;lib/org.restlet.jar;lib/pdfbox-1.8.10.jar;lib/poi-3.12-20150511.jar;lib/poi-scratchpad-3.12-20150511.jar;lib/slf4j-api-1.7.12.jar;lib/slf4j-jdk14-1.7.12.jar;lib/solr-core-5.2.1.jar;lib/solr-solrj-5.2.1.jar;lib/spatial4j-0.4.1.jar;lib/stax2-api-3.1.4.jar;lib/webcat-0.1-swf.jar;lib/weupnp-0.1.3.jar;lib/woodstox-core-asl-4.4.1.jar;lib/xercesImpl.jar;lib/xml-apis.jar;lib/xmpcore-5.1.2.jar;lib/zookeeper-3.4.6.jar</classpath>
<built-to>lib/yacycore.jar</built-to>
<source-level>1.7</source-level>
</compilation-unit>

@ -300,6 +300,38 @@
</plugins>
</build>
<profiles>
<profile>
<id>report</id>
<build>
<plugins>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>1.3.1</version>
</plugin>
</plugins>
</reporting>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>junit</groupId>
@ -368,11 +400,6 @@
<artifactId>fontbox</artifactId>
<version>1.8.10</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-stax-api_1.0_spec</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
@ -573,11 +600,6 @@
<artifactId>weupnp</artifactId>
<version>0.1.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>wstx-asl</artifactId>
<version>3.2.9</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>

@ -27,7 +27,8 @@ public class NumberTools {
/**
* this method replaces Long.parseLong/2 where a substring of decimal numbers shall be parsed
* Strings are also auto-trimmed, that means parsing stops at spaces without throwing a NumberFormatException
* Strings are also auto-trimmed, that means parsing stops at trailing spaces without throwing a NumberFormatException
* leading spaces are skip'd and parse stops at first none digit character
* @param s
* @param startPos
* @return the number
@ -54,6 +55,7 @@ public class NumberTools {
int digit;
char c;
while (s.charAt(i) == ' ') i++; // skip leading blanks
char firstChar = s.charAt(i);
if (firstChar < '0') {
if (firstChar == '-') {
@ -66,7 +68,7 @@ public class NumberTools {
multmin = limit / 10;
while (i < endPos) {
c = s.charAt(i++);
if (c == ' ') break;
if (c < '0' || c > '9') break; // stop at first non digit character
digit = c - '0';
if (digit < 0 || digit > 9 || result < multmin) throw new NumberFormatException(s);
result *= 10;
@ -97,6 +99,7 @@ public class NumberTools {
int digit;
char c;
while (s.charAt(i) == ' ') i++; // skip leading blanks
char firstChar = s.charAt(i);
if (firstChar < '0') {
if (firstChar == '-') {
@ -109,7 +112,7 @@ public class NumberTools {
multmin = limit / 10;
while (i < endPos) {
c = s.charAt(i++);
if (c == ' ') break;
if (c < '0' || c > '9') break; // stop at first non digit character
digit = c - '0';
if (digit < 0 || digit > 9 || result < multmin) throw new NumberFormatException(s);
result *= 10;

@ -66,6 +66,7 @@ import net.yacy.document.parser.xlsParser;
import net.yacy.document.parser.zipParser;
import net.yacy.document.parser.images.genericImageParser;
import net.yacy.document.parser.images.metadataImageParser;
import net.yacy.document.parser.images.svgParser;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.MemoryControl;
@ -105,6 +106,7 @@ public final class TextParser {
initParser(new rtfParser());
initParser(new sevenzipParser());
initParser(new sidAudioParser());
initParser(new svgParser());
initParser(new swfParser());
initParser(new tarParser());
initParser(new torrentParser());
@ -112,7 +114,6 @@ public final class TextParser {
initParser(new vsdParser());
initParser(new xlsParser());
initParser(new zipParser());
initParser(new rdfParser());
initParser(new audioTagParser());
}

@ -28,7 +28,6 @@ import java.io.Writer;
import java.lang.reflect.Array;
import java.net.MalformedURLException;
import java.nio.charset.Charset;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
@ -415,15 +414,14 @@ public class ContentScraper extends AbstractScraper implements Scraper {
if (src.length() > 0) {
final DigestURL url = absolutePath(src);
if (url != null) {
// use Numberformat.parse to allow parse of "550px"
NumberFormat intnum = NumberFormat.getIntegerInstance ();
final int width = intnum.parse(tag.opts.getProperty("width", "-1")).intValue(); // Integer.parseInt fails on "200px"
final int height = intnum.parse(tag.opts.getProperty("height", "-1")).intValue();
// use to allow parse of "550px", with better performance as Numberformat.parse
final int width = NumberTools.parseIntDecSubstring(tag.opts.getProperty("width", "-1")); // Integer.parseInt fails on "200px"
final int height = NumberTools.parseIntDecSubstring(tag.opts.getProperty("height", "-1"));
final ImageEntry ie = new ImageEntry(url, tag.opts.getProperty("alt", EMPTY_STRING), width, height, -1);
this.images.add(ie);
}
}
} catch (final ParseException e) {}
} catch (final NumberFormatException e) {}
this.evaluationScores.match(Element.imgpath, src);
} else if(tag.name.equalsIgnoreCase("base")) {
try {

@ -0,0 +1,257 @@
/**
* svgParser.java
* Copyright 2015 by Burkhard Buelte
* First released 26.09.2015 at http://yacy.net
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt If not, see
* <http://www.gnu.org/licenses/>.
*/
package net.yacy.document.parser.images;
import java.io.EOFException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import net.yacy.cora.document.id.AnchorURL;
import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.document.id.MultiProtocolURL;
import net.yacy.cora.util.ConcurrentLog;
import net.yacy.cora.util.NumberTools;
import net.yacy.document.AbstractParser;
import net.yacy.document.Document;
import net.yacy.document.Parser;
import net.yacy.document.VocabularyScraper;
import net.yacy.document.parser.html.ImageEntry;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
* Metadata parser for svg image files (which are xml files) SVG 1.1 (Second Edition)
* http://www.w3.org/TR/SVG/metadata.html#MetadataElement according to SVG 1.1
* parser stops parsing after the first metadata elment has been read and
* document level metadata are expected picture data (as proposed in spec) like
* <svg>
* <title></title>
* <desc></desc>
* <metadata></metadata>
* <... other/>
* </svg>
*/
public class svgParser extends AbstractParser implements Parser {
public svgParser() {
super("SVG Image Parser");
this.SUPPORTED_EXTENSIONS.add("svg");
this.SUPPORTED_MIME_TYPES.add("image/svg+xml");
}
private static final ThreadLocal<SAXParser> tlSax = new ThreadLocal<SAXParser>();
private static SAXParser getParser() throws SAXException {
SAXParser parser = tlSax.get();
if (parser == null) {
try {
parser = SAXParserFactory.newInstance().newSAXParser();
} catch (final ParserConfigurationException e) {
throw new SAXException(e.getMessage(), e);
}
tlSax.set(parser);
}
return parser;
}
@Override
public Document[] parse(
final AnchorURL location,
final String mimeType,
final String charset,
final VocabularyScraper scraper,
final int timezoneOffset,
final InputStream source) throws Parser.Failure, InterruptedException {
try {
final SAXParser saxParser = getParser();
final svgMetaDataHandler metaData = new svgMetaDataHandler();
try {
saxParser.parse(source, metaData);
} catch (SAXException e) {
// catch EOFException which is intentionally thrown after capturing metadata to skip further reading (not a error, just a way to get out of SAX)
if (e.getException() == null || !(e.getException() instanceof EOFException)) {
throw new Parser.Failure("Unexpected error while parsing svg file. " + e.getMessage(), location);
}
}
String docTitle = metaData.getTitle();
if (docTitle == null) { // use filename like in genericParser
docTitle = location.getFileName().isEmpty() ? location.toTokens() : MultiProtocolURL.unescape(location.getFileName()); //
}
String docDescription = metaData.getDescription();
if (docDescription == null) { // use url token as in genericParser
docDescription = location.toTokens();
}
LinkedHashMap<DigestURL, ImageEntry> images = null;
// add this image to the map of images to register size (as in genericImageParser)
if (metaData.getHeight() != null && metaData.getWidth() != null) {
images = new LinkedHashMap<DigestURL, ImageEntry>();
images.put(location, new ImageEntry(location, "", metaData.getWidth(), metaData.getHeight(), -1));
}
// create the parser document
Document[] docs = new Document[]{new Document(
location,
mimeType,
"UTF-8",
this,
null,
null,
AbstractParser.singleList(docTitle),
null,
"",
null,
null,
0.0f, 0.0f,
docDescription, // text - for this image description is best text we have
null,
null,
images,
false,
null)};
return docs;
} catch (final Exception e) {
if (e instanceof InterruptedException) {
throw (InterruptedException) e;
}
if (e instanceof Parser.Failure) {
throw (Parser.Failure) e;
}
ConcurrentLog.logException(e);
throw new Parser.Failure("Unexpected error while parsing odt file. " + e.getMessage(), location);
}
}
/**
* SAX handler for svg metadata
*/
public class svgMetaDataHandler extends DefaultHandler {
private final StringBuilder buffer = new StringBuilder();
private boolean scrapeMetaData = false; // true if within metadata tag
private String docTitle = null; // document level title
private String docDescription = null; // document level description
private String imgWidth = null; // size in pixel
private String imgHeight = null;
public svgMetaDataHandler() {
}
@Override
public void characters(final char ch[], final int start, final int length) {
buffer.append(ch, start, length);
}
@Override
public void startElement(final String uri, final String name, final String tag, final Attributes atts) throws SAXException {
if (scrapeMetaData) {
// not implemented yet TODO: interprete RDF content
// may contain RDF + DC, DC, CC ...
} else {
if (null != tag) {
switch (tag) {
case "svg":
imgHeight = atts.getValue("height");
imgWidth = atts.getValue("width");
break;
case "metadata":
scrapeMetaData = true;
break;
// some common graph elements as stop condition (skip reading remainder of input), metadata is expected before graphic content
case "g":
case "line":
case "path":
case "rect":
throw new SAXException("EOF svg Metadata", new EOFException());
}
}
}
buffer.delete(0, buffer.length());
}
@Override
public void endElement(final String uri, final String name, final String tag) throws SAXException {
if (scrapeMetaData) {
// stop condition, scrape only first metadata element
if ("metadata".equals(tag)) {
scrapeMetaData = false;
buffer.delete(0, buffer.length());
// we have read metadate, other data are not of interest here, end parsing
throw new SAXException("EOF svg Metadata", new EOFException());
}
} else if ("title".equals(tag)) {
this.docTitle = buffer.toString();
} else if ("desc".equals(tag)) {
this.docDescription = buffer.toString();
}
buffer.delete(0, buffer.length());
}
/**
* @return document level title or null
*/
public String getTitle() {
return docTitle;
}
/**
* @return document level description or null
*/
public String getDescription() {
return docDescription;
}
/**
* @return image width in pixel or null
*/
public Integer getWidth() {
if (imgWidth != null) {
// return number if given in pixel or a number only, return nothing for size like "100%"
if ((imgWidth.indexOf("px") > 0) || ((imgWidth.charAt(imgWidth.length() - 1) >= '0' && imgWidth.charAt(imgWidth.length() - 1) <= '9'))) {
return NumberTools.parseIntDecSubstring(imgWidth);
}
}
return null;
}
/**
* @return image height in pixel or null
*/
public Integer getHeight() {
if (imgHeight != null) {
// return number if given in pixel or a number only, return nothing for size like "100%"
if ((imgHeight.indexOf("px") > 0) || ((imgHeight.charAt(imgHeight.length() - 1) >= '0' && imgHeight.charAt(imgHeight.length() - 1) <= '9'))) {
return NumberTools.parseIntDecSubstring(imgHeight);
}
}
return null;
}
}
}

@ -0,0 +1,27 @@
package net.yacy.cora.util;
import static net.yacy.cora.util.NumberTools.parseIntDecSubstring;
import org.junit.Test;
import static org.junit.Assert.*;
public class NumberToolsTest {
/**
* Test of parseLongDecSubstring method, of class NumberTools.
*/
@Test
public void testParseIntDecSubstring() {
String[] TestNumbers = new String[]{
"101", " 102", " 103", " 104 ",
"+105", " -106", " +107 ", " -108 ",
"109px", " 110px"};
int i=101;
for (String s : TestNumbers) {
int result = parseIntDecSubstring(s);
assertEquals (s + " = " + Integer.toString(i),i,Math.abs(result));
i++;
}
}
}
Loading…
Cancel
Save