Package java.lang

Examples of java.lang.StringBuffer


     * @param   fileTemplate    the regex to be used to identify dspace log files
     */
    public static void setRegex(String fileTemplate)
    {
        // build the exclude characters regular expression
        StringBuffer charRegEx = new StringBuffer();
        charRegEx.append("[");
        for (int i = 0; i < excludeChars.size(); i++)
        {
            charRegEx.append("\\" + (String) excludeChars.get(i));
        }
        charRegEx.append("]");
        excludeCharRX = Pattern.compile(charRegEx.toString());
       
        // regular expression to find handle indicators in strings
        handleRX = Pattern.compile("handle=");
       
        // regular expression to find item_id indicators in strings
        itemRX = Pattern.compile(",item_id=.*$");
       
        // regular expression to find query indicators in strings
        queryRX = Pattern.compile("query=");
       
        // regular expression to find collections in strings
        collectionRX = Pattern.compile("collection_id=[0-9]*,");
       
        // regular expression to find communities in strings
        communityRX = Pattern.compile("community_id=[0-9]*,");
       
        // regular expression to find search result sets
        resultsRX = Pattern.compile(",results=(.*)");
       
        // regular expressions to find single characters anywhere in the string
        singleRX = Pattern.compile("( . |^. | .$)");
       
        // set up the standard log file line regular expression
        String logLine13 = "^(\\d\\d\\d\\d-\\d\\d\\-\\d\\d) \\d\\d:\\d\\d:\\d\\d,\\d\\d\\d (\\w+)\\s+\\S+ @ ([^:]+):[^:]+:([^:]+):(.*)";
        String logLine14 = "^(\\d\\d\\d\\d-\\d\\d\\-\\d\\d) \\d\\d:\\d\\d:\\d\\d,\\d\\d\\d (\\w+)\\s+\\S+ @ ([^:]+):[^:]+:[^:]+:([^:]+):(.*)";
        valid13 = Pattern.compile(logLine13);
        valid14 = Pattern.compile(logLine14);
       
        // set up the pattern for validating log file names
        logRegex = Pattern.compile(fileTemplate);
       
        // set up the pattern for matching any of the query types
        StringBuffer typeRXString = new StringBuffer();
        typeRXString.append("(");
        for (int i = 0; i < excludeTypes.size(); i++)
        {
            if (i > 0)
            {
                typeRXString.append("|");
            }
            typeRXString.append((String) excludeTypes.get(i));
        }
        typeRXString.append(")");
        typeRX = Pattern.compile(typeRXString.toString());
       
        // set up the pattern for matching any of the words to exclude
        StringBuffer wordRXString = new StringBuffer();
        wordRXString.append("(");
        for (int i = 0; i < excludeWords.size(); i++)
        {
            if (i > 0)
            {
                wordRXString.append("|");
            }
            wordRXString.append(" " + (String) excludeWords.get(i) + " ");
            wordRXString.append("|");
            wordRXString.append("^" + (String) excludeWords.get(i) + " ");
            wordRXString.append("|");
            wordRXString.append(" " + (String) excludeWords.get(i) + "$");
        }
        wordRXString.append(")");
        wordRX = Pattern.compile(wordRXString.toString());
       
        return;
    }
