List of usage examples for java.lang String codePointAt
public int codePointAt(int index)
From source file:com.triompha.common.web.html.HtmlUtil.java
/** * ?escape?named entities,??somlanti-xss *///from w w w.j av a2 s . co m public static String namedHtmlEscape(String s) { if (s == null) { return null; } int len = s.length(); StringBuilder escaped = new StringBuilder(len); for (int i = 0; i < len; ++i) { int c = s.codePointAt(i); // try entity reference first String iso = ANTIENTITIES.get(c); if (iso != null) { escaped.append("&").append(iso).append(";"); continue; } else { escaped.append(s.charAt(i)); } } return escaped.toString(); }
From source file:org.opencms.search.solr.spellchecking.CmsSolrSpellchecker.java
/** * Parse parameters from this request using HTTP. * * @param req The ServletRequest containing all request parameters. * @param cms The OpenCms object./*from w ww. ja va 2 s . c o m*/ * @return CmsSpellcheckingRequest object that contains parsed parameters. */ private CmsSpellcheckingRequest parseHttpRequest(final ServletRequest req, final CmsObject cms) { if ((null != cms) && !cms.getRequestContext().getCurrentUser().isGuestUser()) { if (null != req.getParameter(HTTP_PARAMETER_CHECKREBUILD)) { if (CmsSpellcheckDictionaryIndexer.updatingIndexNecessesary(cms)) { parseAndAddDictionaries(cms); } } if (null != req.getParameter(HTTP_PARAMTER_REBUILD)) { parseAndAddDictionaries(cms); } } final String q = req.getParameter(HTTP_PARAMETER_WORDS); if (null == q) { LOG.debug("Invalid HTTP request: No parameter \"" + HTTP_PARAMETER_WORDS + "\" defined. "); return null; } final StringTokenizer st = new StringTokenizer(q); final List<String> wordsToCheck = new ArrayList<String>(); while (st.hasMoreTokens()) { final String word = st.nextToken(); wordsToCheck.add(word); if (Character.isUpperCase(word.codePointAt(0))) { wordsToCheck.add(word.toLowerCase()); } } final String[] w = wordsToCheck.toArray(new String[wordsToCheck.size()]); final String dict = req.getParameter(HTTP_PARAMETER_LANG) == null ? LANG_DEFAULT : req.getParameter(HTTP_PARAMETER_LANG); return new CmsSpellcheckingRequest(w, dict); }
From source file:org.opencms.search.solr.spellchecking.CmsSolrSpellchecker.java
/** * Parse JSON parameters from this request. * * @param jsonRequest The request in the JSON format. * @return CmsSpellcheckingRequest object that contains parsed parameters or null, if JSON input is not well * defined./* www. ja va 2s . c om*/ */ private CmsSpellcheckingRequest parseJsonRequest(JSONObject jsonRequest) { final String id = jsonRequest.optString(JSON_ID); final JSONObject params = jsonRequest.optJSONObject(JSON_PARAMS); if (null == params) { LOG.debug("Invalid JSON request: No field \"params\" defined. "); return null; } final JSONArray words = params.optJSONArray(JSON_WORDS); final String lang = params.optString(JSON_LANG, LANG_DEFAULT); if (null == words) { LOG.debug("Invalid JSON request: No field \"words\" defined. "); return null; } // Convert JSON array to array of type String final List<String> wordsToCheck = new LinkedList<String>(); for (int i = 0; i < words.length(); i++) { final String word = words.opt(i).toString(); wordsToCheck.add(word); if (Character.isUpperCase(word.codePointAt(0))) { wordsToCheck.add(word.toLowerCase()); } } return new CmsSpellcheckingRequest(wordsToCheck.toArray(new String[wordsToCheck.size()]), lang, id); }
From source file:org.apache.pdfbox.pdfviewer.font.TTFGlyph2D.java
/** * Get the GID for the given CIDFont.//from w ww. j a v a 2 s . c om * * @param code the given CID * @return the mapped GID */ private int getGID(int code) { if (hasIdentityCIDMapping) { // identity mapping return code; } if (hasCID2GIDMapping) { // use the provided CID2GID mapping return descendantFont.mapCIDToGID(code); } if (fontCMap != null) { String string = fontCMap.lookup(code, hasTwoByteMappings ? 2 : 1); if (string != null) { return string.codePointAt(0); } } return code; }
From source file:org.apache.pdfbox.pdfviewer.font.TTFGlyph2D.java
/** * {@inheritDoc}//from ww w . j a v a2 s. c o m */ @Override public GeneralPath getPathForCharacterCode(int code) { int glyphId = getGlyphcode(code); if (glyphId > 0) { return getPathForGlyphId(glyphId); } glyphId = code; // there isn't any mapping, but probably an optional CMap if (fontCMap != null) { String string = fontCMap.lookup(code, hasTwoByteMappings ? 2 : 1); if (string != null) { glyphId = string.codePointAt(0); } } return getPathForGlyphId(glyphId); }
From source file:org.apache.axiom.om.util.XMLStreamWriterRemoveIllegalChars.java
protected String xmlData(String value) { char[] buffer = null; int len = value.length(); int srcI = 0; int tgtI = 0; int copyLength = 0; int i = 0;//from ww w. ja v a 2 s . co m // Traverse all of the characters in the input String (value) while (i < len) { // Get the codepoint of the character at the index // Note that the code point may be two characters long (a supplemental character) int cp = value.codePointAt(i); if (cp > FFFF) { // Supplemental Character...Increase index by 2 // Increase the length of good characters to copy by 2 i = i + 2; copyLength = copyLength + 2; } else { // See if the character is invalid if ((cp < 0x20 && (REMOVE[cp] > 0)) || // Control Character (cp >= SURROGATE_START && cp <= SURROGATE_END) || // Bad surrogate (cp == FFFF || cp == FFFE)) { // or illegal character // Flow to here indicates that the character is not allowed. // The good characters (up to this point) are copied into the buffer. // Note that the buffer is initialized with the original characters. // Thus the buffer copy is always done on the same buffer (saving // both time and space). // Make the buffer on demand if (buffer == null) { if (log.isDebugEnabled()) { log.debug("One or more illegal characterss found. Codepoint=" + cp); } buffer = value.toCharArray(); } // Copy the good characters into the buffer System.arraycopy(buffer, srcI, buffer, tgtI, copyLength); tgtI = tgtI + copyLength; // Update the target location in the array srcI = i + 1; // Skip over the current character copyLength = 0; // reset new copy length } else { // Valid character, increase copy length copyLength = copyLength + 1; } // Single bit16 character, increase index by 1 i = i + 1; } } if (buffer == null) { // Normal case, no illegal characters removed..No buffer return value; } else { // Move the final valid characters to the buffer // and return a string representing the value System.arraycopy(buffer, srcI, buffer, tgtI, copyLength); String newValue = new String(buffer, 0, tgtI + copyLength); return newValue; } }
From source file:com.risevision.ui.server.utils.MakeRequestServlet.java
private static String getResponseAsJson(HttpURLConnection urlConnection) { String result = null; // InputStream is = checkForUtf8BOMAndDiscardIfAny(urlConnection.getInputStream()); // String charset = getCharsetType(urlConnection); // BufferedReader reader = new BufferedReader(new InputStreamReader(is, charset)); // String line = new String(bytes, charsetName); ///*from w w w. j a v a 2s . c o m*/ // while ((line = new String(reader.readLine(), "ISO-8859-1")) != null) { // result += line + "\n"; // } // reader.close(); String charset = getCharsetType(urlConnection); // byte[] bytes = IOUtils.toByteArray(urlConnection.getInputStream()); byte[] bytes = null; try { bytes = inputStreamToByteArray(urlConnection.getInputStream()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (RiseUtils.strIsNullOrEmpty(charset)) { charset = getEncodingType(bytes); if (RiseUtils.strIsNullOrEmpty(charset)) { charset = "UTF-8"; } } Charset encoding = Charset.forName(charset); if (result == null) { result = encoding.decode(ByteBuffer.wrap(bytes)).toString(); // Strip BOM if present. if (result.length() > 0 && result.codePointAt(0) == 0xFEFF) { result = result.substring(1); } } return result; }
From source file:com.ebuddy.cassandra.cql.dao.CqlStructuredDataSupport.java
private String getFinishString(String start) { int startCodePointCount = start.codePointCount(0, start.length()); int finishCodePointCount = startCodePointCount + 1; int[] finishCodePoints = new int[finishCodePointCount]; for (int i = 0; i < startCodePointCount; i++) { finishCodePoints[i] = start.codePointAt(i); }//from ww w .j a va 2 s .com finishCodePoints[finishCodePointCount - 1] = MAX_CODE_POINT; return new String(finishCodePoints, 0, finishCodePointCount); }
From source file:org.apache.pdfbox.pdmodel.font.PDFont.java
/** * Encodes the given string for use in a PDF content stream. * * @param text Any Unicode text./* ww w . j ava 2 s . co m*/ * @return Array of PDF content stream bytes. * @throws IOException If the text could not be encoded. */ public final byte[] encode(String text) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); for (int offset = 0; offset < text.length();) { int codePoint = text.codePointAt(offset); // multi-byte encoding with 1 to 4 bytes byte[] bytes = encode(codePoint); out.write(bytes); offset += Character.charCount(codePoint); } return out.toByteArray(); }
From source file:org.apache.pdfbox.pdfviewer.font.TTFGlyph2D.java
private int getGlyphcode(int code) { if (isCIDFont) { return getGID(code); }/*from ww w . j av a2s . com*/ int result = 0; if (fontEncoding != null && !isSymbol) { try { String charactername = fontEncoding.getName(code); if (charactername != null) { if (cmapWinUnicode != null) { String unicode = Encoding.getCharacterForName(charactername); if (unicode != null) { result = unicode.codePointAt(0); } result = cmapWinUnicode.getGlyphId(result); } else if (cmapMacintoshSymbol != null) { result = MacOSRomanEncoding.INSTANCE.getCode(charactername); result = cmapMacintoshSymbol.getGlyphId(result); } } } catch (IOException exception) { LOG.error("Caught an exception getGlyhcode: " + exception); } } if (fontEncoding == null || isSymbol) { if (cmapWinSymbol != null) { result = cmapWinSymbol.getGlyphId(code); if (code >= 0 && code <= 0xFF) { // the CMap may use one of the following code ranges, // so that we have to add the high byte to get the // mapped value if (result == 0) { // F000 - F0FF result = cmapWinSymbol.getGlyphId(code + START_RANGE_F000); } if (result == 0) { // F100 - F1FF result = cmapWinSymbol.getGlyphId(code + START_RANGE_F100); } if (result == 0) { // F200 - F2FF result = cmapWinSymbol.getGlyphId(code + START_RANGE_F200); } } } else if (cmapMacintoshSymbol != null) { result = cmapMacintoshSymbol.getGlyphId(code); } } return result; }