Example usage for java.lang Character isISOControl

List of usage examples for java.lang Character isISOControl

Introduction

In this page you can find the example usage for java.lang Character isISOControl.

Prototype

public static boolean isISOControl(int codePoint) 

Source Link

Document

Determines if the referenced character (Unicode code point) is an ISO control character.

Usage

From source file:org.eclipse.jubula.client.ui.rcp.databinding.validators.TestDataManagerNameValidator.java

/**
 * @param stringValue name to check//w  ww . j av  a2  s  . c  om
 * @return IStatus.OK if this is a valid component name, error status
 * otherwise
 */
public static IStatus isValidTestDataCubeString(String stringValue) {
    if (StringUtils.isEmpty(stringValue)) {
        return ValidationStatus.error(Messages.TestDataCubeErrorEmpty);
    }
    if (stringValue.startsWith(StringConstants.SPACE) || stringValue.charAt(stringValue.length() - 1) == ' ') {

        return ValidationStatus.error(Messages.TestDataCubeErrorNoSpaceAtStartOrEnd);
    }
    for (char ch : stringValue.toCharArray()) {
        if (Character.isISOControl(ch)) {
            return ValidationStatus.error(Messages.TestDataCubeErrorInvalidChar);
        }
    }
    return ValidationStatus.ok();
}

From source file:it.geosolutions.httpproxy.utils.Utils.java

/**
 * @param ch//from   w  w w. j  a  v a 2 s.  c  o m
 * @return
 */
final static int escapeHtmlFull(int ch) {
    if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9') {
        // safe
        return ch;
    } else if (Character.isWhitespace(ch)) {
        if (ch != '\n' && ch != '\r' && ch != '\t')
            // safe
            return ch;
    } else if (Character.isDefined(ch)) {
        // safe
        return ch;
    } else if (Character.isISOControl(ch)) {
        // paranoid version:isISOControl which are not isWhitespace
        // removed !
        // do nothing do not include in output !
        return -1;
    } else if (Character.isHighSurrogate((char) ch)) {
        // do nothing do not include in output !
        return -1;
    } else if (Character.isLowSurrogate((char) ch)) {
        // wrong char[] sequence, //TODO: LOG !!!
        return -1;
    }

    return -1;
}

From source file:io.mapzone.controller.vm.http.HttpForwarder.java

/**
 * Encodes characters in the query or fragment part of the URI.
 *
 * <p>// ww  w.j av a 2 s  .c o m
 * Unfortunately, an incoming URI sometimes has characters disallowed by the
 * spec. HttpClient insists that the outgoing proxied request has a valid URI
 * because it uses Java's {@link URI}. To be more forgiving, we must escape the
 * problematic characters. See the URI class for the spec.
 *
 * @param in example: name=value&foo=bar#fragment
 */
protected static CharSequence encodeUriQuery(CharSequence in) {
    // Note that I can't simply use URI.java to encode because it will escape
    // pre-existing escaped things.
    StringBuilder outBuf = null;
    Formatter formatter = null;
    for (int i = 0; i < in.length(); i++) {
        char c = in.charAt(i);
        boolean escape = true;
        if (c < 128) {
            if (asciiQueryChars.get((int) c)) {
                escape = false;
            }
        } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {// not-ascii
            escape = false;
        }
        if (!escape) {
            if (outBuf != null)
                outBuf.append(c);
        } else {
            // escape
            if (outBuf == null) {
                outBuf = new StringBuilder(in.length() + 5 * 3);
                outBuf.append(in, 0, i);
                formatter = new Formatter(outBuf);
            }
            // leading %, 0 padded, width 2, capital hex
            formatter.format("%%%02X", (int) c);// TODO
        }
    }
    return outBuf != null ? outBuf : in;
}

From source file:org.talend.dataquality.semantic.api.DictionaryUtils.java

/**
 * generate a document.//  w w w.  j  ava  2 s.  c  om
 *
 * @param word
 * @param values
 * @return
 */
