Author: stianh
Date: 2007-05-22 10:13:00 +0200 (Tue, 22 May 2007)
New Revision: 5124

Added:
   trunk/result-spi/src/main/java/no/schibstedsok/searchportal/view/
   
trunk/result-spi/src/main/java/no/schibstedsok/searchportal/view/StringChopper.java
Removed:
   
trunk/result-spi/src/main/java/no/schibstedsok/searchportal/result/StringChopper.java
Log:
Moved StringChopper to folder matching its package statement.

Deleted: 
trunk/result-spi/src/main/java/no/schibstedsok/searchportal/result/StringChopper.java
===================================================================
--- 
trunk/result-spi/src/main/java/no/schibstedsok/searchportal/result/StringChopper.java
       2007-05-21 20:35:28 UTC (rev 5123)
+++ 
trunk/result-spi/src/main/java/no/schibstedsok/searchportal/result/StringChopper.java
       2007-05-22 08:13:00 UTC (rev 5124)
@@ -1,144 +0,0 @@
-/* Copyright (2005-2007) Schibsted Søk AS
- *
- * StringChopper.java
- *
- * Created on June 22, 2006, 5:10 PM
- *
- */
-
-package no.schibstedsok.searchportal.view;
-
-import java.util.LinkedList;
-import java.util.NoSuchElementException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.log4j.Logger;
-import org.apache.commons.lang.StringEscapeUtils;
-
-/** 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 String MALFORMED_HTML_ESCAPING = "Malformed HTML. 
Escaping the entire thing: ";
-
-    private static final Pattern openTag = Pattern.compile("<[^<]+>");
-    private static final Pattern closeTag = Pattern.compile("</[^<]+>");
-    private static final Pattern singleTag = Pattern.compile("<[^<]+/>");
-    private static final Pattern la = Pattern.compile("<");
-    private static final Pattern ra = Pattern.compile(">");
-
-    // Attributes ----------------------------------------------------
-    
-    // Static --------------------------------------------------------
-    
-    /**
-     * 
-     * @param s 
-     * @param length 
-     * @return 
-     */
-    public static String chop(final String s, final int length) {
-        
-        final StringBuilder choppedString = new StringBuilder();
-        
-        
-        if (s.length() <= length){
-            choppedString.append(s);
-            
-        } else {
-            
-            // chop the string first
-            choppedString.append(s.substring(0, length));
-                    
-            // if we chopped a tag in half remove the half left over.
-            int laCount = 0, raCount = 0, laOriginalCount = 0, raOriginalCount 
= 0;
-            for( Matcher m = la.matcher(choppedString); m.find(); ++laCount);
-            for( Matcher m = ra.matcher(choppedString); m.find(); ++raCount);
-            for( Matcher m = la.matcher(s); m.find(); ++laOriginalCount);
-            for( Matcher m = ra.matcher(s); m.find(); ++raOriginalCount);
-            // if we have more left than right arrows AND the original string 
was balanced
-            if( laCount > raCount && laOriginalCount == raOriginalCount){
-                choppedString.setLength(choppedString.lastIndexOf("<"));
-            }
-            
-            // append the dot-dot-dot
-            switch( choppedString.length() >0 ? choppedString.charAt( 
choppedString.length() - 1 ) : ' '){
-                case '.':
-                    if( !choppedString.toString().endsWith("...")){
-                        if( choppedString.toString().endsWith("..")){
-                            choppedString.append('.');
-                        }else {
-                            choppedString.append("..");
-                        }
-                    }
-                    break;
-                default:
-                    final int lastSpace = choppedString.lastIndexOf(" ");
-
-                    if (lastSpace >= 0) {
-                        choppedString.setLength(lastSpace+1);
-                    }
-                    choppedString.append("...");
-                    break;
-           }
-            
-
-        }
-
-        // balance opening tags if the chop happened inbetween open and close 
tags.
-        final LinkedList<String> tags = new LinkedList<String>();
-
-        final Matcher matcher = openTag.matcher(choppedString);
-        while( matcher.find() ){
-            if( closeTag.matcher(matcher.group()).find()) {
-                try {
-                    tags.removeFirst();
-                } catch (NoSuchElementException ex) {
-                    LOG.warn(MALFORMED_HTML_ESCAPING + s);
-                    return StringEscapeUtils.escapeHtml(s); 
-                }
-            }else if( !singleTag.matcher(matcher.group()).find() ){
-                tags.addFirst(matcher.group());
-            }
-        }
-
-        for(String tag : tags){
-            choppedString.append(tag.replaceFirst("<","</"));
-        }        
-        
-        LOG.trace(DEBUG_CHOPSUEY + choppedString);
-        
-        return choppedString.toString();
-    }
-    
-    // Constructors --------------------------------------------------
-    
-    /** Creates a new instance of StringChopper */
-    private StringChopper(){
-    }
-    
-    // Public --------------------------------------------------------
-    
-    // Z implementation ----------------------------------------------
-    
-    // Y overrides ---------------------------------------------------
-    
-    // Package protected ---------------------------------------------
-    
-    // Protected -----------------------------------------------------
-    
-    // Private -------------------------------------------------------
-    
-    // Inner classes -------------------------------------------------
-    
-    
-    
-}

