Example usage for java.lang Long decode

List of usage examples for java.lang Long decode

Introduction

In this page you can find the example usage for java.lang Long decode.

Prototype

public static Long decode(String nm) throws NumberFormatException 

Source Link

Document

Decodes a String into a Long .

Usage

From source file:pt.webdetails.cda.cache.scheduler.CacheScheduleManager.java

private void execute(String obj, OutputStream out) throws PluginHibernateException {
    Long id = Long.decode(obj);
    Session s = getHibernateSession();/*from  ww  w .  j av a2  s. c  o m*/
    CachedQuery q = (CachedQuery) s.load(CachedQuery.class, id);

    if (q == null) {
        // Query doesn't exist or is not set for auto-caching
        return;
    }
    try {
        q.execute();
        q.updateNext();
        CacheActivator.reschedule(queue);
        out.write("{\"status\": \"ok\"}".getBytes(ENCODING));
    } catch (Exception ex) {
        logger.error(ex);
        try {
            out.write("{\"status\": \"error\"}".getBytes(ENCODING));
        } catch (Exception ex1) {
            logger.error(ex1);
        }
    } finally {
        s.beginTransaction();
        s.update(q);
        s.flush();
        s.getTransaction().commit();
        s.close();
    }
}

From source file:pt.webdetails.cda.cache.CacheScheduleManager.java

private void delete(IParameterProvider requestParams, OutputStream out) throws PluginHibernateException {
    Long id = Long.decode(requestParams.getParameter("id").toString());
    Session s = getHibernateSession();/*w  w  w  . j av  a2s .  c  o m*/
    s.beginTransaction();

    Query q = (Query) s.load(Query.class, id);
    s.delete(q);

    for (CachedQuery cq : queue) {
        if (cq.getId() == id) {
            queue.remove(cq);
        }
    }

    s.flush();
    s.getTransaction().commit();
    s.close();
}

From source file:org.jboss.dashboard.workspace.export.WorkspaceBuilder.java

protected void createSection(CreateResult result, WorkspaceImpl workspace, XMLNode node, Map attributes,
        boolean onStartup) throws Exception {
    String id = node.getAttributes().getProperty(ExportVisitor.SECTION_ATTR_ID);
    String idTemplate = node.getAttributes().getProperty(ExportVisitor.SECTION_ATTR_ID_TEMPLATE);
    String position = node.getAttributes().getProperty(ExportVisitor.SECTION_ATTR_POSITION);
    String visible = node.getAttributes().getProperty(ExportVisitor.SECTION_ATTR_VISIBLE);
    String regionSpacing = node.getAttributes().getProperty(ExportVisitor.SECTION_ATTR_REGIONSPACING);
    String panelSpacing = node.getAttributes().getProperty(ExportVisitor.SECTION_ATTR_PANELSPACING);
    String parentId = node.getAttributes().getProperty(ExportVisitor.SECTION_ATTR_PARENT_ID);
    String friendlyUrl = node.getAttributes().getProperty(ExportVisitor.SECTION_ATTR_FR_URL);
    String idSkin = node.getAttributes().getProperty(ExportVisitor.SECTION_ATTR_SKIN_ID);
    String idEnvelope = node.getAttributes().getProperty(ExportVisitor.SECTION_ATTR_ENVELOPE_ID);

    Section section = new Section();
    section.setId(Long.decode(id));
    section.setLayoutId(idTemplate);/*from w ww.  j a va  2 s  .  c o m*/
    section.setPosition(Integer.decode(position).intValue());
    section.setVisible(Boolean.valueOf(visible));
    section.setRegionsCellSpacing(Integer.decode(regionSpacing));
    section.setPanelsCellSpacing(Integer.decode(panelSpacing));
    if (parentId != null)
        section.setParentSectionId(Long.decode(parentId));
    section.setFriendlyUrl(friendlyUrl);
    section.setSkinId(idSkin);
    section.setEnvelopeId(idEnvelope);
    section.setWorkspace(workspace);
    UIServices.lookup().getSectionsManager().store(section);
    workspace.addSection(section);
    UIServices.lookup().getWorkspacesManager().store(workspace);

    //Children
    for (int i = 0; i < node.getChildren().size(); i++) {
        XMLNode child = (XMLNode) node.getChildren().get(i);
        if (ExportVisitor.PARAMETER.equals(child.getObjectName())) {
            String name = child.getAttributes().getProperty(ExportVisitor.PARAMETER_ATTR_NAME);
            if (ExportVisitor.SECTION_CHILD_TITLE.equals(name)) {
                String value = child.getAttributes().getProperty(ExportVisitor.PARAMETER_ATTR_VALUE);
                String lang = child.getAttributes().getProperty(ExportVisitor.PARAMETER_ATTR_LANG);
                section.setTitle(value, lang);
            }
        } else if (ExportVisitor.RESOURCE.equals(child.getObjectName())) {
            createResource(result, workspace.getId(), section.getId(), null, child, attributes, onStartup);
        } else if (ExportVisitor.PANEL.equals(child.getObjectName())) {
            createPanel(result, section, child, attributes, onStartup);
        } else if (ExportVisitor.PERMISSION.equals(child.getObjectName())) {
            createPermission(result, section.getWorkspace(), section, child, attributes);
        }
    }
}

