Example usage for java.util ListIterator hasNext

List of usage examples for java.util ListIterator hasNext

Introduction

In this page you can find the example usage for java.util ListIterator hasNext.

Prototype

boolean hasNext();

Source Link

Document

Returns true if this list iterator has more elements when traversing the list in the forward direction.

Usage

From source file:de.htwg_konstanz.ebus.wholesaler.demo.ImportXML.java

@Override
public final String execute(final HttpServletRequest request, final HttpServletResponse response,
        final ArrayList<String> errorList) {
    // get the login bean from the session
    LoginBean loginBean = (LoginBean) request.getSession(true).getAttribute(PARAM_LOGIN_BEAN);

    // ensure that the user is logged in
    if (loginBean != null && loginBean.isLoggedIn()) {
        // ensure that the user is allowed to execute this action (authorization)
        // at this time the authorization is not fully implemented.
        // -> use the "Security.RESOURCE_ALL" constant which includes all resources.
        if (Security.getInstance().isUserAllowed(loginBean.getUser(), Security.RESOURCE_ALL,
                Security.ACTION_READ)) {
            response.setContentType("text/html;charset=UTF-8");
            /*--------------------------------------
             -- Start Import/*from  w  ww  .j a v a2s .  c  om*/
             ----------------------------------------*/
            // Input Stream which has to be parsed
            InputStream is;
            // Check if the form was sended
            if (ServletFileUpload.isMultipartContent(request)) {
                try {
                    is = upload.upload(request);
                    // Server-Side check if a File was chosen or if it was an emty File
                    if (is == null) {
                        return "importxml.jsp?errormessage=File was empty!!!!!!! Or wrong file-type. only xml is allowed";
                    }

                    // Returns the valid XML document
                    ParseReportDTO report = xmlParser.validateTheXml(is);
                    org.w3c.dom.Document doc = report.getDoc();
                    if (doc == null) {
                        return "importxml.jsp?errormessage=" + report.getMessage();
                    }

                    System.out.println(doc);

                    // Reads the XML-File and saves the Products to the Database
                    ReportDTO returnval = saveProduct.readXML(doc);

                    // Writes the products which are already in database to the URL
                    String notimported = "";
                    if (returnval.getNotImported() != null) {
                        ListIterator<Integer> li = returnval.getNotImported().listIterator();
                        while (li.hasNext()) {
                            notimported = notimported + li.next() + ",";
                        }
                    }

                    if (returnval.getType()) {
                        return "importxml.jsp?infomessage=" + returnval.getMessage();
                    } else {
                        return "importxml.jsp?errormessage=" + returnval.getMessage() + "&notimported="
                                + notimported;
                    }
                    // XML File Validieeren
                } catch (FileUploadException | IOException | SAXException | ParserConfigurationException ex) {
                    Logger.getLogger(ImportXML.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // Rendering the import page
            return "importxml.jsp";
        } else {
            // authorization failed -> show error message
            errorList.add("You are not allowed to perform this action!");
            // redirect to the welcome page
            return "welcome.jsp";
        }
    } else {
        // redirect to the login page
        return "login.jsp";
    }
}

From source file:gov.nih.nci.ncicb.cadsr.common.jsp.tag.handler.AvailableValidValue.java

public List getNotListedValidValues(List questionVVList, List availableVVList) {
    List nonListedVVs = new ArrayList();
    ListIterator availableVVListIterate = availableVVList.listIterator();

    FormValidValue currFormValidValue = null;
    while (availableVVListIterate.hasNext()) {
        currFormValidValue = (FormValidValue) availableVVListIterate.next();
        //Valid Values may not be mapped to VD
        if (!questionVVList.contains(currFormValidValue)) {
            nonListedVVs.add(currFormValidValue);
        }//from w ww. j a  v a 2 s .  c om
    }
    return nonListedVVs;
}

From source file:gsilva.lirc.lircclient.config.LircConfigReader.java

private void endEntry() {
    if (program == null || entry.getProgram() == null || !program.equalsIgnoreCase(entry.getProgram()))
        return;/* w ww. j a  va  2s  . c o  m*/

    if (validator != null) {
        ListIterator<String> configs = entry.getConfigs().listIterator();
        while (configs.hasNext()) {
            String config = configs.next();

            MutableObject<String> mConfig = new MutableObject<String>(config);
            String error = validator.validateLircConfig(mConfig);
            if (error != null)
                syntaxError(error);
            configs.set(mConfig.getValue());
        }
    }

    configEntries.add(entry);
}

From source file:code.lucamarrocco.hoptoad.Backtrace.java

private final List<String> filter(final List<String> backtrace) {
    final ListIterator<String> iterator = backtrace.listIterator();
    while (iterator.hasNext()) {
        String string = iterator.next();
        if (mustBeIgnored(string)) {
            continue;
        }/*w  w w.j a v  a 2 s.  c om*/
        if (not(validBacktrace()).matches(string)) {
            string = removeDobuleDot(string);
        }
        filteredBacktrace.add(string);
    }

    return filteredBacktrace;
}

From source file:edu.cornell.mannlib.vedit.controller.BaseEditController.java

public List<Option> getSortedList(HashMap<String, Option> hashMap, List<Option> optionList, VitroRequest vreq) {

    class ListComparator implements Comparator<String> {

        Collator collator;//from  w w  w . java2 s.co  m

        public ListComparator(Collator collator) {
            this.collator = collator;
        }

        @Override
        public int compare(String str1, String str2) {
            return collator.compare(str1, str2);
        }

    }

    List<String> bodyVal = new ArrayList<String>();
    List<Option> options = new ArrayList<Option>();
    Iterator<Option> itr = optionList.iterator();
    while (itr.hasNext()) {
        Option option = itr.next();
        hashMap.put(option.getBody(), option);
        bodyVal.add(option.getBody());
    }

    Collections.sort(bodyVal, new ListComparator(vreq.getCollator()));
    ListIterator<String> itrStr = bodyVal.listIterator();
    while (itrStr.hasNext()) {
        options.add(hashMap.get(itrStr.next()));
    }
    return options;
}

From source file:org.elasticsoftware.elasticactors.geoevents.actors.Region.java

private void handle(DeRegisterInterest message) {
    State state = getState(State.class);
    ListIterator<RegisterInterest> itr = state.getListeners().listIterator();
    while (itr.hasNext()) {
        RegisterInterest registeredInterest = itr.next();
        if (registeredInterest.getActorRef().equals(message.getActorRef())
                && registeredInterest.getLocation().equals(message.getLocation())) {
            itr.remove();//  ww w . j  a  v a  2 s .c om
            if (message.isPropagate()) {
                // remove without propagating
                removeFromOtherRegions(state.getId(), registeredInterest,
                        new DeRegisterInterest(message.getActorRef(), message.getLocation(), false));
            }
        }
    }
}

From source file:airbrake.Backtrace.java

private final List<String> filter(final List<String> backtrace) {
    final ListIterator<String> iterator = backtrace.listIterator();
    while (iterator.hasNext()) {
        String string = iterator.next();
        if (mustBeIgnored(string)) {
            continue;
        }/* ww w  .  j  av a 2  s.co  m*/
        if (notValidBacktrace(string)) {
            string = removeDobuleDot(string);
        }
        filteredBacktrace.add(string);
    }

    return filteredBacktrace;
}

From source file:com.garyclayburg.persistence.repository.AccountMatcher.java

public User attachAccount(UserAccount scimAccount) {
    User matchedUser = matchAccount(scimAccount);
    User savedUser = null;/*from w w  w  . ja  va2 s.  co  m*/
    if (matchedUser != null) {
        List<UserAccount> userAccounts = matchedUser.getUserAccounts();

        if (userAccounts != null) {
            ListIterator<UserAccount> listIterator = userAccounts.listIterator();
            boolean updatedAccount = false;
            while (listIterator.hasNext()) {
                UserAccount userAccount = listIterator.next();
                String username = userAccount.getUsername();
                String accountType = userAccount.getAccountType();
                if (username != null && accountType != null) {
                    if (username.equals(scimAccount.getUsername())
                            && accountType.equals(scimAccount.getAccountType())) {
                        listIterator.set(scimAccount);
                        updatedAccount = true;
                    }
                }

            }
            if (!updatedAccount) { //add as new account for this matched user
                userAccounts.add(scimAccount);
            }
        } else { //user does not have any accounts yet.  This will be his first.
            List<UserAccount> newAccounts = new ArrayList<>();
            newAccounts.add(scimAccount);
            matchedUser.setUserAccounts(newAccounts);
        }
        savedUser = auditedUserRepo.save(matchedUser);
    }
    return savedUser;
}

From source file:brut.androlib.src.SmaliBuilder.java

private void buildFile(String fileName, DexBuilder dexBuilder) throws AndrolibException, IOException {
    File inFile = new File(mSmaliDir, fileName);
    InputStream inStream = new FileInputStream(inFile);

    if (fileName.endsWith(".smali")) {
        try {/*from   www  .  j  a va2 s.co  m*/
            if (!SmaliMod.assembleSmaliFile(inFile, dexBuilder, false, false)) {
                throw new AndrolibException("Could not smali file: " + fileName);
            }
        } catch (IOException | RecognitionException ex) {
            throw new AndrolibException(ex);
        }
        return;
    }
    if (!fileName.endsWith(".java")) {
        LOGGER.warning("Unknown file type, ignoring: " + inFile);
        return;
    }

    StringBuilder out = new StringBuilder();
    List<String> lines = IOUtils.readLines(inStream);

    if (!mDebug) {
        final String[] linesArray = lines.toArray(new String[0]);
        for (int i = 1; i < linesArray.length - 1; i++) {
            out.append(linesArray[i].split("//", 2)[1]).append('\n');
        }
    } else {
        lines.remove(lines.size() - 1);
        ListIterator<String> it = lines.listIterator(1);

        out.append(".source \"").append(inFile.getName()).append("\"\n");
        while (it.hasNext()) {
            String line = it.next().split("//", 2)[1].trim();
            if (line.isEmpty() || line.charAt(0) == '#' || line.startsWith(".source")) {
                continue;
            }
            if (line.startsWith(".method ")) {
                it.previous();
                DebugInjector.inject(it, out);
                continue;
            }

            out.append(line).append('\n');
        }
    }

    try {
        if (!SmaliMod.assembleSmaliFile(out.toString(), dexBuilder, false, false, inFile)) {
            throw new AndrolibException("Could not smali file: " + fileName);
        }
    } catch (IOException | RecognitionException ex) {
        throw new AndrolibException(ex);
    }
}

From source file:com.bluelotussoftware.apache.commons.fileupload.example.MultiContentServlet.java

/**
 * Handles the HTTP/*from  w ww.j a v  a  2s . c  o m*/
 * <code>POST</code> method.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter writer = null;
    InputStream is = null;
    FileOutputStream fos = null;

    try {
        writer = response.getWriter();
    } catch (IOException ex) {
        log(MultiContentServlet.class.getName() + "has thrown an exception: " + ex.getMessage());
    }

    boolean isMultiPart = ServletFileUpload.isMultipartContent(request);

    if (isMultiPart) {
        log("Content-Type: " + request.getContentType());
        // Create a factory for disk-based file items
        DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();

        /*
         * Set the file size limit in bytes. This should be set as an
         * initialization parameter
         */
        diskFileItemFactory.setSizeThreshold(1024 * 1024 * 10); //10MB.

        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(diskFileItemFactory);

        List items = null;

        try {
            items = upload.parseRequest(request);
        } catch (FileUploadException ex) {
            log("Could not parse request", ex);
        }

        ListIterator li = items.listIterator();

        while (li.hasNext()) {
            FileItem fileItem = (FileItem) li.next();
            if (fileItem.isFormField()) {
                if (debug) {
                    processFormField(fileItem);
                }
            } else {
                writer.print(processUploadedFile(fileItem));
            }
        }
    }

    if ("application/octet-stream".equals(request.getContentType())) {
        log("Content-Type: " + request.getContentType());
        String filename = request.getHeader("X-File-Name");

        try {
            is = request.getInputStream();
            fos = new FileOutputStream(new File(realPath + filename));
            IOUtils.copy(is, fos);
            response.setStatus(HttpServletResponse.SC_OK);
            writer.print("{success: true}");
        } catch (FileNotFoundException ex) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            writer.print("{success: false}");
            log(MultiContentServlet.class.getName() + "has thrown an exception: " + ex.getMessage());
        } catch (IOException ex) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            writer.print("{success: false}");
            log(MultiContentServlet.class.getName() + "has thrown an exception: " + ex.getMessage());
        } finally {
            try {
                fos.close();
                is.close();
            } catch (IOException ignored) {
            }
        }

        writer.flush();
        writer.close();
    }
}