public static Document generateDocument(String docId, String catId, String word, Set<String> values) {
    String tempWord = word.trim();
    Document doc = new Document();

    Field idTermField = new StringField(DictionarySearcher.F_ID, docId, Field.Store.YES);
    doc.add(idTermField);
    Field catidTermField = new StringField(DictionarySearcher.F_CATID, catId, Field.Store.YES);
    doc.add(catidTermField);
    Field wordTermField = new StringField(DictionarySearcher.F_WORD, tempWord, Field.Store.YES);
    doc.add(wordTermField);
    for (String value : values) {
        if (value != null) {
            boolean containsControlChars = false;
            for (char c : value.toCharArray()) {
                if (Character.isISOControl(c)) {
                    containsControlChars = true;
                }
            }
            if (containsControlChars) {
                System.out.println("The value [" + value
                        + "] contains at least one ISO control character and is not added to the index of "
                        + word + ".");
                continue;
            }
            value = value.trim();
            if (value.length() > 0 && !value.equals(tempWord)) {
                List<String> tokens = DictionarySearcher.getTokensFromAnalyzer(value);
                doc.add(new StringField(DictionarySearcher.F_SYNTERM, StringUtils.join(tokens, ' '),
                        Field.Store.NO));
                doc.add(new Field(DictionarySearcher.F_RAW, value, FIELD_TYPE_RAW_VALUE));
                if (tokens.size() > 1) {
                    doc.add(new Field(DictionarySearcher.F_SYN, value, FIELD_TYPE_SYN));
                }
            }
        }
    }
    return doc;
}

From source file:Hexdump.java

/** 
 * Generate "hexdump" output of the buffer at src like the following:
 *
 * <p><blockquote><pre>
 * 00000: 04 d2 29 00 00 01 00 00 00 00 00 01 20 45 47 46  |..)......... EGF|
 * 00010: 43 45 46 45 45 43 41 43 41 43 41 43 41 43 41 43  |CEFEECACACACACAC|
 * 00020: 41 43 41 43 41 43 41 43 41 43 41 41 44 00 00 20  |ACACACACACAAD.. |
 * 00030: 00 01 c0 0c 00 20 00 01 00 00 00 00 00 06 20 00  |..... ........ .|
 * 00040: ac 22 22 e1                                      |."".            |
 * </blockquote></pre>//from  w w  w.jav  a  2s  .co  m
 */

public static void hexdump(PrintStream ps, byte[] src, int srcIndex, int length) {
    if (length == 0) {
        return;
    }

    int s = length % 16;
    int r = (s == 0) ? length / 16 : length / 16 + 1;
    char[] c = new char[r * (74 + NL_LENGTH)];
    char[] d = new char[16];
    int i;
    int si = 0;
    int ci = 0;

    do {
        toHexChars(si, c, ci, 5);
        ci += 5;
        c[ci++] = ':';
        do {
            if (si == length) {
                int n = 16 - s;
                System.arraycopy(SPACE_CHARS, 0, c, ci, n * 3);
                ci += n * 3;
                System.arraycopy(SPACE_CHARS, 0, d, s, n);
                break;
            }
            c[ci++] = ' ';
            i = src[srcIndex + si] & 0xFF;
            toHexChars(i, c, ci, 2);
            ci += 2;
            if (i < 0 || Character.isISOControl((char) i)) {
                d[si % 16] = '.';
            } else {
                d[si % 16] = (char) i;
            }
        } while ((++si % 16) != 0);
        c[ci++] = ' ';
        c[ci++] = ' ';
        c[ci++] = '|';
        System.arraycopy(d, 0, c, ci, 16);
        ci += 16;
        c[ci++] = '|';
        NL.getChars(0, NL_LENGTH, c, ci);
        ci += NL_LENGTH;
    } while (si < length);

    ps.println(c);
}

From source file:com.sec.ose.osi.ui.frm.main.identification.common.JComboComponentName.java

