Package org.clapper.util.text

Examples of org.clapper.util.text.XStringBuffer


                assert (false);
            }
        }

        XStringBuffer buf = new XStringBuffer();
        Matcher matcher = null;

        synchronized (HTMLUtil.class)
        {
            matcher = entityPattern.matcher (s);
        }

        for (;;)
        {
            String match = null;
            String preMatch = null;
            String postMatch = null;
            if (! matcher.find())
                break;

            match = matcher.group(1);
            preMatch = s.substring (0, matcher.start (1) - 1);

            if (preMatch != null)
                buf.append(preMatch);

            if (s.charAt(matcher.end() - 1) != ';')
            {
                // Not a well-formed entity. Copy into the buffer.
                buf.append(s.substring(matcher.start(), matcher.end()));
                postMatch = s.substring(matcher.end(1));
            }

            else
            {
                // Well-formed entity.
                postMatch = s.substring(matcher.end(1) + 1);
                buf.append(convertEntity(match));
            }

            if (postMatch == null)
                break;

            s = postMatch;
            matcher.reset (s);
        }

        if (s.length() > 0)
            buf.append (s);

        return buf.toString();
    }
View Full Code Here


        ResourceBundle bundle = getResourceBundle();
        Map<Character,String> charToEntityName =
            new HashMap<Character,String>();
        Enumeration<String> keys = bundle.getKeys();
        XStringBuffer buf = new XStringBuffer();

        while (keys.hasMoreElements())
        {
            String key = keys.nextElement();
            String sChar = bundle.getString (key);
            char c = sChar.charAt (0);

            // Transform the bundle key into an entity name by removing the
            // "html_" prefix.

            buf.clear();
            buf.append (key);
            buf.delete ("html_");

            charToEntityName.put (c, buf.toString());
        }

        char[] chars = s.toCharArray();
        buf.clear();

        for (int i = 0; i < chars.length; i++)
        {
            char c = chars[i];

            String entity = charToEntityName.get (c);
            if (entity == null)
            {
                if (! TextUtil.isPrintable(c))
                {
                    buf.append("&#");
                    buf.append(Integer.valueOf(c));
                    buf.append(';');
                }
                else
                {
                    buf.append(c);
                }
            }

            else
            {
                buf.append ('&');
                buf.append(entity);
                buf.append(';');
            }
        }

        return buf.toString();
    }
View Full Code Here

     * @see XStringBuffer#encodeMetacharacters()
     */
    public void write (PrintWriter out)
        throws ConfigurationException
    {
        XStringBuffer  value = new XStringBuffer();
        boolean        firstSection = true;

        out.print (COMMENT_CHARS.charAt (0));
        out.print (" Written by ");
        out.println (this.getClass().getName());
        out.print (COMMENT_CHARS.charAt (0));
        out.print (" on ");
        out.println (new Date().toString());
        out.println();

        for (Section section : sectionsInOrder)
        {
            if (! firstSection)
                out.println();

            out.println (SECTION_START + section.getName() + SECTION_END);
            firstSection = false;

            for (String varName : section.getVariableNames())
            {
                Variable var = section.getVariable (varName);
                value.setLength (0);
                value.append (var.getRawValue());
                //value.encodeMetacharacters();

                out.println (varName + ": " + value.toString());
            }
        }
    }
View Full Code Here

    }

    private void runTest()
    {
        PropertiesMap map = new PropertiesMap (System.getProperties());
        XStringBuffer buf = new XStringBuffer();

        System.out.println ("---------------------------------------" +
                            "---------------------------------------");
        System.out.println ("*** Looping over properties by key set.");
        System.out.println ("---------------------------------------" +
                            "---------------------------------------");
        for (String key : map.keySet())
        {
            buf.clear();
            buf.append (map.get (key));
            buf.encodeMetacharacters();
            System.out.println (key + "=" + buf.toString());
        }

        System.out.println ("---------------------------------------" +
                            "---------------------------------------");
        System.out.println ("*** Looping over properties by entry set.");
        System.out.println ("---------------------------------------" +
                            "---------------------------------------");
        for (Map.Entry<String, String> entry : map.entrySet())
        {
            buf.clear();
            buf.append (entry.getValue());
            buf.encodeMetacharacters();
            System.out.println (entry.getKey() + "=" + buf.toString());
        }
    }
View Full Code Here

TOP

Related Classes of org.clapper.util.text.XStringBuffer

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.