View Full Code Here


                        " WHERE element = 'type' " +
                        " AND qualifier IS NULL) ";
        }
       
        // start the date constraint query buffer
        StringBuffer dateQuery = new StringBuffer();
        if (oracle)
        {
            dateQuery.append("SELECT /*+ ORDERED_PREDICATES */ item_id ");
        }
        else
        {
            dateQuery.append("SELECT item_id ");
        }

        dateQuery.append("FROM metadatavalue " +
                          "WHERE metadata_field_id = (" +
                          " SELECT metadata_field_id " +
                          " FROM metadatafieldregistry " +
                          " WHERE element = 'date' " +
                          " AND qualifier = 'accessioned') ");
     
        if (startDate != null)
        {
            if (oracle)
            {
                dateQuery.append(" AND TO_TIMESTAMP( TO_CHAR(text_value), "+
                        "'yyyy-mm-dd\"T\"hh24:mi:ss\"Z\"' ) > TO_DATE('" +
                        unParseDate(startDate) + "', 'yyyy-MM-dd') ");
            }
            else
            {
                dateQuery.append(" AND text_value::timestamp > '" +
                        unParseDate(startDate) + "'::timestamp ");
            }
        }

        if (endDate != null)
        {
            if (oracle)
            {
                dateQuery.append(" AND TO_TIMESTAMP( TO_CHAR(text_value), "+
                        "'yyyy-mm-dd\"T\"hh24:mi:ss\"Z\"' ) < TO_DATE('" +
                        unParseDate(endDate) + "', 'yyyy-MM-dd') ");
            }
            else
            {
                dateQuery.append(" AND text_value::timestamp < '" +
                        unParseDate(endDate) + "'::timestamp ");
            }
        }
       
        // build the final query
        StringBuffer query = new StringBuffer();
       
        query.append("SELECT COUNT(*) AS num " +
                  "FROM item " +
                  "WHERE in_archive = " + (oracle ? "1 " : "true ") +
                  "AND withdrawn = " + (oracle ? "0 " : "false "));
       
        if (startDate != null || endDate != null)
        {
            query.append(" AND item_id IN ( " +
                         dateQuery.toString() + ") ");
        }

        if (type != null)
        {
            query.append(" AND item_id IN ( " +
                         typeQuery + ") ");
        }
       
        TableRow row = DatabaseManager.querySingle(context, query.toString());

        Integer numItems;
        if (oracle)
        {
            numItems = new Integer(row.getIntColumn("num"));
View Full Code Here

      if (tmp.length() == 0)
      {
        return tmp;
      }
      String arrRows [] = tmp.split("\n");
      StringBuffer sp = new StringBuffer ();
      int max = arrRows.length;
      String row;
      int cntTyhjia_riveja = 0;
      for(int i = 0; i < max; i++)
      {
        row = arrRows[i];
        if (row == null || row.trim().length() == 0)
        {         
          if (tyhjien_rivien_lkm < 1)
              continue;
          if (cntTyhjia_riveja >= tyhjien_rivien_lkm)
            continue;
           cntTyhjia_riveja++;
           sp.append("\n");
           continue;
        }
        cntTyhjia_riveja = 0;
        sp.append(removeSpacesFromBeginOfRow(row)+"\n");
      }
     
      return sp.toString();     
   }
View Full Code Here

    }     
   
    char [] arrCh = tmp.toCharArray();
    int max = arrCh.length;
    StringTokenizer tokens = new StringTokenizer(tmp);
    StringBuffer sb = new StringBuffer();
    String token;
   
    for(;tokens.hasMoreTokens();)
    {
    token = tokens.nextToken();
    if (token == null)
      continue;
    if (token.trim().length() == 0)
    {
      //System.out.println("if (token.trim().length() == 0)");
      continue;
    }
    arrCh = tmp.trim().toCharArray();
    max = arrCh.length;
    boolean hasOnlyEnters = true;
    for(int i = 0; i < max; i++)
      if (Character.isLetterOrDigit(arrCh[i]))
      {
        hasOnlyEnters = false;
        break;
      }
    if (!hasOnlyEnters)
      sb.append(token +' ');   
    }
   
    //System.out.println("d:removeDupleSpace 4 tmp='" +tmp +"'");
    return sb.toString();
   }  