private void init() {

    final JTextField tfComponentName = (JTextField) this.getEditor().getEditorComponent();

    tfComponentName.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            char ch = e.getKeyChar();
            if (ch != KeyEvent.VK_ENTER && ch != KeyEvent.VK_BACK_SPACE && ch != KeyEvent.VK_SPACE
                    && (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)))
                return;

            if (ch == KeyEvent.VK_ENTER) {

                JComboComponentName.this.hidePopup();
                return;
            }//w ww. j  av  a  2s  . co  m
            // 1. save string
            String keyword = tfComponentName.getText();//.trim();
            updateComboBoxList(keyword);

        }
    });

    tfComponentName.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            if (tfComponentName.getText().length() > 0)
                showPopup();
        }

        public void focusLost(FocusEvent e) {
            hidePopup();
        }
    });

}

From source file:pl.nask.hsn2.normalizers.UrlNormalizer.java

public UrlNormalizer(String uri) {
    this.original = uri.trim();
    ;//from   ww w .j  a  va  2  s . c  o  m
    toProcess = new StringBuilder(this.original);
    int i = toProcess.indexOf(" ");
    if (i > 0) {
        LOG.warn("URL contains unescaped space(s) will be trimmed at position [{}]:({})", i + 1,
                toProcess.toString());
        toProcess.delete(i, toProcess.length());
    }
    for (int c = 0; c < toProcess.length(); c++) {
        if (Character.isISOControl(toProcess.codePointAt(c))) {
            toProcess.deleteCharAt(c--);
        }
    }
    URLNormalizerUtils.removeObfuscatedEncoding(toProcess, new EncodingType[] { EncodingType.URI_BASE });

}

From source file:com.igormaznitsa.mindmap.exporters.MDExporter.java

private static String makeLineFromString(final String text) {
    final StringBuilder result = new StringBuilder(text.length());

    for (final char c : text.toCharArray()) {
        if (Character.isISOControl(c)) {
            result.append(' ');
        } else {//from ww  w. j  a va2  s .c o m
            result.append(c);
        }
    }

    return result.toString();
}

From source file:com.nesscomputing.syslog4j.impl.message.modifier.escape.HTMLEntityEscapeSyslogMessageModifier.java

/**
 * escapeHtml(String) is based partly on the article posted here: http://www.owasp.org/index.php/How_to_perform_HTML_entity_encoding_in_Java
 * with the addition of common characters and modifications for Java 1.4 support.
 *
 * @param message/*from   www.j  a  va2 s  .co m*/
 * @return Returns a message where any HTML entity characters are escaped.
 */
public static String escapeHtml(String message) {
    StringBuffer b = new StringBuffer(message.length());

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

        if (ch == '<') {
            b.append("&lt;");
        } else if (ch == '>') {
            b.append("&gt;");
        } else if (ch == '"') {
            b.append("&quot;");
        } else if (ch == '\'') {
            b.append("&#39;");
        } else if (ch == '&') {
            b.append("&amp;");
        } else if (ch >= ' ' && ch <= '~') {
            b.append(ch);
        } else if (Character.isWhitespace(ch)) {
            b.append("&#").append((int) ch).append(";");
        } else if (Character.isISOControl(ch)) {
            continue; // Ignore character
        } else if (Character.isDefined(ch)) {
            b.append("&#").append((int) ch).append(";");
        }
    }

    return b.toString();
}

From source file:com.turo.pushy.apns.util.ApnsPayloadBuilderBenchmark.java

@Setup
public void setUp() {
    this.apnsPayloadBuilder = new ApnsPayloadBuilder();

    final char[] messageBodyCharacters;
    {//from  ww w  .j av a  2s .c  o  m
        final Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.forName(this.unicodeBlockName);
        final List<Character> charactersInBlock = new ArrayList<>();

        for (int codePoint = Character.MIN_CODE_POINT; codePoint < Character.MAX_CODE_POINT; codePoint++) {
            if (unicodeBlock.equals(Character.UnicodeBlock.of(codePoint))
                    && !Character.isISOControl(codePoint)) {
                charactersInBlock.add((char) codePoint);
            }
        }

        messageBodyCharacters = new char[charactersInBlock.size()];

        for (int i = 0; i < charactersInBlock.size(); i++) {
            messageBodyCharacters[i] = charactersInBlock.get(i);
        }
    }

    this.messageBody = RandomStringUtils.random(this.messageBodyLength, messageBodyCharacters);
}