List of usage examples for java.lang Long decode
public static Long decode(String nm) throws NumberFormatException
From source file:info.magnolia.ui.vaadin.integration.jcr.DefaultPropertyUtil.java
/** * Create a custom Field Object based on the Type and defaultValue. * If the fieldType is null, the defaultValue will be returned as String or null. * If the defaultValue is null, null will be returned. * * @throws NumberFormatException In case of the default value could not be parsed to the desired class. *//* w w w.j a v a 2s .co m*/ public static Object createTypedValue(Class<?> type, String defaultValue) throws NumberFormatException { if (StringUtils.isBlank(defaultValue)) { return defaultValue; } else if (defaultValue != null) { if (type.getName().equals(String.class.getName())) { return defaultValue; } else if (type.getName().equals(Long.class.getName())) { return Long.decode(defaultValue); } else if (type.isAssignableFrom(Binary.class)) { return null; } else if (type.getName().equals(Double.class.getName())) { return Double.valueOf(defaultValue); } else if (type.getName().equals(Date.class.getName())) { try { return new SimpleDateFormat(DateUtil.YYYY_MM_DD).parse(defaultValue); } catch (ParseException e) { throw new IllegalArgumentException(e); } } else if (type.getName().equals(Boolean.class.getName())) { return BooleanUtils.toBoolean(defaultValue); } else if (type.getName().equals(BigDecimal.class.getName())) { return BigDecimal.valueOf(Long.decode(defaultValue)); } else if (type.isAssignableFrom(List.class)) { return Arrays.asList(defaultValue.split(",")); } else { throw new IllegalArgumentException("Unsupported property type " + type.getName()); } } return null; }
From source file:pt.webdetails.cda.cache.scheduler.CacheScheduleManager.java
private void load(String obj, OutputStream out) throws Exception { Session s = getHibernateSession();// ww w . j a v a 2 s . c o m Long id = Long.decode(obj); Query q = (Query) s.load(Query.class, id); if (q == null) { out.write("{}".getBytes(ENCODING)); logger.error("Couldn't get Query with id=" + id.toString()); } try { JSONObject json = q.toJSON(); out.write(json.toString(2).getBytes(ENCODING)); } catch (Exception e) { logger.error(e); } s.close(); }
From source file:NumberUtils.java
/** * Parse the given text into a number instance of the given target class, * using the corresponding default <code>decode</code> methods. Trims the * input <code>String</code> before attempting to parse the number. Supports * numbers in hex format (with leading 0x) and in octal format (with leading 0). * @param text the text to convert//from w w w. j a v a2 s .c om * @param targetClass the target class to parse into * @return the parsed number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.lang.Byte#decode * @see java.lang.Short#decode * @see java.lang.Integer#decode * @see java.lang.Long#decode * @see #decodeBigInteger(String) * @see java.lang.Float#valueOf * @see java.lang.Double#valueOf * @see java.math.BigDecimal#BigDecimal(String) */ public static Number parseNumber(String text, Class targetClass) { String trimmed = text.trim(); if (targetClass.equals(Byte.class)) { return Byte.decode(trimmed); } else if (targetClass.equals(Short.class)) { return Short.decode(trimmed); } else if (targetClass.equals(Integer.class)) { return Integer.decode(trimmed); } else if (targetClass.equals(Long.class)) { return Long.decode(trimmed); } else if (targetClass.equals(BigInteger.class)) { return decodeBigInteger(trimmed); } else if (targetClass.equals(Float.class)) { return Float.valueOf(trimmed); } else if (targetClass.equals(Double.class)) { return Double.valueOf(trimmed); } else if (targetClass.equals(BigDecimal.class) || targetClass.equals(Number.class)) { return new BigDecimal(trimmed); } else { throw new IllegalArgumentException( "Cannot convert String [" + text + "] to target class [" + targetClass.getName() + "]"); } }
From source file:org.jboss.dashboard.ui.components.permissions.PermissionsHandler.java
public void actionDeleteObject(CommandRequest request) throws Exception { String sid = request.getParameter(PARAM_OBJECT_ID); if (!StringUtils.isEmpty(sid)) { Long id = Long.decode(sid); PermissionDescriptor pd = permissionManager.findPermissionDescriptorById(id); if (pd != null) { securityPolicy.removePermission(pd.getPrincipal(), pd.getPermission()); securityPolicy.save();/*www .j a v a 2 s .c o m*/ } } }
From source file:com.emergya.persistenceGeo.web.RestResourcesController.java
/** * This method loads a resource from server * // w w w . j a v a2 s. c om * @param resourceId * * @return JSON file with resource */ @RequestMapping(value = "/persistenceGeo/getResource/{resourceId}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE }) public void getResource(@PathVariable String resourceId, HttpServletResponse response) { try { Long accessId = Long.decode(resourceId.split("_")[0]); ResourceDto resource = loadFiles.get(accessId); if (resource == null) { // not loaded yet resource = resourceService.getByAccessId(accessId); loadFiles.put(accessId, resource); } response.setContentType(resource.getType()); response.setHeader("Content-Length", new Long(resource.getSize()).toString()); response.setHeader("Content-Disposition", "inline; filename=" + resource.getName()); IOUtils.copy(new FileInputStream(resource.getData()), response.getOutputStream()); response.flushBuffer(); } catch (Exception e) { e.printStackTrace(); } }
From source file:pt.webdetails.cda.cache.CacheScheduleManager.java
private void persist(IParameterProvider requestParams, OutputStream out) throws Exception { Long id = Long.decode(requestParams.getParameter("id").toString()); Session s = getHibernateSession();/*ww w .ja v a2 s . c o m*/ s.beginTransaction(); UncachedQuery uq = (UncachedQuery) s.load(UncachedQuery.class, id); CachedQuery cq = uq.cacheMe(); if (uq != null) { s.delete(s); } JSONObject json = uq.toJSON(); out.write(json.toString(2).getBytes(ENCODING)); s.flush(); s.getTransaction().commit(); s.close(); }
From source file:org.jboss.dashboard.ui.controller.requestChain.ModalDialogRenderer.java
protected Panel getCurrentPanel() throws Exception { final String idPanel = getRequest().getParameter(Parameters.DISPATCH_IDPANEL); if (idPanel == null) return null; Long id = Long.decode(idPanel); NavigationManager navMgr = NavigationManager.lookup(); Panel[] panels = navMgr.getCurrentSection().getAllPanels(); for (int i = 0; i < panels.length; i++) { Panel panel = panels[i];/*w w w . j av a 2s . c o m*/ if (panel.getPanelId().equals(id)) return panel; } return null; }
From source file:fr.gael.dhus.olingo.v1.entity.Node.java
@Override public Long getContentLength() { initNode();//from www. j ava 2 s. c om if (contentLength == null) { contentLength = -1L; if (hasStream()) { InputStream stream = getStream(); if (stream instanceof FileInputStream) { try { contentLength = ((FileInputStream) stream).getChannel().size(); } catch (IOException e) { // Error while accessing file size: using -1L } } // Still not initialized ? if (contentLength == -1) { DrbAttribute attr = this.drbNode.getAttribute("size"); if (attr != null) { try { contentLength = Long.decode(attr.getValue().toString()); } catch (NumberFormatException nfe) { // Error in attribute... } } } } else { contentLength = 0L; } } return contentLength; }
From source file:info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapterTypedPropertyTest.java
@Test public void testGetItemPropertyWithLongProperty() throws Exception { // GIVEN/*from ww w . j a va2 s . c om*/ // Create a NewNodeAdapter String nodeName = "rootNode"; String id = "propertyID"; String value = "10000"; Node parentNode = session.getRootNode().addNode(nodeName); JcrNodeAdapter adapter = new JcrNodeAdapter(parentNode); // Create the property Property propertyInitial = DefaultPropertyUtil.newDefaultProperty("Long", value); adapter.addItemProperty(id, propertyInitial); // WHEN Property property = adapter.getItemProperty(id); // THEN assertSame(property, propertyInitial); assertEquals(PropertyType.nameFromValue(PropertyType.LONG), property.getType().getSimpleName()); assertEquals(Long.decode(value), property.getValue()); }
From source file:com.emergya.persistenceGeo.web.UserAdminController.java
/** * Pagina para guardar o actualizar//from w w w.jav a 2 s. c om * * @param model * * @return "usuarios" */ @RequestMapping(value = "/admin/salvarUsuario", method = RequestMethod.POST) public String saveUser(@RequestParam String username, @RequestParam String nombreCompleto, @RequestParam String password, @RequestParam String apellidos, @RequestParam String email, @RequestParam String telefono, @RequestParam(required = false) String admin, @RequestParam(required = false) String valid, @RequestParam(required = false) String id, Model model) { UserDto usuario = new UserDto(); // Set id usuario.setId(id != null ? Long.decode(id) : null); usuario.setUsername(username); // Set own attributes usuario.setNombreCompleto(nombreCompleto); usuario.setPassword(password); usuario.setApellidos(apellidos); usuario.setEmail(email); usuario.setTelefono(telefono); usuario.setAdmin(CHK_SI.equals(admin) ? Boolean.TRUE : Boolean.FALSE); usuario.setValid(BOOL_SI.equals(valid) ? Boolean.TRUE : Boolean.FALSE); usuario.setFechaCreacion(new Date()); usuario.setFechaActualizacion(new Date()); // Set relations attributes usuario.setAuthority(""); if (usuario.getId() != null) { usuario = (UserDto) userAdminService.update(usuario); } else { usuario = (UserDto) userAdminService.create(usuario); } return getUsers(model); }