TKMarkupCharParamClass.java :  » Content-Management-System » webman » com » teamkonzept » publishing » markups » Java Open Source

Java Open Source » Content Management System » webman 
webman » com » teamkonzept » publishing » markups » TKMarkupCharParamClass.java
/*
 * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/publishing/markups/TKMarkupCharParamClass.java,v 1.5 2000/05/22 15:01:27 careck Exp $
 *
 */
package com.teamkonzept.publishing.markups;

public class TKMarkupCharParamClass extends TKMarkupParamClass {

  public String checkValue (String raw) {

    if (raw == null) return raw;

    String value = raw.trim();

    if (value.length() == 1) return value;
    else return null;
  }

  public int parseUnquotedValue (String text, int pos, StringBuffer value) 
    throws TKMarkupParserException {

    if (value != null) value.setLength (0);

    int oldPos = pos;
    pos = parsePattern (text,pos,null,"'");
    if (pos <= oldPos) return oldPos;
    
    if (pos < text.length()) {
    
      char chr = text.charAt (pos);

      if ((chr == '\\') && (pos+1 < text.length())) {
      
        if (value == null) pos++;
        else value.append (text.charAt (++pos));
        
      } else if (value != null) value.append (chr);

      pos++;
    }

    int nextOldPos = pos;
    pos = parsePattern (text,pos,null,"'");

    if (pos <= nextOldPos) return oldPos;
    else return pos;
  }

  public String wrapValue (String value) {

    if ((value == null) || (value.length() == 0)) return null;
    
    StringBuffer buf = new StringBuffer();

    char chr = value.charAt(0);
    
    if (chr == '\'') return "'\\''";
    else if (chr == '\'') return "'\\\\'";
    
    buf.append ('\'').append(chr).append('\'');
    
    return buf.toString();
  }
}

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.