From source file:com.l2jfree.gameserver.templates.StatsSet.java

/**
 * Returns the long associated to the key put in parameter ("name"). If the value associated to the key is null, this method returns the value of the parameter deflt.
 * //from w w  w.ja  v  a 2 s. c  o  m
 * @param name : String designating the key in the set
 * @param deflt : long designating the default value if value associated with the key is null
 * @return long : value associated to the key
 */
public final long getLong(String name, long deflt) {
    Object val = get(name);
    if (val == null)
        return deflt;
    if (val instanceof Number)
        return ((Number) val).longValue();
    try {
        return Long.decode((String) val);
    } catch (Exception e) {
        throw new IllegalArgumentException("Integer value required, but found: " + val);
    }
}

From source file:org.apache.cocoon.acting.DatabaseAuthenticatorAction.java

private HashMap propagateParameters(Configuration conf, ResultSet rs, Session session) {
    Configuration table = conf.getChild("table");
    Configuration[] select = table.getChildren("select");
    String session_param, type;/*from ww w .  j  av a2  s. co m*/
    HashMap map = new HashMap();
    try {
        for (int i = 0; i < select.length; i++) {
            try {
                session_param = select[i].getAttribute("to-session");
                if (StringUtils.isNotBlank(session_param)) {
                    Object o = null;
                    String s = rs.getString(i + 1);
                    /* propagate to session */
                    type = select[i].getAttribute("type", "");
                    if (StringUtils.isBlank(type) || "string".equals(type)) {
                        o = s;
                    } else if ("long".equals(type)) {
                        Long l = Long.decode(s);
                        o = l;
                    } else if ("double".equals(type)) {
                        Double d = Double.valueOf(s);
                        o = d;
                    }
                    if (session != null) {
                        session.setAttribute(session_param, o);
                        getLogger().debug("DBAUTH: propagating param " + session_param + "=" + s);
                    }
                    map.put(session_param, o);
                }
            } catch (Exception e) {
                // Empty
            }
        }
        return map;
    } catch (Exception e) {
        getLogger().debug("exception: ", e);
    }
    return null;
}

From source file:pt.webdetails.cda.cache.scheduler.CacheScheduleManager.java

private void delete(String obj, OutputStream out) throws PluginHibernateException {
    Long id = Long.decode(obj);
    Session s = getHibernateSession();/*from   ww w .  j av a  2 s  .c  o m*/
    s.beginTransaction();

    Query q = (Query) s.load(Query.class, id);
    s.delete(q);

    for (CachedQuery cq : queue) {
        if (cq.getId() == id) {
            queue.remove(cq);
        }
    }

    s.flush();
    s.getTransaction().commit();
    s.close();
}

From source file:controllers.Service.java

