Package org.jboss.portal.common.text

Examples of org.jboss.portal.common.text.CharBuffer


      // Map result = Collections.EMPTY_MAP;

      ParameterMap parameterMap = new ParameterMap();

      String encodedName = null;
      CharBuffer buffer = new CharBuffer(50);


      int pos = 0;
      int len = queryString.length();
      int state = LOOKUP;
      while (true)
      {
         char c;
         if (pos < len)
         {
            c = queryString.charAt(pos++);
         }
         else if (pos == len)
         {
            c = '&';
            pos++;
         }
         else
         {
            break;
         }

         //
         switch(state)
         {
            case LOOKUP:
               if (c == '&')
               {
                  // Do nothing
               }
               else if (c == '=')
               {
                  state = INVALID_CHUNK;
               }
               else
               {
                  state = PARAM_NAME;
                  buffer.append(c);
               }
               break;
            case PARAM_NAME:
               if (c == '&')
               {
                  String tmp = buffer.asString();

                  //
                  try
                  {
                     parameterDecoder.encode(tmp, buffer);
                     append(parameterMap, buffer.asString(false), "");
                  }
                  catch (EncodingException e)
                  {
                     log.debug("Could not decode parameter name " + tmp, e);
                  }

                  //
                  buffer.reset();
                  state = LOOKUP;
               }
               else if (c == '=')
               {
                  encodedName = buffer.asString();
                  buffer.reset();
                  state = PARAM_VALUE;
               }
               else
               {
                  buffer.append(c);
               }
               break;
            case PARAM_VALUE:
               if (c == '&')
               {

                  //
                  try
                  {
                     // Save value
                     String encodedValue = buffer.asString();

                     // Decode parameter name
                     parameterDecoder.encode(encodedName, buffer);
                     String name = buffer.asString(false);

                     // Now decode parameter value
                     try
                     {
                        buffer.reset();
                        parameterDecoder.encode(encodedValue, buffer);
                        String value = buffer.asString();
                        append(parameterMap, name, value);
                     }
                     catch (EncodingException e)
                     {
                        log.debug("Could not decode parameter value " + encodedValue, e);
                     }
                  }
                  catch (EncodingException e)
                  {
                     log.debug("Could not decode parameter name " + encodedName, e);
                  }

                  //
                  buffer.reset();
                  state = LOOKUP;
               }
               else
               {
                  buffer.append(c);
               }
               break;
            case INVALID_CHUNK:
               if (c == '&')
               {
View Full Code Here


      this.serialization = serialization;
   }

   private String renderURL(Map<String, String> parameters, URLFormat format)
   {
      CharBuffer buffer = new CharBuffer();
      buffer.append(clientReq.getScheme());
      buffer.append("://");
      buffer.append(clientReq.getServerName());
      buffer.append(':');
      buffer.append(Integer.toString(clientReq.getServerPort()));
      buffer.append(clientReq.getContextPath());
      buffer.append(clientReq.getServletPath());

      //
      if (clientReq.getPathInfo() != null)
      {
         buffer.append(clientReq.getPathInfo());
      }

      //
      String parameterSeparator = format.getWantEscapeXML() == Boolean.TRUE ? "&amp;" : "&";

      //
      boolean first = true;
      for (Map.Entry<String, String> entry : parameters.entrySet())
      {
         String name = entry.getKey();
         String value = entry.getValue();
         buffer.append(first ? "?" : parameterSeparator);
         buffer.append(name, FastURLEncoder.getUTF8Instance());
         buffer.append('=');
         buffer.append(value, FastURLEncoder.getUTF8Instance());
         first = false;
      }

      //
      String url = buffer.asString();
      return clientResp.encodeURL(url);
   }
View Full Code Here

      {
         return baseName;
      }
      else
      {
         CharBuffer buffer = new CharBuffer(baseName.length() + 15);
         buffer.append(baseName);

         //
         buffer.append('_');

         //
         try
         {
            LocaleFormat.DEFAULT.write(locale, buffer);
         }
         catch (IOException e)
         {
            throw new AssertionError(e);
         }
         catch (ConversionException e)
         {
            throw new AssertionError(e);
         }

         //
         return buffer.asString();
      }
   }
View Full Code Here

   protected String internalToString(Locale locale) throws ConversionException
   {
      try
      {
         CharBuffer buffer = new CharBuffer();
         internalWrite(locale, buffer);
         return buffer.asString();
      }
      catch (IOException e)
      {
         throw new UndeclaredIOException(e);
      }
View Full Code Here

TOP

Related Classes of org.jboss.portal.common.text.CharBuffer

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.