View Full Code Here

        public ConvertedRow
        removeOrConvertChars(String tmp, String [] arrSearch,
            String [] arrReplace, boolean bRegexReplace,
            CharArea [] arrExcludeAreas)
        {
           StringBuffer sb = new StringBuffer();
           String strSearch, strReplace;
          
           int max_search = arrSearch.length;
           int max_replace = arrReplace.length;
      
           int max = tmp.length();
           byte [] arrByteChangedChars = new byte[max];
           for(int i = 0; i < max; i++)
           {
           arrByteChangedChars[i] = 0;
           }
          
           // String inputString = new String(tmp);
          
           char chCurrent = 0;
           char chReplace = 0;
           int ichCurrent;
           boolean bCharFounded = false;
        
           for(int k = 0 ; k < max; k++ )
         {
             chCurrent = tmp.charAt(k);
             ichCurrent = chCurrent;
             chReplace = chCurrent;
             bCharFounded = false;
             strReplace = null;
             for(int i = 0 ; i < max_search; i++ )
             {
                 strSearch = arrSearch[i];
               if (strSearch == null)
                 continue;
               if (strSearch.toString().trim().length() == 0)
               {
                 //System.out.println("if (token.trim().length() == 0)");
                 continue;
               }
               strReplace = arrReplace[i];
               /*
               if (tmp.contains(strMuutettava))
               {
                 int ind = tmp.indexOf(strMuutettava);
                 //System.out.println(strMuutettava +"='" + strMuutettava +" " +ind);
               }
               */
               if (strReplace == null)
                 strReplace = ""; // tmp = tmp.replaceAll(strSearch, "");
              
               char chSearch = 0; // testi koodia:
               if (strSearch.length()>0)
                  chSearch = strSearch.charAt(0);
               int iSearch = chSearch;
               char chReplaceNewValue = 0;
               if (strReplace.length()>0)
                 chReplaceNewValue = strReplace.charAt(0);
               int iReplaceNewValue = chReplaceNewValue; // testikoodia loppu
               // regex-muutos kutsu: jos regexin erikoismerkkejä hakuarvoissa,
               // ne pitää koodata hakuarvoihin erikseen!!! Huom! Erotin merkkeinä \\\\
               // eli kääntäjä muuttaa sen ajossa \\ merkkeiksi.
               //if (bRegexReplace)
                 //tmp = tmp.replaceAll(strMuutettava, strkorvattava);
               //else
                 //tmp = replaceAll(tmp, strMuutettava, strkorvattava);
               if (chCurrent == chSearch)
               {
                 chReplace = chReplaceNewValue;
                 bCharFounded = true;
                 break;
               }                             
             }
             //if (chReplace == chCurrent || chReplace != 0)
             if (!bCharFounded)
               sb.append(chCurrent);
             else
             if (strReplace != null)
               sb.append(strReplace);
             if (bCharFounded && (strReplace != null
               && !strReplace.equals("" +chCurrent))
               || strReplace == null /* chReplace != chCurrent */ )
             arrByteChangedChars[k] = 1;
         }
                  
           /*  Vanhaa koodia; ei toimi, koska StringTokenizer ei selviydy jakamisesta
            * oikein esim: \\\\ , vaan ohittaa kyseisen kohdan siististi päätyen \\\\
            * kohdan jälkeiseen taulukon alkioon.
           StringTokenizer tokenMuutettavat = new StringTokenizer(muutettavatMerkit, haeMerkkeja);
           StringTokenizer tokenkorvattavat = new StringTokenizer(korvattavatMerkit, haeMerkkeja);
           */ 
           //System.out.println("d:removeDupleSpace 4 tmp='" +tmp +"'");
          
           /*
           int maxEA = arrExcludeAreas.length;
           int ind, chEnd;
           CharArea ca;
          
         int max = tmp.length();
           byte [] arrByteChangedChars = new byte[max];
           for(int i = 0; i < max; i++)
           {
           arrByteChangedChars[i] = 0;
           }
             
           for(int i = 0; i < maxEA; i++)
           {
           ca = arrExcludeAreas[i];
           if (ca == null)
             continue;
           chEnd = ca.getChEndChar();
           for (int j = ca.getChStartChar(); j < chEnd; j++)
           {
             if (isCharIn((char)j, arrMuutettavat))
               continue;
             ind = tmp.indexOf("" + j);
             if (ind == -1)
               continue;
             arrByteChangedChars[i] = 1;  // wrong none-changed excluded char founded
           }
           }
           */
           return new ConvertedRow(tmp, sb.toString(), arrByteChangedChars);
           // return tmp;
            }
