Example usage for java.lang NumberFormatException printStackTrace

List of usage examples for java.lang NumberFormatException printStackTrace

Introduction

In this page you can find the example usage for java.lang NumberFormatException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.znsx.cms.web.controller.UserController.java

@InterfaceDescription(logon = true, method = "Create_User", cmd = "2002")
@RequestMapping("/create_user.json")
public void createUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String standardNumber = request.getParameter("standardNumber");

    String ccsId = request.getParameter("ccsId");
    if (StringUtils.isBlank(ccsId)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [ccsId]");
    }//from   www  .j av  a 2 s .  co  m

    String logonName = request.getParameter("logonName");
    if (StringUtils.isBlank(logonName)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [logonName]");
    }

    String name = request.getParameter("name");
    if (StringUtils.isBlank(name)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [name]");
    }

    String password = request.getParameter("password");
    if (StringUtils.isBlank(password)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [password]");
    }

    Short sex = new Short("0");
    String sexString = request.getParameter("sex");
    if (StringUtils.isNotBlank(sexString)) {
        try {
            sex = Short.parseShort(sexString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter sex[" + sexString + "] invalid !");
        }
    }

    String email = request.getParameter("email");

    String phone = request.getParameter("phone");

    String address = request.getParameter("address");

    String organId = request.getParameter("organId");
    if (StringUtils.isBlank(organId)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [organId]");
    }

    Short priority = new Short("0");
    String priorityString = request.getParameter("priority");
    if (StringUtils.isNotBlank(priorityString)) {
        try {
            priority = Short.parseShort(priorityString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter priority[" + priorityString + "] invalid !");
        }
    }

    String note = request.getParameter("note");

    Integer maxConnect = 1;
    String maxConnectString = request.getParameter("maxConnect");
    if (StringUtils.isNotBlank(maxConnectString)) {
        try {
            maxConnect = Integer.parseInt(maxConnectString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter maxConnect[" + maxConnectString + "] invalid !");
        }
    }

    // ?License??,?
    License license = licenseManager.getLicense();
    int userCount = userManager.countUser();
    if (userCount >= Integer.parseInt(license.getUserAmount())) {
        throw new BusinessException(ErrorCode.USER_AMOUNT_LIMIT, "User amount over license limit !");
    }

    // ??
    if (StringUtils.isBlank(standardNumber)) {
        standardNumber = userManager.generateStandardNum("User", organId);
    }

    // 
    String userId = userManager.createUser(name, standardNumber, ccsId, logonName, password, sex, email, phone,
            address, organId, priority, note, maxConnect);

    BaseDTO dto = new BaseDTO();
    dto.setCmd("2002");
    dto.setMethod("Create_User");
    dto.setMessage(userId);

    writePage(response, dto);
}

From source file:client.gui.ConnectionDialog.java

public void actionPerformed(final ActionEvent event) {

    String nick = null;/*  ww w.  jav  a2  s. c o m*/
    String host = null;
    int port = 0;

    if (event.getSource() == connect) {
        nick = this.nick.getText();
        host = this.host.getText();
        try {
            port = Integer.parseInt(this.port.getText());
        } catch (NumberFormatException e1) {
            new MyDialog("Port number must be integer").setVisible(true);
            return;
        }
    } else if (event.getSource() == connectDev) {
        nick = generateNick();
        host = "localhost";
        port = 5555;
    } else if (event.getSource() == connectSame) {
        nick = "a";
        host = "localhost";
        port = 5555;
    }

    if (port <= 0) {
        new MyDialog("Port number must be bigger than 0").setVisible(true);
        return;
    }

    Socket socket;
    BufferedReader in;

    try {
        socket = new Socket(host, port);
        GlobalVariables.out = new PrintWriter(socket.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    } catch (java.net.UnknownHostException e2) {
        new MyDialog("Unknown host").setVisible(true);
        return;
    } catch (IOException e3) {
        new MyDialog("Connection unsuccessful").setVisible(true);
        GlobalVariables.connected = false;
        return;
    } catch (java.lang.IllegalArgumentException e4) {
        new MyDialog("Port number is too big").setVisible(true);
        return;
    }

    System.out.println("Nick: " + nick);

    final JSONArray toSend = new JSONArray();
    try {
        toSend.put(new JSONObject().put("action", "first_connection"));
        toSend.put(new JSONObject().put("nick", nick));
    } catch (JSONException e1) {
        e1.printStackTrace();
    }

    GlobalVariables.daemon = true;
    GlobalVariables.me.setNick(nick);
    GlobalVariables.connect.setEnabled(false);
    GlobalVariables.connected = true;
    setVisible(false);
    GlobalVariables.out.println(toSend);
    Thread thread;
    thread = new ReceivingData(in);
    thread.setDaemon(true);
    thread.start();
}

From source file:org.dcm4chee.proxy.forward.ForwardFiles.java

private Integer getPreviousRetries(ProxyAEExtension proxyAEE, File file) {
    String suffix = file.getName().substring(file.getName().lastIndexOf('.'));
    Retry matchingRetry = getMatchingRetry(proxyAEE, suffix);
    if (matchingRetry != null) {
        String substring = suffix.substring(matchingRetry.getRetryObject().getSuffix().length());
        if (!substring.isEmpty())
            try {
                return Integer.parseInt(substring);
            } catch (NumberFormatException e) {
                LOG.error("Error parsing number of retries in suffix of file " + file.getName());
                if (LOG.isDebugEnabled())
                    e.printStackTrace();
            }/*  w  ww. jav  a2s  .  c  o  m*/
    }
    return 1;
}

From source file:com.safi.workshop.util.SafletPersistenceManager.java

public void disconnectLocalResources() {
    IWorkspace ws = ResourcesPlugin.getWorkspace();
    IProject[] projects = ws.getRoot().getProjects();
    List<IProject> plist = new ArrayList<IProject>(Arrays.asList(projects));
    final Map<String, ServerResource> localResources = new HashMap<String, ServerResource>();
    for (final IProject p : plist) {
        try {//from   w w w . j  a  v  a 2  s. c om

            String id = p.getPersistentProperty(SafletPersistenceManager.RES_ID_KEY);
            if (StringUtils.isNotBlank(id)) {
                try {
                    p.setPersistentProperty(SafletPersistenceManager.RES_ID_KEY, null);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
            String lm = p.getPersistentProperty(SafletPersistenceManager.MODIFIED_KEY);
            if (StringUtils.isNotBlank(lm)) {
                try {
                    p.setPersistentProperty(SafletPersistenceManager.MODIFIED_KEY, null);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }

            String lu = p.getPersistentProperty(SafletPersistenceManager.UPDATED_KEY);
            if (StringUtils.isNotBlank(lu)) {
                try {
                    p.setPersistentProperty(SafletPersistenceManager.UPDATED_KEY, null);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }

            p.accept(new IResourceVisitor() {

                @Override
                public boolean visit(IResource resource) throws CoreException {
                    if (resource.getType() == IResource.FILE && "saflet".equals(resource.getFileExtension())) {
                        String id = resource.getPersistentProperty(SafletPersistenceManager.RES_ID_KEY);
                        if (StringUtils.isNotBlank(id)) {
                            try {
                                resource.setPersistentProperty(SafletPersistenceManager.RES_ID_KEY, null);
                            } catch (NumberFormatException e) {
                                e.printStackTrace();
                            }
                        }
                        String lm = resource.getPersistentProperty(SafletPersistenceManager.MODIFIED_KEY);
                        if (StringUtils.isNotBlank(lm)) {
                            try {
                                resource.setPersistentProperty(SafletPersistenceManager.MODIFIED_KEY, null);
                            } catch (NumberFormatException e) {
                                e.printStackTrace();
                            }
                        }

                        String lu = resource.getPersistentProperty(SafletPersistenceManager.UPDATED_KEY);
                        if (StringUtils.isNotBlank(lu)) {
                            try {
                                resource.setPersistentProperty(SafletPersistenceManager.UPDATED_KEY, null);
                            } catch (NumberFormatException e) {
                                e.printStackTrace();
                            }
                        }

                    }
                    return true;
                }

            });
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }

    DriverManager manager = SQLExplorerPlugin.getDefault().getDriverModel();
    Set<DBResource> resources = new HashSet<DBResource>();
    for (ManagedDriver md : manager.getDrivers()) {
        if (md.getDriver() != null) {
            resources.add(md.getDriver());
        }
    }
    AliasManager am = SQLExplorerPlugin.getDefault().getAliasManager();
    for (Alias a : am.getAliases()) {
        if (a.getConnection() != null) {
            resources.add(a.getConnection());
            for (Query q : a.getConnection().getQueries()) {
                resources.add(q);
                for (QueryParameter qp : q.getParameters())
                    resources.add(qp);
            }
        }

    }

    for (DBResource res : resources) {
        res.setId(-1);
        res.setLastModified(null);
        res.setLastUpdated(null);
    }
}

From source file:org.fao.geonet.kernel.SchemaManager.java

/**
  * Gets the next available blank number that can be used to map the presentation xslt used by the schema (see
  * metadata-utils.xsl and Geonet.File.METADATA_MAX_BLANKS). If the presentation xslt is already mapped then we exit
  * early with return value -1.//from ww  w. j av  a 2  s .  c  o m
 *
 * @param root the list of elements from the schemaplugin-uri-catalog
 * @param name the name of the schema to use
  * @return
  * @throws Exception
 */
private int getHighestSchemaPluginCatalogId(String name, Element root) throws Exception {
    @SuppressWarnings("unchecked")
    List<Content> contents = root.getContent();

    String baseBlank = Geonet.File.METADATA_BASEBLANK;
    String ourUri = buildSchemaFolderPath(name);

    for (Content content : contents) {
        Element uri = null;

        if (content instanceof Element)
            uri = (Element) content;
        else
            continue; // skip this

        if (!uri.getName().equals("rewriteURI") || !uri.getNamespace().equals(Namespaces.OASIS_CATALOG)) {
            if (Log.isDebugEnabled(Geonet.SCHEMA_MANAGER))
                Log.debug(Geonet.SCHEMA_MANAGER,
                        "Skipping element " + uri.getQualifiedName() + ":" + uri.getNamespace());
            continue;
        }

        // -- if already mapped then exit
        if (uri.getAttributeValue("rewritePrefix").equals(ourUri))
            return -1;

        String nameAttr = uri.getAttributeValue("uriStartString");
        if (nameAttr.startsWith(Geonet.File.METADATA_BLANK)) {
            if (nameAttr.compareTo(baseBlank) > 0)
                baseBlank = nameAttr;
        }
    }

    // -- get highest appropriate number
    String baseNr = baseBlank.replace(Geonet.File.METADATA_BLANK, "");
    int baseNrInt = 0;
    try {
        baseNrInt = Integer.parseInt(baseNr);
    } catch (NumberFormatException nfe) {
        nfe.printStackTrace();
        throw new IllegalArgumentException("Cannot decode blank number from " + baseBlank);
    }
    return baseNrInt;
}

From source file:com.znsx.cms.web.controller.UserController.java

@InterfaceDescription(logon = true, method = "Create_Sys_Log", cmd = "1021")
@RequestMapping("/create_sys_log.xml")
public void createSysLog(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String targetId = request.getParameter("targetId");
    if (StringUtils.isBlank(targetId)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [targetId]");
    }/*from  w ww  . ja  v  a  2s .  c  om*/

    String operationTypeModel = request.getParameter("operationTypeModel");

    Integer targetType = null;
    String targetTypeString = request.getParameter("targetType");
    if (StringUtils.isBlank(targetTypeString)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [targetType]");
    } else {
        try {
            targetType = Integer.parseInt(targetTypeString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter targetType[" + targetType + "] invalid !");
        }
    }

    String operationCode = request.getParameter("operationCode");
    if (StringUtils.isBlank(operationCode)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [operationCode]");
    }

    String operationType = request.getParameter("operationType");
    if (StringUtils.isBlank(operationType)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [operationType]");
    }

    String operationName = request.getParameter("operationName");
    if (StringUtils.isBlank(operationName)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [operationName]");
    }

    String successFlag = request.getParameter("successFlag");
    if (StringUtils.isBlank(successFlag)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [successFlag]");
    }

    // ???,??CameraDws?
    String type = "";
    if (TypeDefinition.DEVICE_TYPE_CAMERA == targetType.intValue()) {
        type = "Camera";
    } else if (TypeDefinition.SERVER_TYPE_DWS == targetType.intValue()) {
        type = "Dws";
    } else if (TypeDefinition.DEVICE_TYPE_DVR == targetType.intValue()) {
        type = "Dvr";
    } else if (TypeDefinition.DEVICE_TYPE_VD == targetType.intValue()) {
        type = "FVehicleDetector";
    } else if (TypeDefinition.DEVICE_TYPE_WS == targetType.intValue()) {
        type = "WindSpeed";
    } else if (TypeDefinition.DEVICE_TYPE_WST == targetType.intValue()) {
        type = "WeatherStat";
    } else if (TypeDefinition.DEVICE_TYPE_LOLI == targetType.intValue()) {
        type = "LoLi";
    } else if (TypeDefinition.DEVICE_TYPE_FD == targetType.intValue()) {
        type = "FireDetector";
    } else if (TypeDefinition.DEVICE_TYPE_COVI == targetType.intValue()) {
        type = "Covi";
    } else if (TypeDefinition.DEVICE_TYPE_NOD == targetType.intValue()) {
        type = "NoDetector";
    } else if (TypeDefinition.DEVICE_TYPE_CMS == targetType.intValue()) {
        type = "ControlDevice";
    } else if (TypeDefinition.DEVICE_TYPE_FAN == targetType.intValue()) {
        type = "ControlDevice";
    } else if (TypeDefinition.DEVICE_TYPE_LIGHT == targetType.intValue()) {
        type = "ControlDevice";
    } else if (TypeDefinition.DEVICE_TYPE_RD == targetType.intValue()) {
        type = "ControlDevice";
    } else if (TypeDefinition.DEVICE_TYPE_WP == targetType.intValue()) {
        type = "ControlDevice";
    } else if (TypeDefinition.DEVICE_TYPE_RAIL == targetType.intValue()) {
        type = "ControlDevice";
    } else if (TypeDefinition.DEVICE_TYPE_IS == targetType.intValue()) {
        type = "ControlDevice";
    } else if (TypeDefinition.DEVICE_TYPE_PB == targetType.intValue()) {
        type = "PushButton";
    } else if (TypeDefinition.DEVICE_TYPE_TSL == targetType.intValue()) {
        type = "ControlDevice";
    } else if (TypeDefinition.DEVICE_TYPE_LIL == targetType.intValue()) {
        type = "ControlDevice";
    } else if (TypeDefinition.DEVICE_TYPE_BT == targetType.intValue()) {
        type = "BoxTransformer";
    } else if (TypeDefinition.DEVICE_TYPE_VI_DETECTOR == targetType.intValue()) {
        type = "ViDetector";
    } else if (TypeDefinition.DEVICE_TYPE_ROAD_DETECTOR == targetType.intValue()) {
        type = "RoadDetector";
    } else if (TypeDefinition.DEVICE_TYPE_BRIDGE_DETECTOR == targetType.intValue()) {
        type = "BridgeDetector";
    } else if (TypeDefinition.DEVICE_TYPE_EMERGENCY_PHONE == targetType.intValue()) {
        type = "UrgentPhone";
    } else if (TypeDefinition.DEVICE_TYPE_SOLAR_BATTERY == targetType.intValue()) {
        type = "SolarBattery";
    } else if (TypeDefinition.DEVICE_TYPE_DISPLAY_WALL == targetType.intValue()) {
        type = "DisplayWall";
    } else if (TypeDefinition.DEVICE_TYPE_WH == targetType.intValue()) {
        type = "EmUnit";
    } else if (TypeDefinition.DEVICE_TYPE_TUNNEL == targetType.intValue()) {
        type = "Organ";
    } else if (TypeDefinition.DEVICE_TYPE_BRIDGE == targetType.intValue()) {
        type = "Organ";
    } else if (TypeDefinition.DEVICE_TYPE_ROAD == targetType.intValue()) {
        type = "Organ";
    } else if (TypeDefinition.DEVICE_TYPE_TOLLGATE == targetType.intValue()) {
        type = "Organ";
    } else if (TypeDefinition.DEVICE_TYPE_ROAD_MOUTH == targetType.intValue()) {
        type = "RoadMouth";
    } else if (TypeDefinition.DEVICE_TYPE_EM_RESOURCE == targetType.intValue()) {
        type = "Resource";
    } else if (TypeDefinition.DEVICE_TYPE_WAREHOUSE == targetType.intValue()) {
        type = "EmUnit";
    } else if (TypeDefinition.DEVICE_TYPE_FIRE == targetType.intValue()) {
        type = "EmUnit";
    } else if (TypeDefinition.DEVICE_TYPE_HOSPITAL == targetType.intValue()) {
        type = "EmUnit";
    } else if (TypeDefinition.DEVICE_TYPE_POLICE == targetType.intValue()) {
        type = "EmUnit";
    } else if (TypeDefinition.DEVICE_TYPE_ROAD_ADMIN == targetType.intValue()) {
        type = "EmUnit";
    } else if (TypeDefinition.DEVICE_TYPE_CMS_INFO == targetType.intValue()) {
        type = "Playlist";
    } else if (TypeDefinition.DEVICE_TYPE_CMS_INFO_FOLDER == targetType.intValue()) {
        type = "PlaylistFolder";
    } else if (TypeDefinition.DEVICE_TYPE_VIEW_SELECT == targetType.intValue()) {
        type = "null";
    } else if (TypeDefinition.DEVICE_TYPE_STAT == targetType.intValue()) {
        type = "null";
    } else if (TypeDefinition.DEVICE_TYPE_WORK_MANAGE == targetType.intValue()) {
        type = "null";
    } else if (TypeDefinition.DEVICE_TYPE_FLOW_VIEW == targetType.intValue()) {
        type = "null";
    } else if (TypeDefinition.DEVICE_TYPE_EVENT == targetType.intValue()) {
        type = "Event";
    } else if (TypeDefinition.DEVICE_TYPE_USER == targetType.intValue()) {
        type = "User";
    } else if (TypeDefinition.DEVICE_TYPE_TUNNEL_VIEW == targetType.intValue()) {
        type = "null";
    } else if (TypeDefinition.DEVICE_TYPE_TOLLGATE_VIEW == targetType.intValue()) {
        type = "null";
    } else if (TypeDefinition.DEVICE_TYPE_BRIDGE_VIEW == targetType.intValue()) {
        type = "null";
    } else {
        type = "null";
    }
    String targetName = "null";
    if (!"null".equals(type)) {
        targetName = sysLogManager.getNameByIdAndType(targetId, type);
        // Camera???
        if (StringUtils.isBlank(targetName) && type.equals("Camera")) {
            targetName = sysLogManager.getNameByIdAndType(targetId, "SubPlatformResource");
        }
    } else {
        targetName = operationName;
    }
    String resourceType = resource.get().getType();
    String resourceId = resource.get().getId();
    String resourceName = resource.get().getName();
    // ??
    if (resourceType.equals(TypeDefinition.CLIENT_TYPE_SGC)
            || resourceType.equals(TypeDefinition.CLIENT_TYPE_CS)) {
        userManager.saveUserOperationLog(resourceId, operationName, operationTypeModel);
    }

    SysLog sysLog = new SysLog();
    sysLog.setCreateTime(System.currentTimeMillis());
    sysLog.setLogTime(System.currentTimeMillis());
    sysLog.setOperationCode(operationCode);
    sysLog.setOperationName(operationName);
    sysLog.setOperationType(operationType);
    sysLog.setOrganId(resource.get().getOrganId());
    sysLog.setResourceId(resourceId);
    sysLog.setResourceName(resourceName);
    sysLog.setResourceType(resourceType);
    sysLog.setSuccessFlag(successFlag);
    sysLog.setTargetId(targetId);
    sysLog.setTargetName(targetName);
    sysLog.setTargetType(type);
    sysLogManager.batchLog(sysLog);

    // 
    BaseDTO dto = new BaseDTO();
    dto.setCmd("1021");
    dto.setMethod("Create_Sys_Log");
    Document doc = new Document();
    Element root = ElementUtil.createElement("Response", dto, null, null);
    doc.setRootElement(root);
    writePageWithContentLength(response, doc);
}

From source file:at.ac.tuwien.inso.subcat.miner.MinerRunner.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption("h", "help", false, "Show this options");
    options.addOption("m", "miner-help", false, "Show miner specific options");
    options.addOption("d", "db", true, "The database to process (required)");
    options.addOption("p", "project", true, "The project ID to process");
    options.addOption("P", "list-projects", false, "List all registered projects");
    options.addOption("v", "verbose", false, "Show details");

    options.addOption(null, "bug-repo", true, "Bug Repository URL");
    options.addOption(null, "bug-product", true, "Bug Product Name");
    options.addOption(null, "bug-tracker", true, "Bug Tracker name (e.g. bugzilla)");
    options.addOption(null, "bug-account", true, "Bug account name");
    options.addOption(null, "bug-passwd", true, "Bug account password");
    options.addOption(null, "bug-enable-untrusted", false, "Accept untrusted certificates");
    options.addOption(null, "bug-threads", true, "Thread count used in bug miners");
    options.addOption(null, "bug-cooldown-time", true, "Bug cooldown time");
    options.addOption(null, "bug-miner-option", true, "Bug miner specific option. Format: <option-name>:value");
    options.addOption(null, "bug-update", false, "Mine all changes since the last run");
    options.getOption("bug-miner-option").setArgs(Option.UNLIMITED_VALUES);

    options.addOption(null, "src-path", true, "Local source repository path");
    options.addOption(null, "src-remote", true, "Remote address");
    options.addOption(null, "src-passwd", true, "Source repository account password");
    options.addOption(null, "src-account", true, "Source repository account name");
    options.addOption(null, "src-miner-option", true,
            "Source miner specific option. Format: <option-name>:value");
    options.getOption("src-miner-option").setArgs(Option.UNLIMITED_VALUES);

    final Reporter reporter = new Reporter(true);
    reporter.startTimer();//from   w w w.  jav  a2  s  .co  m

    boolean printTraces = false;
    Settings settings = new Settings();
    ModelPool pool = null;

    CommandLineParser parser = new PosixParser();

    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("postprocessor", options);
            return;
        }

        if (cmd.hasOption("miner-help")) {
            init();
            for (MetaData meta : registeredMiner) {
                System.out.println(meta.name());
                for (Entry<String, ParamType> opt : meta.getSpecificParams().entrySet()) {
                    System.out.println("  - " + opt.getKey() + " (" + opt.getValue() + ")");
                }
            }
            return;
        }

        if (cmd.hasOption("db") == false) {
            reporter.error("miner", "Option --db is required");
            reporter.printSummary();
            return;
        }

        printTraces = cmd.hasOption("verbose");
        pool = new ModelPool(cmd.getOptionValue("db"), 2);

        if (cmd.hasOption("list-projects")) {
            Model model = pool.getModel();

            for (Project proj : model.getProjects()) {
                System.out.println("  " + proj.getId() + ": " + proj.getDate());
            }

            model.close();
            return;
        }

        Project project;
        Model model = pool.getModel();
        boolean hasSrcInfos = false;
        boolean hasBugInfos = false;
        if (cmd.hasOption("project")) {
            try {
                int projId = Integer.parseInt(cmd.getOptionValue("project"));
                project = model.getProject(projId);
            } catch (NumberFormatException e) {
                reporter.error("post-processor", "Invalid project ID");
                reporter.printSummary();
                return;
            }

            if (project == null) {
                reporter.error("post-processor", "Invalid project ID");
                reporter.printSummary();
                return;
            }

            List<String> flags = model.getFlags(project);
            hasBugInfos = flags.contains(Model.FLAG_BUG_INFO);
            hasSrcInfos = flags.contains(Model.FLAG_SRC_INFO);
        } else {
            project = model.addProject(new Date(), null, settings.bugTrackerName, settings.bugRepository,
                    settings.bugProductName, null);
        }
        model.close();

        //
        // Source Repository Mining:
        //

        settings.srcLocalPath = cmd.getOptionValue("src-path");
        settings.srcRemote = cmd.getOptionValue("src-remote");
        settings.srcRemotePw = cmd.getOptionValue("src-passwd");
        settings.srcRemoteUser = cmd.getOptionValue("src-account");

        if (settings.srcRemotePw == null || settings.srcRemoteUser == null) {
            if (settings.srcRemotePw != null) {
                reporter.error("miner", "--src-passwd should only be used in combination with --src-account");
                reporter.printSummary();
                return;
            } else if (settings.srcRemoteUser != null) {
                reporter.error("miner", "--src-account should only be used in combination with --src-passwd");
                reporter.printSummary();
                return;
            }
        }

        if (settings.srcRemoteUser != null && settings.srcRemote == null) {
            reporter.error("miner", "--src-account should only be used in combination with --src-remote");
            reporter.printSummary();
            return;
        }

        if (settings.srcLocalPath != null && hasSrcInfos) {
            reporter.error("miner", "Source repository updates are not supported yet.");
            reporter.printSummary(true);
            return;
        }

        //
        // Bug Repository Mining:
        //

        settings.bugRepository = cmd.getOptionValue("bug-repo");
        settings.bugProductName = cmd.getOptionValue("bug-product");
        settings.bugTrackerName = cmd.getOptionValue("bug-tracker");
        settings.bugEnableUntrustedCertificates = cmd.hasOption("bug-enable-untrusted");
        settings.bugLoginUser = cmd.getOptionValue("bug-account");
        settings.bugLoginPw = cmd.getOptionValue("bug-passwd");

        settings.bugUpdate = cmd.hasOption("bug-update");
        boolean includeBugs = false;
        if (settings.bugUpdate) {
            if (project.getBugTracker() == null || project.getDomain() == null) {
                reporter.error("miner",
                        "flag --bug-update is requires previously mined bugs. Use --bug-repository, --bug-product and --bug-tracker.");
                reporter.printSummary(true);
                return;
            }
            if (settings.bugTrackerName != null) {
                reporter.warning("miner", "flag --bug-tracker without effect");
            }
            if (settings.bugProductName != null) {
                reporter.warning("miner", "flag --bug-product without effect");
            }
            if (settings.bugRepository != null) {
                reporter.warning("miner", "flag --bug-repository without effect");
            }

            settings.bugTrackerName = project.getBugTracker();
            settings.bugProductName = project.getProduct();
            settings.bugRepository = project.getDomain();
            includeBugs = true;
        } else if (settings.bugRepository != null && settings.bugProductName != null
                && settings.bugTrackerName != null) {
            if (hasBugInfos == false) {
                // The user is trying to append bug tracker information to a existing project.
            } else if (!settings.bugTrackerName.equalsIgnoreCase(project.getBugTracker())
                    || !settings.bugProductName.equalsIgnoreCase(project.getProduct())
                    || !settings.bugRepository.equalsIgnoreCase(project.getDomain())) {
                reporter.error("miner",
                        "There are already previously mined bugs for this project. Use --bug-update to update the database.");
                reporter.printSummary(true);
                return;
            }
            if (settings.bugRepository == null) {
                reporter.error("miner", "flag --bug-repository is required");
                reporter.printSummary(true);
                return;
            }
            if (settings.bugProductName == null) {
                reporter.error("miner", "flag --bug-product is required");
                reporter.printSummary(true);
                return;
            }
            includeBugs = true;
        }

        if (includeBugs) {
            if (settings.bugLoginPw == null || settings.bugLoginUser == null) {
                if (settings.bugLoginPw != null) {
                    reporter.error("miner",
                            "--bug-passwd should only be used in combination with --bug-account");
                    reporter.printSummary();
                    return;
                } else if (settings.bugLoginUser != null) {
                    reporter.error("miner",
                            "--bug-account should only be used in combination with --bug-passwd");
                    reporter.printSummary();
                    return;
                }
            }

            if (cmd.hasOption("bug-threads")) {
                try {
                    settings.bugThreads = Integer.parseInt(cmd.getOptionValue("bug-threads"));
                } catch (Exception e) {
                    reporter.error("miner", "--bug-threads: Invalid parameter type");
                    reporter.printSummary();
                    return;
                }
            }

            if (cmd.hasOption("bug-cooldown-time")) {
                try {
                    settings.bugCooldownTime = Integer.parseInt(cmd.getOptionValue("bug-cooldown-time"));
                } catch (Exception e) {
                    reporter.error("miner", "--bug-cooldown-time: Invalid parameter type");
                    reporter.printSummary();
                    return;
                }
            }

            if (cmd.hasOption("bug-miner-option")) {
                for (String str : cmd.getOptionValues("bug-miner-option")) {
                    addSpecificParameter(settings.bugSpecificParams, str);
                }
            }

            if (cmd.hasOption("src-miner-option")) {
                for (String str : cmd.getOptionValues("src-miner-option")) {
                    addSpecificParameter(settings.srcSpecificParams, str);
                }
            }
        } else {
            if (settings.bugLoginPw != null) {
                reporter.error("miner", "--bug-passwd should only be used in combination with --bug-account");
                reporter.printSummary();
                return;
            }
            if (settings.bugLoginUser != null) {
                reporter.error("miner", "--bug-account should only be used in combination with --bug-account");
                reporter.printSummary();
                return;
            }
            if (settings.bugRepository != null) {
                reporter.error("miner",
                        "--bug-repo should only be used in combination with --bug-product and --bug-tracker");
                reporter.printSummary();
                return;
            }
            if (settings.bugProductName != null) {
                reporter.error("miner",
                        "--bug-product should only be used in combination with --bug-repo and --bug-tracker");
                reporter.printSummary();
                return;
            }
            if (settings.bugTrackerName != null) {
                reporter.error("miner",
                        "--bug-tracker should only be used in combination with --bug-repo and --bug-product");
                reporter.printSummary();
                return;
            }
            if (settings.bugEnableUntrustedCertificates) {
                reporter.error("miner",
                        "--bug-enable-untrusted should only be used in combination with --bug-repo, --bug-tracker and --bug-product");
                reporter.printSummary();
                return;
            }
            if (settings.bugUpdate) {
                reporter.error("miner",
                        "--bug-update should only be used in combination with --bug-repo, --bug-tracker and --bug-product");
                reporter.printSummary();
                return;
            }
            if (cmd.hasOption("bug-threads")) {
                reporter.error("miner",
                        "--bug-threads should only be used in combination with --bug-repo, --bug-tracker and --bug-product");
                reporter.printSummary();
                return;
            }
            if (cmd.hasOption("bug-cooldown-time")) {
                reporter.error("miner",
                        "--bug-cooldown-time should only be used in combination with --bug-repo, --bug-tracker and --bug-product");
                reporter.printSummary();
                return;
            }
            if (cmd.hasOption("bug-miner-option")) {
                reporter.error("miner",
                        "--bug-miner-option should only be used in combination with --bug-repo, --bug-tracker and --bug-product");
                reporter.printSummary();
                return;
            }
        }

        //
        // Run:
        //

        MinerRunner runner = new MinerRunner(pool, project, settings, reporter);
        if (cmd.hasOption("verbose")) {
            runner.addListener(new MinerListener() {
                private Map<Miner, Integer> totals = new HashMap<Miner, Integer>();

                @Override
                public void start(Miner miner) {
                }

                @Override
                public void end(Miner miner) {
                }

                @Override
                public void stop(Miner miner) {
                }

                @Override
                public void tasksTotal(Miner miner, int count) {
                    totals.put(miner, count);
                }

                @Override
                public void tasksProcessed(Miner miner, int processed) {
                    Integer total = totals.get(miner);
                    reporter.note(miner.getName(),
                            "status: " + processed + "/" + ((total == null) ? "0" : total));
                }
            });
        }

        runner.run();
    } catch (ParameterException e) {
        reporter.error(e.getMiner().getName(), e.getMessage());
    } catch (ParseException e) {
        reporter.error("miner", "Parsing failed: " + e.getMessage());
        if (printTraces == true) {
            e.printStackTrace();
        }
    } catch (ClassNotFoundException e) {
        reporter.error("miner", "Failed to create a database connection: " + e.getMessage());
        if (printTraces == true) {
            e.printStackTrace();
        }
    } catch (SQLException e) {
        reporter.error("miner", "Failed to create a database connection: " + e.getMessage());
        if (printTraces == true) {
            e.printStackTrace();
        }
    } catch (MinerException e) {
        reporter.error("miner", "Mining Error: " + e.getMessage());
        if (printTraces == true) {
            e.printStackTrace();
        }
    } finally {
        if (pool != null) {
            pool.close();
        }
    }

    reporter.printSummary(true);
}

From source file:br.unicamp.cst.behavior.glas.SequenceBuilderCodelet.java

@Override
public void proc() {
    if (enabled) {

        boolean new_stim = (NEW_STIM_MO.getI().equals(String.valueOf(true)));
        boolean new_action = (NEW_ACTION_MO.getI().equals(String.valueOf(true)));
        boolean new_reward = (NEW_REWARD_MO.getI().equals(String.valueOf(true)));

        if (new_stim && new_action && new_reward) { //OK to snapshot an event!

            try {
                sensed_stimulus = Integer.valueOf((String) STIMULUS_MO.getI());
            } catch (NumberFormatException e) {
                sensed_stimulus = 0;//from  w  ww  .ja va  2s .c  om
            }

            try {
                expected_action = Integer.valueOf((String) ACTION_MO.getI());
            } catch (NumberFormatException e) {
                expected_action = 0;
            }

            try {
                reward_received = Double.valueOf((String) PREVIOUS_REWARD_MO.getI());
            } catch (NumberFormatException e) {
                reward_received = 0.0;
            }
            if (this.printEvents) {
                System.out
                        .println("Event:" + sensed_stimulus + ", " + expected_action + ", " + reward_received);
            }

            JSONObject event;
            try {
                event = new JSONObject();//A new event each time
                event.put(GlasSequenceElements.SENSED_STIMULUS.toString(), sensed_stimulus);
                event.put(GlasSequenceElements.EXPECTED_ACTION.toString(), expected_action);
                event.put(GlasSequenceElements.REWARD_RECEIVED.toString(), reward_received);

                //--------------------
                //               int s = event.getInt(GlasSequenceElements.SENSED_STIMULUS.toString());
                //               int a = event.getInt(GlasSequenceElements.EXPECTED_ACTION.toString());
                //               double r = event.getInt(GlasSequenceElements.REWARD_RECEIVED.toString());
                //----------------
                sequence.put(event);
            } catch (JSONException e) {
                e.printStackTrace();
            }

            EVENTS_SEQUENCE_MO.updateI(sequence.toString());

            //----------

            NEW_STIM_MO.updateI(String.valueOf(false));
            NEW_ACTION_MO.updateI(String.valueOf(false));
            NEW_REWARD_MO.updateI(String.valueOf(false));

        } //if enable
    } // proc()

}

From source file:eu.carrade.amaury.BallsOfSteel.BoSCommand.java

/**
 * Handles a command.//  w w  w  .  j  a  va2 s  .  co  m
 * 
 * @param sender The sender
 * @param command The executed command
 * @param label The alias used for this command
 * @param args The arguments given to the command
 * 
 * @author Amaury Carrade
 */
@SuppressWarnings("rawtypes")
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

    boolean ourCommand = false;
    for (String commandName : p.getDescription().getCommands().keySet()) {
        if (commandName.equalsIgnoreCase(command.getName())) {
            ourCommand = true;
            break;
        }
    }

    if (!ourCommand) {
        return false;
    }

    /** Team chat commands **/

    if (command.getName().equalsIgnoreCase("t")) {
        doTeamMessage(sender, command, label, args);
        return true;
    }
    if (command.getName().equalsIgnoreCase("g")) {
        doGlobalMessage(sender, command, label, args);
        return true;
    }
    if (command.getName().equalsIgnoreCase("togglechat")) {
        doToggleTeamChat(sender, command, label, args);
        return true;
    }

    if (args.length == 0) {
        help(sender, args, false);
        return true;
    }

    String subcommandName = args[0].toLowerCase();

    // First: subcommand existence.
    if (!this.commands.contains(subcommandName)) {
        try {
            Integer.valueOf(subcommandName);
            help(sender, args, false);
        } catch (NumberFormatException e) { // If the subcommand isn't a number, it's an error.
            help(sender, args, true);
        }
        return true;
    }

    // Second: is the sender allowed?
    if (!isAllowed(sender, subcommandName)) {
        unauthorized(sender, command);
        return true;
    }

    // Third: instantiation
    try {
        Class<? extends BoSCommand> cl = this.getClass();
        Class[] parametersTypes = new Class[] { CommandSender.class, Command.class, String.class,
                String[].class };

        Method doMethod = cl.getDeclaredMethod("do" + WordUtils.capitalize(subcommandName), parametersTypes);

        doMethod.invoke(this, new Object[] { sender, command, label, args });

        return true;

    } catch (NoSuchMethodException e) {
        // Unknown method => unknown subcommand.
        help(sender, args, true);
        return true;

    } catch (SecurityException | IllegalAccessException | IllegalArgumentException
            | InvocationTargetException e) {
        sender.sendMessage(i.t("cmd.errorLoad"));
        e.printStackTrace();
        return false;
    }
}

From source file:com.irccloud.android.GingerbreadImageProxy.java

private void processRequest(HttpRequest request, Socket client) throws IllegalStateException, IOException {
    if (request == null) {
        return;/*w w w.ja  v  a 2  s  .c  om*/
    }
    URL url = new URL(request.getRequestLine().getUri());

    HttpURLConnection conn = null;

    Proxy proxy = null;
    String host = null;
    int port = -1;

    if (Build.VERSION.SDK_INT < 11) {
        Context ctx = IRCCloudApplication.getInstance().getApplicationContext();
        if (ctx != null) {
            host = android.net.Proxy.getHost(ctx);
            port = android.net.Proxy.getPort(ctx);
        }
    } else {
        host = System.getProperty("http.proxyHost", null);
        try {
            port = Integer.parseInt(System.getProperty("http.proxyPort", "8080"));
        } catch (NumberFormatException e) {
            port = -1;
        }
    }

    if (host != null && host.length() > 0 && !host.equalsIgnoreCase("localhost")
            && !host.equalsIgnoreCase("127.0.0.1") && port > 0) {
        InetSocketAddress proxyAddr = new InetSocketAddress(host, port);
        proxy = new Proxy(Proxy.Type.HTTP, proxyAddr);
    }

    if (url.getProtocol().toLowerCase().equals("https")) {
        conn = (HttpsURLConnection) ((proxy != null) ? url.openConnection(proxy)
                : url.openConnection(Proxy.NO_PROXY));
    } else {
        conn = (HttpURLConnection) ((proxy != null) ? url.openConnection(proxy)
                : url.openConnection(Proxy.NO_PROXY));
    }

    conn.setConnectTimeout(30000);
    conn.setReadTimeout(30000);
    conn.setUseCaches(true);

    if (!isRunning)
        return;

    try {
        client.getOutputStream().write(
                ("HTTP/1.0 " + conn.getResponseCode() + " " + conn.getResponseMessage() + "\n\n").getBytes());

        if (conn.getResponseCode() == 200 && conn.getInputStream() != null) {
            byte[] buff = new byte[8192];
            int readBytes;
            while (isRunning && (readBytes = conn.getInputStream().read(buff, 0, buff.length)) != -1) {
                client.getOutputStream().write(buff, 0, readBytes);
            }
        }
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        client.close();
    }

    conn.disconnect();
    stop();
}