java.io.CharConversionException Java Examples

The following examples show how to use java.io.CharConversionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UncheckedItems.java    From tikione-steam-cleaner with MIT License 6 votes vote down vote up
/**
 * Set the list of unchecked items to memorize.
 *
 * @param items the items to memorize.
 * @throws CharConversionException if an error occurs while setting the list from the file (invalid characters).
 * @throws InfinitiveLoopException if an error occurs while setting the list from the file (file parsing error).
 */
@SuppressWarnings("Duplicates")
public void setUncheckedItems(List<String> items)
        throws CharConversionException,
        InfinitiveLoopException {
    List<String> prevItems = getUncheckedItems();
    if (!prevItems.containsAll(items) || !items.containsAll(prevItems)) {
        updated = true;
        StringBuilder buffer = new StringBuilder(512);
        boolean first = true;
        for (String item : items) {
            if (first) {
                buffer.append(item);
            } else {
                buffer.append('\"').append(item);
            }
            first = false;
        }
        ini.setKeyValue(CONFIG_UNCHECKED_REDIST_ITEMS, CONFIG_UNCHECKED_REDIST_ITEMS__ITEM_LIST, buffer.toString());
    }
}
 
Example #2
Source File: ProjectsRootNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override String getHtmlDisplayName() {
    String htmlName = getOriginal().getHtmlDisplayName();
    if (htmlName == null) {
        try {
            htmlName = XMLUtil.toElementContent(getOriginal().getDisplayName());
        } catch (CharConversionException ex) {
            // ignore
        }
    }
    if (htmlName == null) {
        return null;
    }
    if (files != null && files.iterator().hasNext()) {
        try {
            String annotatedMagic = files.iterator().next().getFileSystem().
                    getDecorator().annotateNameHtml(MAGIC, files);
            if (annotatedMagic != null) {
                htmlName = annotatedMagic.replace(MAGIC, htmlName);
            }
        } catch (FileStateInvalidException e) {
            LOG.log(Level.INFO, null, e);
        }
    }      
    return isMainAsync()? "<b>" + htmlName + "</b>" : htmlName;
}
 
Example #3
Source File: AdjustConfigurationPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    AnalyzerFactory a = (AnalyzerFactory) value;
    String text = SPIAccessor.ACCESSOR.getAnalyzerDisplayName(a);
    boolean isErroneous;
    synchronized (errors) {
        isErroneous = errors.containsKey(a);
    }
    if (isErroneous) {
        try {
            text = "<html><font color='ref'>" + XMLUtil.toElementContent(text);
        } catch (CharConversionException ex) {
            LOG.log(Level.FINE, null, ex);
        }
    }
    return super.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus);
}
 
Example #4
Source File: BootCPNodeFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public String getHtmlDisplayName() {
    final Pair<String, JavaPlatform> platHolder = pp.getPlatform();
    if (platHolder == null) {
        return null;
    }
    final JavaPlatform jp = platHolder.second();
    if (jp == null || !jp.isValid()) {
        String displayName = this.getDisplayName();
        try {
            displayName = XMLUtil.toElementContent(displayName);
        } catch (CharConversionException ex) {
            // OK, no annotation in this case
            return null;
        }
        return "<font color=\"#A40000\">" + displayName + "</font>"; //NOI18N
    } else {
        return null;
    }
}
 
Example #5
Source File: ServletOutputStream.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
    * Writes a <code>String</code> to the client, 
    * without a carriage return-line feed (CRLF) 
    * character at the end.
    *
    *
    * @param s			the <code>String</code> to send to the client
    *
    * @exception IOException 	if an input or output exception occurred
    *
    */

   public void print(String s) throws IOException {
if (s==null) s="null";
int len = s.length();
for (int i = 0; i < len; i++) {
    char c = s.charAt (i);

    //
    // XXX NOTE:  This is clearly incorrect for many strings,
    // but is the only consistent approach within the current
    // servlet framework.  It must suffice until servlet output
    // streams properly encode their output.
    //
    if ((c & 0xff00) != 0) {	// high order byte must be zero
	String errMsg = lStrings.getString("err.not_iso8859_1");
	Object[] errArgs = new Object[1];
	errArgs[0] = new Character(c);
	errMsg = MessageFormat.format(errMsg, errArgs);
	throw new CharConversionException(errMsg);
    }
    write (c);
}
   }
 
