Example usage for org.apache.commons.net.nntp NewGroupsOrNewsQuery NewGroupsOrNewsQuery

List of usage examples for org.apache.commons.net.nntp NewGroupsOrNewsQuery NewGroupsOrNewsQuery

Introduction

In this page you can find the example usage for org.apache.commons.net.nntp NewGroupsOrNewsQuery NewGroupsOrNewsQuery.

Prototype

public NewGroupsOrNewsQuery(Calendar date, boolean gmt) 

Source Link

Document

Creates a new query using the given time as a reference point.

Usage

From source file:me.lehrner.newsgroupsndy.presenter.tasks.UpdateGroupListAsyncTask.java

@Override
protected Boolean doInBackground(Server... servers) {
    mServerId = servers[0].getId();//from   ww  w. j  ava 2s. c o m

    String hostName = servers[0].getServerUrl();
    int lastVisitInt = servers[0].getLastVisit();

    NewsgroupInfo[] newsgroupInfos;
    ArrayList<String> groupNames = new ArrayList<>();

    try {
        NNTPClient nntpClient = new NNTPClient();
        nntpClient.connect(hostName, 119);

        Log.d(LOG_TAG, "lastVisitInt: " + lastVisitInt);

        if (lastVisitInt != 0) {
            Calendar lastVisit = Calendar.getInstance();
            lastVisit.setTimeInMillis(lastVisitInt * 1000L);

            NewGroupsOrNewsQuery query = new NewGroupsOrNewsQuery(lastVisit, false);
            newsgroupInfos = nntpClient.listNewNewsgroups(query);

            Log.d(LOG_TAG, "listNewNewsgroups");

        } else {
            newsgroupInfos = nntpClient.listNewsgroups();

            Log.d(LOG_TAG, "listNewsgroups");

        }

        nntpClient.disconnect();
    } catch (IOException e) {
        Log.d(LOG_TAG, "IOException");

        GroupPresenter groupPresenter = mGroupPresenterWeakReference.get();

        if (groupPresenter != null) {
            groupPresenter.updateNotSuccessful();
        }
        return false;
    }

    if (newsgroupInfos == null) {
        Log.d(LOG_TAG, "newsgroupInfos is null");
        return false;
    }

    for (NewsgroupInfo newsgroupInfo : newsgroupInfos) {
        groupNames.add(newsgroupInfo.getNewsgroup());
    }

    return mGroupRepository.saveGroups(mServerId, groupNames);
}

From source file:ProtocolRunner.java

private void jRadioButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton11ActionPerformed
    // list new news group for nntp:
    if(!checkValidConnection()) return;
        //  w  ww . j av  a2s  . c  o  m
    // create a query to find new news groups since yesterday
    GregorianCalendar today = new GregorianCalendar();    
    today.roll(Calendar.DAY_OF_YEAR, false);
    NewGroupsOrNewsQuery query = 
      new NewGroupsOrNewsQuery(today, false);
        
    try{
        NewsgroupInfo[] newsgroups = 
            ((NNTPClient)tcpClient).listNewNewsgroups(query);
        tcpServerResponse.append(
            ((NNTPClient)tcpClient).getReplyString() + "\r\n");
            
        if(newsgroups == null) return;
        for(int i=0; i<newsgroups.length; i++) {
            tcpServerResponse.append(newsgroups[i].getNewsgroup() + "\r\n");                
        }
        if(newsgroups.length == 0)
            tcpServerResponse.append("No new NewsGroups\r\n");            
    }catch(IOException ioex) { showError(ioex.getMessage()); }      
        
}

