Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * JBoss, Home of Professional Open Source.
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site:
 import static;
Utility class for resolving predefined XML entity and character references.

Jason T. Greene
    private static final HashMap<StringCharacterentities = new HashMap<StringCharacter>(8);
    private static int resolveCharRef(String sourceint posStringBuilder builder)
       int radix = 10;
       if (source.charAt(pos += 2) == 'x')
          radix = 16;
       int end = source.indexOf(';'pos);
       if (end == -1)
          throw .entityResolutionInvalidCharacterReference(source);
       int c = Integer.parseInt(source.substring(posend), radix);
       return end + 1;
    private static int resolveEntityRef(String sourceint posStringBuilder builder)
       int end = source.indexOf(';', ++pos);
       if (end == -1)
          throw .entityResolutionInvalidEntityReference(source);
       String entity = source.substring(posend);
       Character c = .get(entity);
       if (c == null)
          throw .entityResolutionInvalidEntity(entity);
       return end + 1;

Transforms an XML normalized string by resolving all predefined character and entity references

normalized an XML normalized string
a standard java string that is no longer XML normalized
    public static String resolve(String normalized)
       StringBuilder builder = new StringBuilder();
       int end = normalized.length();
       int pos = normalized.indexOf('&');
       int last = 0;
       // No references
       if (pos == -1)
          return normalized;
       while (pos != -1)
         String sub = normalized.subSequence(lastpos).toString();
         int peek = pos + 1;
         if (peek == end)
            throw .entityResolutionInvalidEntityReference(normalized);
         if (normalized.charAt(peek) == '#')
            pos = resolveCharRef(normalizedposbuilder);
            pos = resolveEntityRef(normalizedposbuilder);
         last = pos;
         pos = normalized.indexOf('&'pos);
      if (last < end)
         String sub = normalized.subSequence(lastend).toString();
      return builder.toString();
New to GrepCode? Check out our FAQ X