Example #6
Source File: NotificationImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private JComponent createDetails(String text, ActionListener action) {
    try {
        text = (action == null ? "<html>" : "<html><a href=\"_blank\">") + XMLUtil.toElementContent(text); //NOI18N
    } catch (CharConversionException ex) {
        throw new IllegalArgumentException(ex);
    }
    if (null == action) {
        return new JLabel(text);
    }
    JButton btn = new JButton(text);
    btn.setFocusable(false);
    btn.setBorder(BorderFactory.createEmptyBorder());
    btn.setBorderPainted(false);
    btn.setFocusPainted(false);
    btn.setOpaque(false);
    btn.setContentAreaFilled(false);
    btn.addActionListener(action);
    btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    Color c = UIManager.getColor("nb.html.link.foreground"); //NOI18N
    if (c != null) {
        btn.setForeground(c);
    }
    return btn;
}
 
Example #7
Source File: Utilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static String target2String(TypeElement target) {
    final Name qualifiedName = target.getQualifiedName(); //#130759
    if (qualifiedName == null) {
        Logger.getLogger(Utilities.class.getName()).warning("Target qualified name could not be resolved."); //NOI18N
        return ""; //NOI18N
    } else {
        String qnString = qualifiedName.toString();
        if (qnString.length() == 0) {
            //probably an anonymous class
            qnString = target.asType().toString();
        }

        try {
            qnString = XMLUtil.toElementContent(qnString);
        } catch (CharConversionException ex) {
            Logger.getLogger(Utilities.class.getName()).log(Level.FINE, null, ex);
        }

        return qnString;
    }
}
 
Example #8
Source File: BreadCrumbsNodeImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static String escape(String s) {
    if (s != null) {
        //unescape unicode sequences first (would be better if Pretty would not print them, but that might be more difficult):
        Matcher matcher = UNICODE_SEQUENCE.matcher(s);
        
        if (matcher.find()) {
            StringBuilder result = new StringBuilder();
            int lastReplaceEnd = 0;
            do {
                result.append(s.substring(lastReplaceEnd, matcher.start()));
                int ch = Integer.parseInt(matcher.group(1), 16);
                result.append((char) ch);
                lastReplaceEnd = matcher.end();
            } while (matcher.find());
            result.append(s.substring(lastReplaceEnd));
            s = result.toString();
        }
        try {
            return XMLUtil.toAttributeValue(s);
        } catch (CharConversionException ex) {
        }
    }
    return null;
}
 
Example #9
Source File: DataEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected String messageHtmlName() {
    if (! obj.isValid()) {
        return null;
    }

    String name = obj.getNodeDelegate().getHtmlDisplayName();
    if (name == null) {
        try {
            name = XMLUtil.toElementContent(obj.getNodeDelegate().getDisplayName());
        } catch (CharConversionException ex) {
            return null;
        }
    }

    return annotateName(name, true, isModified(), !obj.getPrimaryFile().canWrite());
}
 
Example #10
Source File: ServletOutputStream.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Writes a <code>String</code> to the client, without a carriage
 * return-line feed (CRLF) character at the end.
 * 
 * @param s
 *            the <code>String</code> to send to the client
 * @exception IOException
 *                if an input or output exception occurred
 */
