List of usage examples for java.lang Character toChars
public static char[] toChars(int codePoint)
From source file:com.gelakinetic.mtgfam.helpers.CardDbAdapter.java
public static String removeAccentMarks(String s) { return s.replace(Character.toChars(0xC0)[0] + "", "A").replace(Character.toChars(0xC1)[0] + "", "A") .replace(Character.toChars(0xC2)[0] + "", "A").replace(Character.toChars(0xC3)[0] + "", "A") .replace(Character.toChars(0xC4)[0] + "", "A").replace(Character.toChars(0xC5)[0] + "", "A") .replace(Character.toChars(0xC6)[0] + "", "Ae").replace(Character.toChars(0xC7)[0] + "", "C") .replace(Character.toChars(0xC8)[0] + "", "E").replace(Character.toChars(0xC9)[0] + "", "E") .replace(Character.toChars(0xCA)[0] + "", "E").replace(Character.toChars(0xCB)[0] + "", "E") .replace(Character.toChars(0xCC)[0] + "", "I").replace(Character.toChars(0xCD)[0] + "", "I") .replace(Character.toChars(0xCE)[0] + "", "I").replace(Character.toChars(0xCF)[0] + "", "I") .replace(Character.toChars(0xD0)[0] + "", "D").replace(Character.toChars(0xD1)[0] + "", "N") .replace(Character.toChars(0xD2)[0] + "", "O").replace(Character.toChars(0xD3)[0] + "", "O") .replace(Character.toChars(0xD4)[0] + "", "O").replace(Character.toChars(0xD5)[0] + "", "O") .replace(Character.toChars(0xD6)[0] + "", "O").replace(Character.toChars(0xD7)[0] + "", "x") .replace(Character.toChars(0xD8)[0] + "", "O").replace(Character.toChars(0xD9)[0] + "", "U") .replace(Character.toChars(0xDA)[0] + "", "U").replace(Character.toChars(0xDB)[0] + "", "U") .replace(Character.toChars(0xDC)[0] + "", "U").replace(Character.toChars(0xDD)[0] + "", "Y") .replace(Character.toChars(0xE0)[0] + "", "a").replace(Character.toChars(0xE1)[0] + "", "a") .replace(Character.toChars(0xE2)[0] + "", "a").replace(Character.toChars(0xE3)[0] + "", "a") .replace(Character.toChars(0xE4)[0] + "", "a").replace(Character.toChars(0xE5)[0] + "", "a") .replace(Character.toChars(0xE6)[0] + "", "ae").replace(Character.toChars(0xE7)[0] + "", "c") .replace(Character.toChars(0xE8)[0] + "", "e").replace(Character.toChars(0xE9)[0] + "", "e") .replace(Character.toChars(0xEA)[0] + "", "e").replace(Character.toChars(0xEB)[0] + "", "e") .replace(Character.toChars(0xEC)[0] + "", "i").replace(Character.toChars(0xED)[0] + "", "i") .replace(Character.toChars(0xEE)[0] + "", "i").replace(Character.toChars(0xEF)[0] + "", "i") .replace(Character.toChars(0xF1)[0] + "", "n").replace(Character.toChars(0xF2)[0] + "", "o") .replace(Character.toChars(0xF3)[0] + "", "o").replace(Character.toChars(0xF4)[0] + "", "o") .replace(Character.toChars(0xF5)[0] + "", "o").replace(Character.toChars(0xF6)[0] + "", "o") .replace(Character.toChars(0xF8)[0] + "", "o").replace(Character.toChars(0xF9)[0] + "", "u") .replace(Character.toChars(0xFA)[0] + "", "u").replace(Character.toChars(0xFB)[0] + "", "u") .replace(Character.toChars(0xFC)[0] + "", "u").replace(Character.toChars(0xFD)[0] + "", "y") .replace(Character.toChars(0xFF)[0] + "", "y"); }
From source file:org.sakaiproject.dav.DavServlet.java
/** * PROPPATCH Method./*from w ww. ja v a 2s. c o m*/ */ @SuppressWarnings("deprecation") protected void doProppatch(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // Check that the resource is not locked if (isLocked(req)) { resp.sendError(SakaidavStatus.SC_LOCKED); } // we can't actually do this, but MS requires us to. Say we did. // I'm trying to be as close to valid here, so I generate an OK // for all the properties they tried to set. This is really hairy because // it gets into name spaces. But if we ever try to implement this for real, // we'll have to do this. So might as well start now. // During testing I found by mistake that it's actually OK to send // an empty multistatus return, so I don't actually need all of this stuff. // The big problem is that the properties are typically not in the dav namespace // we build a hash table of namespaces, with the prefix we're going to use // since D: is used for dav, we start with E:, actually D+1 DocumentBuilder documentBuilder = null; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setFeature("http://xml.org/sax/features/external-general-entities", false); factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); documentBuilder = factory.newDocumentBuilder(); } catch (Exception e) { resp.sendError(SakaidavStatus.SC_METHOD_FAILURE); return; } int contentLength = req.getContentLength(); // a list of the properties with the new prefix List<String> props = new ArrayList<String>(); // hash of namespace, prefix Hashtable<String, String> spaces = new Hashtable<String, String>(); // read the xml document if (contentLength > MAX_XML_STREAM_LENGTH) { resp.sendError(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE); return; } else if (contentLength > 0) { byte[] byteContent = new byte[contentLength]; InputStream inputStream = req.getInputStream(); int lenRead = 0; try { while (lenRead < contentLength) { int read = inputStream.read(byteContent, lenRead, contentLength - lenRead); if (read <= 0) break; lenRead += read; } } catch (Exception ignore) { } // Parse the input XML to see what they really want if (lenRead > 0) try { // if we got here, "is" is the xml document InputStream is = new ByteArrayInputStream(byteContent, 0, lenRead); Document document = documentBuilder.parse(new InputSource(is)); // Get the root element of the document Element rootElement = document.getDocumentElement(); // find all the property nodes NodeList childList = rootElement.getElementsByTagNameNS("DAV:", "prop"); int nextChar = 1; for (int i = 0; i < childList.getLength(); i++) { // this should be a prop node Node currentNode = childList.item(i); // this should be the actual property NodeList names = currentNode.getChildNodes(); // this should be the name for (int j = 0; j < names.getLength(); j++) { String namespace = names.item(j).getNamespaceURI(); String prefix = spaces.get(namespace); // see if we know about this namespace. If not add it and // generate a prefix if (prefix == null) { prefix = "" + Character.toChars('D' + nextChar)[0]; spaces.put(namespace, prefix); } props.add(prefix + ":" + names.item(j).getLocalName()); } } } catch (Exception ignore) { } } resp.setStatus(SakaidavStatus.SC_MULTI_STATUS); resp.setContentType("text/xml; charset=UTF-8"); Writer writer = resp.getWriter(); writer.write("<D:multistatus xmlns:D=\"DAV:\""); // dump all the name spaces and their prefix for (String namespace : spaces.keySet()) writer.write(" xmlns:" + spaces.get(namespace) + "=\"" + namespace + "\""); writer.write("><D:response><D:href>" + javax.servlet.http.HttpUtils.getRequestURL(req) + "</D:href>"); // now output properties, claiming we did it for (String pname : props) { writer.write("<D:propstat><D:prop><" + pname + "/></D:prop><D:status>HTTP/1.1 201 OK</D:status></D:propstat>"); } writer.write("</D:response></D:multistatus>"); writer.close(); }
From source file:com.nest5.businessClient.Initialactivity.java
@Override public void OnPayClicked(String method, double value, double discount, int tipp) { currentOrder = cookingOrders.get(currentSelectedPosition); int togo = 0; int delivery = 0; try {//from ww w . ja v a 2 s .c o m togo = cookingOrdersTogo.get(currentOrder) != null ? cookingOrdersTogo.get(currentOrder) : 0; delivery = cookingOrdersDelivery.get(currentOrder) != null ? cookingOrdersDelivery.get(currentOrder) : 0; } catch (Exception e) { e.printStackTrace(); } int number = checkSaleNumber(); //si falla se resta un numero de las ventas actuales mas adelante,. if (number > 0) { saveSale(method, value, discount, delivery, togo, tipp); Date date = new Date(); String fecha = new SimpleDateFormat("dd/MM/yyyy - HH:mm:ss").format(date); //String fecha = DateFormat.getDateFormat(Initialactivity.this).format( // date); // imprimir, conectar por wifi y enviar el texto arregladito a la app de // puente String mesa = "DOMICILIO / PARA LLEVAR"; if (currentTable != null) { mesa = currentTable.getTable().getName().toUpperCase(Locale.getDefault()); } int lines = 0; StringBuilder factura = new StringBuilder(); //factura.append("MR. PASTOR COMIDA\r\nRaPIDA MEXICANA" + "\r\n"); SharedPreferences prefs = Util.getSharedPreferences(mContext); String empresa = prefs.getString(Setup.COMPANY_NAME, "Nombre de Empresa"); String nit = prefs.getString(Setup.COMPANY_NIT, "000000000-0"); String email = prefs.getString(Setup.COMPANY_EMAIL, "email@empresa.com"); String pagina = prefs.getString(Setup.COMPANY_URL, "http://www.empresa.com"); String direccion = prefs.getString(Setup.COMPANY_ADDRESS, "Direccin Fsica Empresa"); String telefono = prefs.getString(Setup.COMPANY_TEL, "555-55-55"); String mensaje = prefs.getString(Setup.COMPANY_MESSAGE, "No hay ningn mensaje configurado an. En el mensaje es recomendable mencionar tus redes sociales, benficios y promociones que tengas, adems de informacin de inters paratus clientes. "); String propina = prefs.getString(Setup.TIP_MESSAGE, "No hay ningn mensaje de propina configurado an. "); String resolution = prefs.getString(Setup.RESOLUTION_MESSAGE, "Resolucin de facturacin No. 00000-0000 de 1970 DIAN"); int currentSale = prefs.getInt(Setup.CURRENT_SALE, 0); factura.append(empresa + "\r\n"); factura.append(nit + "\r\n"); factura.append(direccion + "\r\n"); factura.append(telefono + "\r\n"); factura.append(email + "\r\n"); factura.append(pagina + "\r\n"); factura.append(resolution + "\r\n"); factura.append("Factura de Venta No. " + String.valueOf(currentSale) + "\r\n"); lines++; factura.append("\r\n"); factura.append(fecha); factura.append("\r\n"); factura.append(mesa); lines++; lines++; lines++; factura.append("\r\n"); factura.append(" Item Cantidad Precio\r\n"); lines++; Iterator<Entry<Registrable, Integer>> it = currentOrder.entrySet().iterator(); //////Log.i("MISPRUEBAS","Valor de currentOrder"+String.valueOf(currentOrder.size())); // Log.d(TAG,String.valueOf(currentOrder.size())); LinkedHashMap<Registrable, Integer> currentObjects = new LinkedHashMap<Registrable, Integer>(); float base = 0; float iva = 0; float total = 0; ArrayList<String> productos = new ArrayList<String>(); ArrayList<String> quantities = new ArrayList<String>(); ArrayList<String> precios = new ArrayList<String>(); while (it.hasNext()) { LinkedHashMap.Entry<Registrable, Integer> pairs = (LinkedHashMap.Entry<Registrable, Integer>) it .next(); currentObjects.put(pairs.getKey(), pairs.getValue()); String name = pairs.getKey().name; int longName = name.length(); int subLength = 14 - longName; if (subLength < 0) name = name.substring(0, 14); int espacios1 = 4; int espacios2 = 12; if (name.length() < 14) { espacios1 += 14 - name.length(); } factura.append(name); productos.add(name); int qtyL = String.valueOf(pairs.getValue()).length(); float precioiva = (float) Math .round(pairs.getKey().price + pairs.getKey().price * pairs.getKey().tax); base += (float) Math.round(pairs.getKey().price * pairs.getValue()); iva += (float) Math.round((pairs.getKey().price * pairs.getKey().tax) * pairs.getValue()); total += precioiva * pairs.getValue(); int priceL = String.valueOf(precioiva).length(); espacios1 = espacios1 - qtyL < 1 ? espacios1 = 1 : espacios1 - qtyL; espacios2 = espacios2 - priceL < 1 ? espacios2 = 1 : espacios2 - priceL; espacios2 = espacios2 - qtyL < 1 ? espacios2 = 1 : espacios2 - qtyL; for (int k = 0; k < espacios1; k++) { factura.append(" "); } factura.append(pairs.getValue()); for (int k = 0; k < espacios2; k++) { factura.append(" "); } quantities.add(String.valueOf(pairs.getValue())); factura.append("$"); factura.append(precioiva); factura.append("\r\n"); precios.add("$" + precioiva); lines++; } float propvalue = 0; if (tipp == 1) propvalue = (float) Math.round(total * 0.1); float descuento = 0; if (discount > 0) { descuento = (float) Math.round(base - (base * (discount / 0))); } lines++; lines++; factura.append("\r\n"); factura.append("<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>\r\n"); factura.append("BASE: $" + base + "\r\n"); factura.append("Descuento (" + discount + "): $" + descuento + "\r\n"); factura.append("Imp.: $" + iva + "\r\n"); factura.append("SUBTOTAL: $" + Math.round(total - descuento) + "\r\n"); factura.append("PROPINA: $" + propvalue + "\r\n"); float precfinal = propvalue + total - descuento; factura.append("TOTAL: $" + precfinal + "\r\n"); factura.append("\r\n"); factura.append("<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>\r\n"); factura.append("\r\n"); lines++; factura.append(propina + "\r\n"); factura.append(mensaje); String send = factura.toString(); //////Log.i("MISPRUEBAS",factura.toString()); // Enviar un string diferente que lleva la orden actual. // new WiFiSend().execute(comanda.toString());// enviar el mensaje de // verdad int[] arrayOfInt = new int[2]; arrayOfInt[0] = 27; arrayOfInt[1] = 64; int[] array2 = new int[3]; array2[0] = 27; array2[1] = 74; array2[2] = 2; StringBuilder builder1 = new StringBuilder(); for (int h = 0; h < 2; h++) { builder1.append(Character.toChars(arrayOfInt[h])); } StringBuilder builder2 = new StringBuilder(); builder2.append(Character.toChars(10)); StringBuilder complete = new StringBuilder(String.valueOf(builder1.toString())) .append(String.valueOf(builder2.toString())); String enviar = complete.toString(); Boolean printed = true; try { if (mChatService.getState() == mChatService.STATE_CONNECTED) { try { mChatService.write(factura.toString().getBytes("x-UnicodeBig")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } else { printed = false; Toast.makeText(mContext, "No hay impresora bluetooth conectada.", Toast.LENGTH_LONG).show(); } } catch (NullPointerException e) { printed = false; e.printStackTrace(); } if (!printed) {//buscar impresora TCP/IP StringBuilder formateado = new StringBuilder(); formateado.append(CLEAR_PRINTER); formateado.append(INITIALIZE_PRINTER); formateado.append(JUSTIFICATION_CENTER); formateado.append(DOUBLE_WIDE_CHARACTERS); formateado.append(empresa); formateado.append(SINGLE_WIDE_CHARACTERS); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(nit); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(direccion); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(telefono); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(email); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(pagina); formateado.append(PRINT_FEED_ONE_LINE); formateado.append("Factura de Venta No." + String.valueOf(currentSale)); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(resolution); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(fecha); formateado.append(PRINT_FEED_N_LINES); formateado.append((char) 0x02); formateado.append(mesa); formateado.append(PRINT_FEED_N_LINES); formateado.append((char) 0x02); formateado.append(DOUBLE_WIDE_CHARACTERS); formateado.append(JUSTIFICATION_LEFT); formateado.append("ITEM"); formateado.append(HORIZONTAL_TAB); formateado.append("CANT."); formateado.append(HORIZONTAL_TAB); formateado.append("PRECIO"); formateado.append(SINGLE_WIDE_CHARACTERS); formateado.append(PRINT_FEED_ONE_LINE); for (String actual : productos) { int pos = productos.indexOf(actual); String cantidad = quantities.get(pos); String precio = precios.get(pos); formateado.append(actual); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("x" + cantidad); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(precio); formateado.append(PRINT_FEED_ONE_LINE); } formateado.append(DOUBLE_WIDE_CHARACTERS); formateado.append("______________________"); formateado.append(SINGLE_WIDE_CHARACTERS); formateado.append(PRINT_FEED_N_LINES); formateado.append((char) 0x02); formateado.append("BASE:"); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("$" + base); formateado.append(PRINT_FEED_ONE_LINE); formateado.append("DESCUENTO (:" + discount + "%)"); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("$" + descuento); formateado.append(PRINT_FEED_ONE_LINE); formateado.append("Impuesto:"); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("$" + iva); formateado.append(PRINT_FEED_ONE_LINE); formateado.append("SUBTOTAL:"); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("$" + Math.round(total - descuento)); formateado.append(PRINT_FEED_ONE_LINE); formateado.append("PROPINA:"); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("$" + propvalue); formateado.append(PRINT_FEED_ONE_LINE); formateado.append("TOTAL:"); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("$" + precfinal); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(DOUBLE_WIDE_CHARACTERS); formateado.append("______________________"); formateado.append(SINGLE_WIDE_CHARACTERS); formateado.append(PRINT_FEED_N_LINES); formateado.append((char) 0x02); formateado.append(ITALIC_STYLE); formateado.append(propina); formateado.append(PRINT_FEED_N_LINES); formateado.append((char) 0x02); formateado.append(mensaje); formateado.append(ITALIC_CANCEL); formateado.append(FINALIZE_TICKET); formateado.append(FULL_CUT); if (mTCPPrint != null) { if (mTCPPrint.getStatus() == TCPPrint.CONNECTED) { mTCPPrint.sendMessage(formateado.toString()); mTCPPrint.sendMessage(formateado.toString()); } else { mTCPPrint.stopClient(); new connectTask().execute(formateado.toString()); alertbox("Oops!", "Al Parecer no hay impresora disponible. Estamos tratando de reconectarnos e imprimir. Si no funciona, reinicia la Red o la impresora y ve a rdenes para imprimir el pedido."); } } else { alertbox("Oops!", "Al Parecer no hay impresora disponible. Trataremos en este momento de nuevo de imprimir el pedido. Si no funciona, reinicia la red o la impreso y ve a rdenes para imprimir de nuevo la orden."); new connectTask().execute(formateado.toString()); } } currentOrder.clear(); //NUEVOO makeTable("NA"); } else { alertbox("!ATENCIN!", "Esta venta no se puede facturar. Este dispositivo no tiene ms facturas autorizadas. Consulta el administrador, o si tu lo eres, ve a tu panel de control Nest5 y autoriza ms facturas. Para ms informacin: http://soporte.nest5.com"); } }
From source file:com.flexoodb.common.FlexUtils.java
public static String removeInvalidXMLCharacters(String s) { StringBuilder out = new StringBuilder(); int codePoint; int i = 0;// w ww. j a va 2 s.c om while (i < s.length()) { // This is the unicode code of the character. codePoint = s.codePointAt(i); if ((codePoint == 0x9) || (codePoint == 0xA) || (codePoint == 0xD) || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF))) { out.append(Character.toChars(codePoint)); } i += Character.charCount(codePoint); } return out.toString(); }
From source file:com.flexoodb.common.FlexUtils.java
public static String removeNonASCII(String s) { StringBuilder out = new StringBuilder(); int codePoint; int i = 0;/*www . ja va 2 s . com*/ while (i < s.length()) { // This is the unicode code of the character. codePoint = s.codePointAt(i); if (codePoint < 128) { out.append(Character.toChars(codePoint)); } i += Character.charCount(codePoint); } return out.toString(); }