Copied: 
trunk/result-spi/src/main/java/no/schibstedsok/searchportal/view/StringChopper.java
 (from rev 5123, 
trunk/result-spi/src/main/java/no/schibstedsok/searchportal/result/StringChopper.java)
===================================================================
--- 
trunk/result-spi/src/main/java/no/schibstedsok/searchportal/view/StringChopper.java
                         (rev 0)
+++ 
trunk/result-spi/src/main/java/no/schibstedsok/searchportal/view/StringChopper.java
 2007-05-22 08:13:00 UTC (rev 5124)
@@ -0,0 +1,144 @@
+/* Copyright (2005-2007) Schibsted Søk AS
+ *
+ * StringChopper.java
+ *
+ * Created on June 22, 2006, 5:10 PM
+ *
+ */
+
+package no.schibstedsok.searchportal.view;
+
+import java.util.LinkedList;
+import java.util.NoSuchElementException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.log4j.Logger;
+import org.apache.commons.lang.StringEscapeUtils;
+
+/** 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 String MALFORMED_HTML_ESCAPING = "Malformed HTML. 
Escaping the entire thing: ";
+
+    private static final Pattern openTag = Pattern.compile("<[^<]+>");
+    private static final Pattern closeTag = Pattern.compile("</[^<]+>");
+    private static final Pattern singleTag = Pattern.compile("<[^<]+/>");
+    private static final Pattern la = Pattern.compile("<");
+    private static final Pattern ra = Pattern.compile(">");
+
+    // Attributes ----------------------------------------------------
+    
+    // Static --------------------------------------------------------
+    
+    /**
+     * 
+     * @param s 
+     * @param length 
+     * @return 
+     */
+    public static String chop(final String s, final int length) {
+        
+        final StringBuilder choppedString = new StringBuilder();
+        
+        
+        if (s.length() <= length){
+            choppedString.append(s);
+            
+        } else {
+            
+            // chop the string first
+            choppedString.append(s.substring(0, length));
+                    
+            // if we chopped a tag in half remove the half left over.
+            int laCount = 0, raCount = 0, laOriginalCount = 0, raOriginalCount 
= 0;
+            for( Matcher m = la.matcher(choppedString); m.find(); ++laCount);
+            for( Matcher m = ra.matcher(choppedString); m.find(); ++raCount);
+            for( Matcher m = la.matcher(s); m.find(); ++laOriginalCount);
+            for( Matcher m = ra.matcher(s); m.find(); ++raOriginalCount);
+            // if we have more left than right arrows AND the original string 
was balanced
+            if( laCount > raCount && laOriginalCount == raOriginalCount){
+                choppedString.setLength(choppedString.lastIndexOf("<"));
+            }
+            
+            // append the dot-dot-dot
+            switch( choppedString.length() >0 ? choppedString.charAt( 
choppedString.length() - 1 ) : ' '){
+                case '.':
+                    if( !choppedString.toString().endsWith("...")){
+                        if( choppedString.toString().endsWith("..")){
+                            choppedString.append('.');
+                        }else {
+                            choppedString.append("..");
+                        }
+                    }
+                    break;
+                default:
+                    final int lastSpace = choppedString.lastIndexOf(" ");
+
+                    if (lastSpace >= 0) {
+                        choppedString.setLength(lastSpace+1);
+                    }
+                    choppedString.append("...");
+                    break;
+           }
+            
+
+        }
+
+        // balance opening tags if the chop happened inbetween open and close 
tags.
+        final LinkedList<String> tags = new LinkedList<String>();
+
+        final Matcher matcher = openTag.matcher(choppedString);
+        while( matcher.find() ){
+            if( closeTag.matcher(matcher.group()).find()) {
+                try {
+                    tags.removeFirst();
+                } catch (NoSuchElementException ex) {
+                    LOG.warn(MALFORMED_HTML_ESCAPING + s);
+                    return StringEscapeUtils.escapeHtml(s); 
+                }
+            }else if( !singleTag.matcher(matcher.group()).find() ){
+                tags.addFirst(matcher.group());
+            }
+        }
+
+        for(String tag : tags){
+            choppedString.append(tag.replaceFirst("<","</"));
+        }        
+        
+        LOG.trace(DEBUG_CHOPSUEY + choppedString);
+        
+        return choppedString.toString();
+    }
+    
+    // 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

Reply via email to