public void print(String s) throws IOException {
    if (s == null)
        s = "null";
    int len = s.length();
    for (int i = 0; i < len; i++) {
        char c = s.charAt(i);

        //
        // XXX NOTE: This is clearly incorrect for many strings,
        // but is the only consistent approach within the current
        // servlet framework. It must suffice until servlet output
        // streams properly encode their output.
        //
        if ((c & 0xff00) != 0) { // high order byte must be zero
            String errMsg = lStrings.getString("err.not_iso8859_1");
            Object[] errArgs = new Object[1];
            errArgs[0] = Character.valueOf(c);
            errMsg = MessageFormat.format(errMsg, errArgs);
            throw new CharConversionException(errMsg);
        }
        write(c);
    }
}
 
Example #11
Source File: Patterns.java    From tikione-steam-cleaner with MIT License 6 votes vote down vote up
private List<Redist> getRedistPatternsAndDesc(String configKey)
        throws CharConversionException,
        InfinitiveLoopException {
    List<Redist> redistList = new ArrayList<>(8);
    List<String> redistTokens = new ArrayList<>(64);
    for (Ini singleIni : inis) {
        String[] tokens = singleIni.getKeyValue("", CONFIG_REDIST_PATTERNS, configKey).split("\"", 0);
        redistTokens.addAll(Arrays.asList(tokens));
    }
    boolean FileDescToggle = true;
    String redistName = null;
    String redtsiDescription;
    for (String redist : redistTokens) {
        if (redist.length() > 0) { // Skip first and last tokens.
            if (FileDescToggle) {
                redistName = redist;
            } else {
                redtsiDescription = redist;
                redistList.add(new Redist(redistName, redtsiDescription));
            }
            FileDescToggle ^= true;
        }
    }
    return redistList;
}
 
Example #12
Source File: PlatformNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public String getHtmlDisplayName () {
    final Pair<String,JavaPlatform> platHolder = pp.getPlatform();
    if (platHolder == null) {
        return null;
    }
    final JavaPlatform jp = platHolder.second();
    if (jp == null || !jp.isValid()) {
        String displayName = this.getDisplayName();
        try {
            displayName = XMLUtil.toElementContent(displayName);
        } catch (CharConversionException ex) {
            // OK, no annotation in this case
            return null;
        }
        return "<font color=\"#A40000\">" + displayName + "</font>"; //NOI18N
    } else {
        return null;
    }
}
 
Example #13
Source File: Config.java    From tikione-steam-cleaner with MIT License 6 votes vote down vote up
public List<String> getPossibleSteamFolders()
        throws CharConversionException,
        InfinitiveLoopException {
    String folderList = ini.getKeyValue("/", CONFIG_STEAM_FOLDERS, CONFIG_STEAM_FOLDERS__POSSIBLE_DIRS);
    String[] patterns = folderList.split(Matcher.quoteReplacement(";"), 0);
    List<String> allSteamPaths = new ArrayList<>(80);
    File[] roots = File.listRoots();
    String[] driveLetters = new String[roots.length];
    for (int nRoot = 0; nRoot < roots.length; nRoot++) {
        driveLetters[nRoot] = roots[nRoot].getAbsolutePath();
    }
    String varDriveLetter = /* Matcher.quoteReplacement( */ "{drive_letter}"/* ) */;
    for (String basePattern : patterns) {
        for (String driveLetter : driveLetters) {
            allSteamPaths.add(basePattern.replace(varDriveLetter, driveLetter));
        }
    }
    Collections.addAll(allSteamPaths, patterns);
    return allSteamPaths;
}
 
Example #14
Source File: TextDetail.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Append part of line that is before matched text.
 *
 * @param text Buffer to append to.
 * @param prefixStart Line index of the first character to be displayed.
 * @param matchStart Line index of the matched text.
 * @param trim Skip leading whitespace characters.
 */
private void appendMarkedTextPrefix(StringBuilder text, int prefixStart,
        int matchStart, boolean trim) throws CharConversionException {
    int first = 0; // index of first non-whitespace character
    if (trim) {
        CharSequence lineText = txtDetail.getLineText();
        while (first < matchStart && lineText.charAt(first) <= '\u0020') {
            first++;
        }
    }
    if (prefixStart > 0 && first < prefixStart) {
        text.append(ELLIPSIS);
    }
    text.append(escape(txtDetail.getLineTextPart(
            Math.max(prefixStart, first), matchStart)));
}
 