From source file:ProtocolRunner.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    // Single Value Dialog OK Button
        /* w w w  .j  a va 2  s.c  o  m*/
    // this method only handles tcp protocols, for udp protocols, another
    // method is used
    if(jTabbedPane1.getSelectedIndex() == 1) { // means we are in udp tab
        udpSingleValOKButton(); 
        return;
    }
        
    String valueText = singleValueField.getText();
    String valueLabel = singleValueLabel.getText();
    int selection = tcpSelectionBox.getSelectedIndex();
    try{
        if(selection == 4) { // means handling FTP
            if("New Directory:".equals(valueLabel)) { 
                // means CWD
                ((FTPClient)tcpClient).changeWorkingDirectory(valueText);
            } else if(
                "New Directory Name:".equals(valueLabel)) {
                    // means make new directory
                    ((FTPClient)tcpClient).makeDirectory(valueText);
            } else if(
                "Full path to local file:".equals(
                    valueLabel)) { 
                        // means uploading file
                        FileInputStream input = 
                            new FileInputStream(valueText);
                        ((FTPClient)tcpClient).storeFile(
                            new File(valueText).getName(), input);
                        input.close();
            } else if("Remote file:".equals(valueLabel)) { 
                // means downloading a file
                FileOutputStream output = 
                    new FileOutputStream(
                        System.getProperty("user.dir") + 
                        System.getProperty("file.separator") + 
                        valueText);
                ((FTPClient)tcpClient).retrieveFile(valueText, output);
                output.close();
            }
            tcpServerResponse.append(
                ((FTPClient)tcpClient).getReplyString() + "\r\n");
        } else if(selection == 5) { // means handling NNTP
            if("Full or part name of group:".equals(valueLabel)) {
                // means getting new news of a group
                    
                // create a query to get all new messages in this group
                // since yesterday
                GregorianCalendar today = new GregorianCalendar();    
                today.roll(Calendar.DAY_OF_YEAR, false);
                NewGroupsOrNewsQuery query = 
                  new NewGroupsOrNewsQuery(today, false);
                query.addDistribution(valueText);
                    
                String[] result = 
                    ((NNTPClient)tcpClient).listNewNews(query);
                    
                tcpServerResponse.append(
                    ((NNTPClient)tcpClient).getReplyString() + "\r\n");
                    
                // in case the NEWNEWS cmmand is disabled
                if(result == null)  return;

                for(int i=0; i<result.length; i++) {
                    tcpServerResponse.append(
                        result[i] + "\r\n");
                }
            } else if("Enter message id:".equals(valueLabel)) {
                // means getting a message based on id
                DotTerminatedMessageReader reader = 
                    (DotTerminatedMessageReader)
                    ((NNTPClient)tcpClient).retrieveArticle(
                    "<" + valueText + ">");
                tcpServerResponse.append(
                    ((NNTPClient)tcpClient).getReplyString() + "\r\n");                    
                    
                if(reader == null) return;
                    
                BufferedReader buffReader = new BufferedReader(reader);
                String lineRead;
                while((lineRead = buffReader.readLine()) != null) {
                    tcpServerResponse.append(lineRead + "\r\n");
                }
            }
        } else if(selection == 6) { // means handling pop3
            if("Enter message number:".equals(valueLabel)) { 
                // means getting a message based on number
                DotTerminatedMessageReader reader = 
                    (DotTerminatedMessageReader)                    
                    ((POP3Client)tcpClient).retrieveMessage(
                        Integer.parseInt(valueText));
                    
                tcpServerResponse.append(
                    ((POP3Client)tcpClient).getReplyString() + 
                    "\r\n");
                    
                if(reader == null) return;
                    
                BufferedReader buffReader = new BufferedReader(reader);
                String lineRead;
                while((lineRead = buffReader.readLine()) != null) {
                    tcpServerResponse.append(lineRead + "\r\n");
                }                    
            } else if("Enter message number to delete:".equals(valueLabel)){
                // means deleting a message based on id
                ((POP3Client)tcpClient).deleteMessage(
                    Integer.parseInt(valueText));
                tcpServerResponse.append(
                    ((POP3Client)tcpClient).getReplyString() + 
                    "\r\n");                    
            }
        } else if(selection == 2) { // is echo
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(
                    ((EchoTCPClient)tcpClient).getInputStream()));
                
            PrintWriter writer =
                new PrintWriter(
                    new OutputStreamWriter(
                        ((EchoTCPClient)tcpClient).getOutputStream()), true);
                
            // write to the server
            writer.println(valueText);
                
            // read from the server
            tcpServerResponse.append(reader.readLine());
                
            // streams are not closed here as there is no provision for the
            // user to send another stream of data. Thus the user has to
            // close the connection, which cleans up open streams.
        } else if(selection == 3) { // is finger
            tcpServerResponse.setText(
                ((FingerClient)tcpClient).query(false, valueText));
        } else if(selection == 9) { // is whois
            tcpServerResponse.setText(
                ((WhoisClient)tcpClient).query(valueText));
        }
    }catch(IOException ioex) { showError(ioex.getMessage()); return; }
    finally {
        singleValueField.setText("");
        singleValueDialog.setVisible(false);
    }
}