View Full Code Here

     //}
     final String cnstII = "<i><i>";
     newData = tmp.replaceAll(cnstII, "<i>");
     tmp = newData;
     if (newData != null)
       sp = new StringBuffer(newData);
   }
View Full Code Here

   private  String
   poistaKTaiIKoodinEdestaTyhjiaRivinvaihtojaJosOn()
   {
     int cntPTR = sp.length();
     int i = cntPTR-1;
     StringBuffer spTmp = new StringBuffer (sp.toString());
       char ch;
      
     while(i > -1)
     {
       ch = spTmp.charAt(i);
       if ( ch != '\n' && !Character.isWhitespace(ch))
       {
         spTmp.append('\n');
         sp = spTmp;        
         return spTmp.toString();
       }
        

       spTmp.deleteCharAt(i);
       i--;
     }

     spTmp.append('\n');
     sp = spTmp;
     return spTmp.toString();
   }
View Full Code Here

     int len = value.length(), i = 0;
     if (strErikoismerkkijono_rivin_alussa != null)
       i = strErikoismerkkijono_rivin_alussa.length();
     boolean isWhiteSpace = false;
    
     StringBuffer spTmp = new StringBuffer (value);
      
     while(cntPTR > 0 && i < len)
     {
       isWhiteSpace = false;
       if (!Character.isWhitespace(spTmp.charAt(i)))
         return false;
       isWhiteSpace = true;
       spTmp.deleteCharAt(i);
       len = spTmp.length();
       cntPTR--;
     }

       //System.out.println("1strErikoismerkkijono_rivin_alussa=" + value);
     return true;
View Full Code Here

         htValues.put(htKey, htValue);        
        
         bEkaKierros = false;
       }
      
       StringBuffer configIsMissing = new StringBuffer();
       if (str_readcharacterset == null)
         configIsMissing.append("config value readcharacterset is missing!\n");
       if (str_writecharacterset == null)
         configIsMissing.append("config value writecharacterset is missing!\n");
       /*
       if (str_allowedcharacterset == null)
         configIsMissing.append("config value allowedcharacterset is missing!\n");
       if (str_allowedcharareas == null)
         configIsMissing.append("config value allowedcharareas is missing!\n");
       */
       if (str_excludecharareas == null)
         configIsMissing.append("config value excludecharareas is missing!\n");
      
       if (configIsMissing.length() > 0)
         throw new CharConvertRowsException("Error: " + configIsMissing.toString());
      
       // arvoilla kutsutaan: m_dtBook2Genre.removeOrConvertChars(..,..,..)
       //m_strKorvattavat = spKorvattavat.toString().trim();
       //m_strMuutettavat  = spMuutettavat.toString().trim();
       Object arrObjMuutettavat [] =  htValues.keySet().toArray();
View Full Code Here

   throws Exception
   {
     int i, iRow, iRowChar, indErrorPos, iChError,
     iLen = text.length();    
    char ch, chCharSet;
     StringBuffer sbErrorRow = new StringBuffer();
     StringBuffer sbErrorData = new StringBuffer();
     boolean bErrorFounded = false;
     String strCh, strCharSet, strErrorRow;
    
     iRowChar = 0;
     iRow = 1;
    
     for(i = 0; i < iLen; i++)
     {
       iRowChar++;
       ch = text.charAt(i);
       if (ch == '\n')
       {
        iRowChar = 0;
        if (bErrorFounded)
        {
             m_bPossibleErrorCharachters = true;
             sbErrorData.append(sbErrorRow.toString());
        }
         bErrorFounded = false;
        strErrorRow = "";
        sbErrorRow = new StringBuffer ();
        // dddd sbErrorRowPosition
        iRow++;
       }
       
       strCh = "" + ch;
View Full Code Here

TOP

Related Classes of java.lang.StringBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.