Example #15
Source File: BasicInfoPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages("ERR_Coord_breaks_pom=Error: Group Id or Artifact Id would invalidate Maven POM xml file.")
private boolean checkCoord(JTextField field) {
    String coord = field.getText();
    boolean result = false;
    try {
        String escaped = XMLUtil.toAttributeValue(coord);
        result = escaped.length() == coord.length() && coord.indexOf(">") == -1
                && coord.indexOf(" ") == -1;
    } catch (CharConversionException ex) {
        // ignore this one
    }
    if (result) {
        result = !containsMultiByte(coord);
    } else {
        category.setErrorMessage(ERR_Coord_breaks_pom());
    }

    if (result) {
        category.setErrorMessage(null);
    }

    return result;
}
 
Example #16
Source File: NotificationImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private JComponent createDetails( String text, ActionListener action ) {
    if( null == action ) {
        return new JLabel(text);
    }
    try {
        text = "<html><u>" + XMLUtil.toElementContent(text); //NOI18N
    } catch( CharConversionException ex ) {
        throw new IllegalArgumentException(ex);
    }
    JButton btn = new JButton(text);
    btn.setFocusable(false);
    btn.setBorder(BorderFactory.createEmptyBorder());
    btn.setBorderPainted(false);
    btn.setFocusPainted(false);
    btn.setOpaque(false);
    btn.setContentAreaFilled(false);
    btn.addActionListener(action);
    btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    Color c = UIManager.getColor("nb.html.link.foreground"); //NOI18N
    if (c != null) {
        btn.setForeground(c);
    }
    return btn;
}
 
Example #17
Source File: HudsonJobBuildNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public HudsonJobBuildNode(HudsonJobBuild build) {
    super(makeChildren(build), Lookups.singleton(build));
    setName(Integer.toString(build.getNumber()));
    setDisplayName(NbBundle.getMessage(HudsonJobBuildNode.class, "HudsonJobBuildNode.displayName", build.getNumber()));
    Color effectiveColor;
    if (build.isBuilding()) {
        effectiveColor = build.getJob().getColor();
    } else {
        effectiveColor = Utilities.getColorForBuild(build);
    }
    try {
        htmlDisplayName = effectiveColor.colorizeDisplayName(XMLUtil.toElementContent(getDisplayName()));
    } catch (CharConversionException x) {
        htmlDisplayName = null;
    }
    setIconBaseWithExtension(effectiveColor.iconBase());
    this.build = build;
}
 
Example #18
Source File: ServletOutputStream.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Writes a <code>String</code> to the client, without a carriage
 * return-line feed (CRLF) character at the end.
 * 
 * @param s
 *            the <code>String</code> to send to the client
 * @exception IOException
 *                if an input or output exception occurred
 */
public void print(String s) throws IOException {
    if (s == null)
        s = "null";
    int len = s.length();
    for (int i = 0; i < len; i++) {
        char c = s.charAt(i);

        //
        // XXX NOTE: This is clearly incorrect for many strings,
        // but is the only consistent approach within the current
        // servlet framework. It must suffice until servlet output
        // streams properly encode their output.
        //
        if ((c & 0xff00) != 0) { // high order byte must be zero
            String errMsg = lStrings.getString("err.not_iso8859_1");
            Object[] errArgs = new Object[1];
            errArgs[0] = Character.valueOf(c);
            errMsg = MessageFormat.format(errMsg, errArgs);
            throw new CharConversionException(errMsg);
        }
        write(c);
    }
}
 
