Author: ssenrogn Date: 2007-11-26 18:29:01 +0100 (Mon, 26 Nov 2007) New Revision: 5935
Modified: trunk/ trunk/result-spi/src/main/java/no/sesat/search/result/StringChopper.java Log: Merged revisions 5932 via svnmerge from https://dev.schibstedsok.no/svn/search-portal/branches/2.15 ........ r5932 | ssenrogn | 2007-11-26 18:09:22 +0100 (Mon, 26 Nov 2007) | 1 line SEARCH-3795 - implemented handling of attributes when chopping tags. ........ Property changes on: trunk ___________________________________________________________________ Name: svnmerge-integrated - /branches/2.10:1-4690,4692-4745 /branches/2.11:1-4933 /branches/2.12:1-5051,5053-5106 /branches/2.13:1-5378 /branches/2.14:1-5508 /branches/2.15:1-5923,5933 /branches/2.6:1-3877 /branches/2.7:1-4160 /branches/2.8:1-4446 /branches/2.9:1-4626 /branches/MAP_SEARCHv2:1-4544 + /branches/2.10:1-4690,4692-4745 /branches/2.11:1-4933 /branches/2.12:1-5051,5053-5106 /branches/2.13:1-5378 /branches/2.14:1-5508 /branches/2.15:1-5923,5932-5933 /branches/2.6:1-3877 /branches/2.7:1-4160 /branches/2.8:1-4446 /branches/2.9:1-4626 /branches/MAP_SEARCHv2:1-4544 Modified: trunk/result-spi/src/main/java/no/sesat/search/result/StringChopper.java =================================================================== --- trunk/result-spi/src/main/java/no/sesat/search/result/StringChopper.java 2007-11-26 17:27:16 UTC (rev 5934) +++ trunk/result-spi/src/main/java/no/sesat/search/result/StringChopper.java 2007-11-26 17:29:01 UTC (rev 5935) @@ -1,7 +1,7 @@ /* Copyright (2005-2007) Schibsted Søk AS * This file is part of SESAT. * You can use, redistribute, and/or modify it, under the terms of the SESAT License. - * You should have received a copy of the SESAT License along with this program. + * You should have received a copy of the SESAT License along with this program. * If not, see https://dev.sesat.no/confluence/display/SESAT/SESAT+License * * SESAT is free software: you can redistribute it and/or modify @@ -31,16 +31,16 @@ import org.apache.log4j.Logger; /** My favourite dish of ChopSuey. - * + * * @version $Id$ * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a> */ public final class StringChopper { - + // Constants ----------------------------------------------------- - + private static final Logger LOG = Logger.getLogger(StringChopper.class); - + private static final String DEBUG_CHOPSUEY = "Chopped it up to "; private static final Pattern openTag = Pattern.compile("<[^<]+>"); @@ -48,35 +48,35 @@ private static final Pattern singleTag = Pattern.compile("<[^<]+/>"); // Attributes ---------------------------------------------------- - + // Static -------------------------------------------------------- - + /** * null safe. - * @param s - * @param length - * @return + * @param s + * @param length + * @return */ public static String chop(final String s, final int length) { return chop(s, length, false); - } - + } + /** * null safe. - * @param s - * @param length + * @param s + * @param length * @param chopWord allowed to chop a word in half - * @return - */ + * @return + */ public static String chop(final String s, final int length, final boolean chopWord) { - + if(null != s){ final StringBuilder choppedString = new StringBuilder(s); int laOriginalCount = 0, raOriginalCount = 0, markupLength = 0; boolean insideMarkup = false; - for(int i = 0; i < choppedString.length(); ++i){ + for(int i = 0; i < choppedString.length(); ++i){ if( '<' == choppedString.charAt(i) ){ ++laOriginalCount; insideMarkup = true;} if (insideMarkup) { @@ -87,7 +87,7 @@ } - // if we have more left than right arrows + // if we have more left than right arrows while(laOriginalCount > raOriginalCount){ choppedString.append('>'); ++raOriginalCount; @@ -104,7 +104,7 @@ // if we chopped a tag in half remove the half left over. int laCount = 0, raCount = 0; - for(int i = 0; i < choppedString.length(); ++i){ + for(int i = 0; i < choppedString.length(); ++i){ if( '<' == choppedString.charAt(i) ){ ++laCount; } else if( '>' == choppedString.charAt(i) ){ ++raCount; } } @@ -169,24 +169,26 @@ //LOG.debug("Ignoring single tag " + matcher.group()); }else{ + // Removing attributes etc to find the correct closing tag. //LOG.debug("Found opening tag " + matcher.group()); - tags.addFirst(matcher.group()); + //LOG.debug(" adding to stack: " + matcher.group().replaceFirst(" [^>]+", "")); + tags.addFirst(matcher.group().replaceFirst(" [^>]+", "")); } } // remove tags that had no opening - for(int[] startEnd : tagsToRemove){ + for(final int[] startEnd : tagsToRemove){ //LOG.debug("Removing " + matcher.group()); choppedString.delete(startEnd[0], startEnd[1]); } // add tags to balance - for(String tag : tags){ + for(final String tag : tags){ //LOG.debug("Adding " + tag.replaceFirst("<", "</")); choppedString.append(tag.replaceFirst("<", "</")); - } + } } LOG.trace(DEBUG_CHOPSUEY + choppedString); @@ -194,27 +196,27 @@ } return null; } - + // Constructors -------------------------------------------------- - + /** Creates a new instance of StringChopper */ private StringChopper(){ } - + // Public -------------------------------------------------------- - + // Z implementation ---------------------------------------------- - + // Y overrides --------------------------------------------------- - + // Package protected --------------------------------------------- - + // Protected ----------------------------------------------------- - + // Private ------------------------------------------------------- - + // Inner classes ------------------------------------------------- - - - + + + } _______________________________________________ Kernel-commits mailing list [email protected] http://sesat.no/mailman/listinfo/kernel-commits
