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

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

Introduction

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

Prototype

public void addDistribution(String distribution) 

Source Link

Document

Add a distribution group to the query.

Usage

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. jav  a 2 s. c  om
    // 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);
    }
}