Example #19
Source File: XmlReader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public int read(char buf [], int offset, int len) throws IOException {
    int i, c;

    if (instream == null)
        return -1;

    for (i = 0; i < len; i++) {
        if (start >= finish) {
            start = 0;
            finish = instream.read(buffer, 0, buffer.length);
            if (finish <= 0) {
                if (finish <= 0)
                    this.close();
                break;
            }
        }
        c = buffer[start++];
        if ((c & 0x80) != 0)
            throw new CharConversionException("Illegal ASCII character, 0x"
                    + Integer.toHexString(c & 0xff));
        buf[offset + i] = (char) c;
    }
    if (i == 0 && finish <= 0)
        return -1;
    return i;
}
 
Example #20
Source File: CustomizerComponentFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Component getListCellRendererComponent(JList list, Object value,
        int index, boolean isSelected, boolean cellHasFocus) {
    String text;
    if (value == UIUtil.WAIT_VALUE) {
        text = UIUtil.WAIT_VALUE;
    } else if (value == INVALID_PLATFORM) {
        text = INVALID_PLATFORM;
        renderer.setHtml(true);
    } else {
        ModuleDependency md = (ModuleDependency) value;
        // XXX the following is wrong; spec requires additional logic:
        boolean bold = boldfaceApiModules && md.getModuleEntry().getPublicPackages().length > 0;
        boolean deprecated = md.getModuleEntry().isDeprecated();
        renderer.setHtml(bold || deprecated);
        String locName = md.getModuleEntry().getLocalizedName();
        text = locName;
        if (bold || deprecated) {
            try {
                text = "<html>" + (bold ? "<b>" : "") + (deprecated ? "<s>" : "") + XMLUtil.toElementContent(locName); // NOI18N
            } catch (CharConversionException e) {
                // forget it
            }
        }
    }
    return renderer.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus);
}
 
Example #21
Source File: XmlReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public int read(char buf [], int offset, int len) throws IOException {
    int i, c;

    if (instream == null)
        return -1;

    for (i = 0; i < len; i++) {
        if (start >= finish) {
            start = 0;
            finish = instream.read(buffer, 0, buffer.length);
            if (finish <= 0) {
                if (finish <= 0)
                    this.close();
                break;
            }
        }
        c = buffer[start++];
        if ((c & 0x80) != 0)
            throw new CharConversionException("Illegal ASCII character, 0x"
                    + Integer.toHexString(c & 0xff));
        buf[offset + i] = (char) c;
    }
    if (i == 0 && finish <= 0)
        return -1;
    return i;
}
 
Example #22
Source File: XmlReader.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public int read(char buf [], int offset, int len) throws IOException {
    int i, c;

    if (instream == null)
        return -1;

    for (i = 0; i < len; i++) {
        if (start >= finish) {
            start = 0;
            finish = instream.read(buffer, 0, buffer.length);
            if (finish <= 0) {
                if (finish <= 0)
                    this.close();
                break;
            }
        }
        c = buffer[start++];
        if ((c & 0x80) != 0)
            throw new CharConversionException("Illegal ASCII character, 0x"
                    + Integer.toHexString(c & 0xff));
        buf[offset + i] = (char) c;
    }
    if (i == 0 && finish <= 0)
        return -1;
    return i;
}
 
Example #23
Source File: HudsonMavenModuleBuildNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public HudsonMavenModuleBuildNode(HudsonMavenModuleBuild module) {
    super(makeChildren(module), Lookups.singleton(module));
    this.module = module;
    setName(module.getName());
    setDisplayName(module.getDisplayName());
    try {
        htmlDisplayName = module.getColor().colorizeDisplayName(XMLUtil.toElementContent(getDisplayName()));
    } catch (CharConversionException x) {
        htmlDisplayName = null;
    }
    setIconBaseWithExtension(module.getColor().iconBase());
}
 
Example #24
Source File: DashboardUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String escapeXmlChars(String text) {
    String result = text;
    try {
        result = XMLUtil.toElementContent(text);
    } catch (CharConversionException ex) {
    }
    return result;
}
 