public static void getAllResults(String surveyId) {
    Survey survey = Survey.findById(Long.decode(surveyId));
    Collection<NdgResult> results = new ArrayList<NdgResult>();
    Collection<NdgResult> removalResults = new ArrayList<NdgResult>();
    results = survey.resultCollection;/*  w  w  w .  j av a2s.  co  m*/

    for (NdgResult current : results) {
        if (current.latitude == null || current.longitude == null) {
            removalResults.add(current);
        }
    }
    results.removeAll(removalResults);

    JSONSerializer surveyListSerializer = new JSONSerializer();
    surveyListSerializer
            .include("id", "resultId", "title", "startTime", "endTime", "ndgUser", "latitude", "longitude")
            .exclude("*").rootName("items");

    renderJSON(surveyListSerializer.serialize(results));
}

From source file:org.jbpm.formModeler.components.editor.WysiwygFormEditor.java

public void actionDelete(CommandRequest request) throws Exception {
    checkEditionContext(request);/*from w  w  w.  j a v  a2  s .c  o  m*/

    Long pos = Long.decode(request.getParameter("position"));
    Form form = getCurrentForm();
    if (form == null) {
        log.error("Cannot modify unexistant form.");
    } else {
        Field fieldNextToDeleted = getFieldInPosition(pos.intValue() + 1);
        if (fieldNextToDeleted != null) {
            Field fieldToDelete = getFieldInPosition(pos.intValue());
            if (!Boolean.TRUE.equals(fieldToDelete.getGroupWithPrevious())) {
                fieldNextToDeleted.setGroupWithPrevious(fieldToDelete.getGroupWithPrevious());
            }
        }
        getFormManager().deleteField(form, pos.intValue());
        if (getCurrentEditFieldPosition() == pos.intValue())
            setCurrentEditFieldPosition(-1);
        else if (getCurrentEditFieldPosition() > pos.intValue())
            setCurrentEditFieldPosition(getCurrentEditFieldPosition() - 1);
    }
}

From source file:com.emergya.persistenceGeo.web.RestLayersAdminController.java

/**
 * This method loads layers.json related with a user
 * //w  w  w .j av a2 s . co m
 * @param username
 * 
 * @return JSON file with layers
 */
@RequestMapping(value = "/persistenceGeo/getLayerResource/{layerId}", method = RequestMethod.GET, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public void loadLayer(@PathVariable String layerId, HttpServletResponse response) {
    try {
        /*
        //TODO: Secure with logged user
        String username = ((UserDetails) SecurityContextHolder.getContext()
              .getAuthentication().getPrincipal()).getUsername(); 
         */
        response.setContentType("application/xml");
        response.setHeader("Content-Disposition", "attachment; filename=test.xml");
        IOUtils.copy(new FileInputStream(loadedLayers.get(Long.decode(layerId))), response.getOutputStream());
        response.flushBuffer();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.emergya.persistenceGeo.web.RestFoldersAdminController.java

/**
 * This method loads all folders related with a user
 * /*from   w  ww  .java 2 s.  c  o  m*/
 * @param username
 * 
 * @return JSON file with folders
 */
@RequestMapping(value = "/persistenceGeo/loadFoldersByGroup/{idGroup}", produces = {
        MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Map<String, Object> loadFoldersByGroup(@PathVariable String idGroup,
        @RequestParam(value = "filter", required = false) String filter) {
    Map<String, Object> result = new HashMap<String, Object>();
    List<FolderDto> folders = null;
    try {
        /*
         * //TODO: Secure with logged user String username = ((UserDetails)
         * SecurityContextHolder.getContext()
         * .getAuthentication().getPrincipal()).getUsername();
         */
        if (idGroup != null) {
            folders = new LinkedList<FolderDto>();
            FolderDto rootFolder;
            if (filter != null) {
                rootFolder = foldersAdminService.getRootGroupFolder(Long.decode(idGroup));
            } else {
                rootFolder = foldersAdminService.getRootGroupFolder(Long.decode(idGroup));
            }
            FoldersUtils.getFolderTreeFiltered(rootFolder, folders,
                    filter != null ? new Boolean(filter) : null);
        }
        result.put(SUCCESS, true);
    } catch (Exception e) {
        e.printStackTrace();
        result.put(SUCCESS, false);
    }

    result.put(RESULTS, folders != null ? folders.size() : 0);
    result.put(ROOT, folders);

    return result;
}