Example #25
Source File: TestMethodNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public String getHtmlDisplayName() {
    Status status = testcase.getStatus();

    StringBuffer buf = new StringBuffer(60);
    buf.append(testcase.getDisplayName());
    buf.append("&nbsp;&nbsp;");                                     //NOI18N
    buf.append("<font color='#");                                   //NOI18N
    buf.append(status.getHtmlDisplayColor() + "'>"); //NOI18N

    String cause = null;
    if (INLINE_RESULTS && testcase.getTrouble() != null && testcase.getTrouble().getStackTrace() != null &&
            testcase.getTrouble().getStackTrace().length > 0) {
        try {
            cause = XMLUtil.toElementContent(testcase.getTrouble().getStackTrace()[0]).replace("\n", "&nbsp;"); // NOI18N
        } catch (CharConversionException ex) {
            // We're messing with user testoutput - always risky. Don't complain
            // here, simply fall back to the old behavior of the test runner -
            // don't include the message
            cause = null;
        }
    }

    if (cause != null) {
        cause = TestsuiteNode.cutLine(cause, 
                                      TestsuiteNode.MAX_MSG_LINE_LENGTH,
                                      true); // Issue #172772
        buf.append(DisplayNameMapper.getCauseHTML(status, cause));
    } else {
        buf.append(testcase.getTimeMillis() < 0 ? DisplayNameMapper.getNoTimeHTML(status)
                : DisplayNameMapper.getTimeHTML(status, testcase.getTimeMillis() / 1000f));
    }

    buf.append("</font>");                                          //NOI18N
    return buf.toString();
}
 
Example #26
Source File: LibrariesNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override String getHtmlDisplayName() {
    if (dep.getModuleEntry().isDeprecated()) {
        try {
            return "<s>" + XMLUtil.toElementContent(getDisplayName()) + "</s>"; // NOI18N
        } catch (CharConversionException x) {
            // ignore
        }
    }
    return null;
}
 
Example #27
Source File: LibrariesNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override String getHtmlDisplayName() {
    if (dep.getModuleEntry().isDeprecated()) {
        try {
            return "<s>" + XMLUtil.toElementContent(getDisplayName()) + "</s>"; // NOI18N
        } catch (CharConversionException x) {
            // ignore
        }
    }
    return null;
}
 
Example #28
Source File: SuiteCustomizerLibraries.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override String getHtmlDisplayName() {
    if (isDeprecated()) {
        try {
            return "<html><s>" + XMLUtil.toElementContent(getDisplayName()) + "</s>"; // NOI18N
        } catch (CharConversionException ex) {}
    }
    return null;
}
 
Example #29
Source File: ClientSideProjectLogicalView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public String getHtmlDisplayName() {
    String dispName = super.getDisplayName();
    try {
        dispName = XMLUtil.toElementContent(dispName);
    } catch (CharConversionException ex) {
        return dispName;
    }
    return ClientSideProjectUtilities.hasErrors(project)
            ? "<font color=\"#" + Integer.toHexString(ClientSideProjectUtilities.getErrorForeground().getRGB() & 0xffffff) + "\">" + dispName + "</font>" // NOI18N
            : null;
}
 
Example #30
Source File: XMLUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Check if all passed characters match XML expression [2].
 * @return true if no escaping necessary
 * @throws CharConversionException if contains invalid chars
 */
private static boolean checkAttributeCharacters(String chars)
throws CharConversionException {
    boolean escape = false;

    for (int i = 0; i < chars.length(); i++) {
        char ch = chars.charAt(i);

        if (((int) ch) <= 93) { // we are UNICODE ']'

            switch (ch) {
            case 0x9:
            case 0xA:
            case 0xD:

                continue;

            case '\'':
            case '"':
            case '<':
            case '&':
                escape = true;

                continue;

            default:

                if (((int) ch) < 0x20) {
                    throw new CharConversionException("Invalid XML character &#" + ((int) ch) + ";.");
                }
            }
        }
    }

    return escape == false;
}