Examples of UIRequest_Output


Examples of net.sf.jeters.componentInterface.dataStructs.UIRequest_Output

            "restriction_value_" + i,
            str("restrictionValue", (i+1)),
            str("helpRestrictionValue")));
      }     

      requestList.add(new UIRequest_Output(helpString));
     
     
      UIRequest[] requestArray = new UIRequest[requestList.size()];
      requestArray = requestList.toArray(requestArray);
     
      NamedDataSet reply = uiForRequests.request(requestArray);
       
      if (reply == null) { return null; } //cancelled - #### !! return-point !! ####
       
      try { //catch MalformedURLException and NamedDataNotAvailableException
       
        createBot(conf_wikiURLs[reply.<Integer>get("url")]);
       
        Integer type = reply.get("type");       
        String name = reply.get("name");
               
        if ( type == 0 /*article*/ ){
                                   
          result = readArticle(name);
       
        }
         
        else { //one of the iterator-generating types
 
          try { //catch JWBFExceptions
           
            /* get the appropriate iterator */
           
            switch (type) {
               
              case 1: /*articles from*/
                      titleIterator = new AllPageTitles(bot, name,null,nonredirects).iterator();
                      break;
 
              case 2: /*articles starting with*/
                        titleIterator = new AllPageTitles(bot,null,name,nonredirects).iterator();
                        break;
                 
              case 3: /*category*/
                  titleIterator = new CategoryMembersSimple(bot, name).iterator();
                  break;
             
              case 4: /*backlinks*/
                  titleIterator = new BacklinkTitles(bot, name).iterator();
                  break;
 
              case 5: /*imagelinks*/
                  if (!imagePrefix.equals("")) {
                    name = imagePrefix + name;
                  }
                  titleIterator = new ImageUsageTitles(bot, name).iterator();
                  break;
   
              case 6: /*template users*/
                  if (!templatePrefix.equals("")) {
                    name = templatePrefix + name;
                  }                 
                  titleIterator = new TemplateUserTitles(bot, name).iterator();
                  break;
                 
            }
           
            /* apply the restrictions */
           
            for (int i = 0; i < restrictionsInArticleSelection;
              i ++) {
                         
              Integer restrictionType =
                reply.get("restriction_type_" + i);       
              String restrictionValue =
                reply.get("restriction_value_" + i);

              if (restrictionType > 0 &&
                  restrictionValue != null) {

                switch (restrictionType) {

                case 1: /* articles from */               

                  titleIterator =
                    new RestrictedIterator_StartFrom(
                        titleIterator,
                        restrictionValue);
                  break;

                case 2: /* articles starting with */               

                  titleIterator =
                    new RestrictedIterator_Prefix(
                        titleIterator,
                        restrictionValue);
                  break;

                }
             
              }
             
            }             
           
          } catch (VersionException ve) {
            String error = str("errorReceivingInfoWithExceptionName", "VersionException", ve.getMessage());
            uiForRequests.request(new UIRequest_Output(error));
          } catch (CookieException ce) {
            String error = str("errorReceivingInfoWithExceptionName", "CookieException", ce.getMessage());
            uiForRequests.request(new UIRequest_Output(error));             
          } catch (JwbfException je) {
            String error = str("errorReceivingInfo", je.getMessage());
            uiForRequests.request(new UIRequest_Output(error));           
          }
           
          //return the first article
           
          if (titleIterator.hasNext()) {             
            result = readArticle(titleIterator.next());             
          } else {
            result = null;
          }
           
        }       
                 
      } catch (MalformedURLException e) {
        uiForRequests.request(
            new UIRequest_Output(
                str("errorMalformedURL") + e.getMessage() ));
      } catch (NamedDataNotAvailableException e) {       
        uiForRequests.request(new UIRequest_Output(str("errorUserInput")));
      }
       
    }
   
    /* optionally show read article in browser, then return text */
 
View Full Code Here

Examples of net.sf.jeters.componentInterface.dataStructs.UIRequest_Output

             
            completed = true;
           
          } catch (MalformedURLException e) {
            uiForRequests.request(
                new UIRequest_Output(
                    str("errorMalformedURL", e.getMessage())));
          } catch (NamedDataNotAvailableException e) {       
            uiForRequests.request(new UIRequest_Output(str("errorUserInput")));
          }
         
        }
       
      }
     
    } else {

      if (text.getWikiURL() != null) {
        try {
          createBot(text.getWikiURL().toString());         
        } catch (MalformedURLException e) {
          //do nothing, user will be asked
        }
      }
     
      if (bot == null || alwaysAskForOutputWiki) {
       
        int selectedURLIndex = indexOfUrlInURLStringArray(wikiURLs, text.getWikiURL());
       
        UIRequest[] requestArray = new UIRequest[] {
            new UIRequest_Selection("url", str("mediaWikiWrite"), str("helpMediaWikiWrite"), selectedURLIndex, conf_wikiURLs)
        };
       
        NamedDataSet reply = uiForRequests.request(requestArray);
       
        try {
          createBot(conf_wikiURLs[reply.<Integer>get("url")]);
        } catch (MalformedURLException e) {
          uiForRequests.request(
              new UIRequest_Output(
                  str("errorMalformedURL", e.getMessage())));
        } catch (NamedDataNotAvailableException e) {       
          uiForRequests.request(new UIRequest_Output(str("errorUserInput")));
        }
       
      }
     
    }
     
    /* write the article to the wiki (after logging in) */
     
    if( text != null ){   
     
      /*
       * if the bot is not logged in,
       * but all information is available to log in, do so
       */
       
      if( !bot.isLoggedIn()
          && username != null && !username.equals("")
          && password != null ){         
         
        try {
          bot.login(username, password);
        } catch (ActionException e) {
          /* the "Login failed" message will be printed */         
        }
         
        if ( !bot.isLoggedIn() && !password.equals("") ) {
          uiForRequests.request(
              new UIRequest_Output(str("errorLoginFailed")) );       
       
           
      }
       
      /*
       * if bot (still) not logged in, ask for username and password
       * until the bot is logged in or the user gives up
       */
       
      boolean tryAgain = true;
   
      while( !bot.isLoggedIn() && tryAgain ){
                       
        UIRequest requestArray[] = {
          new UIRequest_String("username", str("username"),
              str("helpUsername"), username),
          new UIRequest_String("password", str("password"),
              str("helpPassword"),
              UIRequest_String.LayoutFlag.hideInput)
        };
       
        NamedDataSet reply = uiForRequests.request(requestArray);
       
        if ( reply == null ) { //cancelled
          tryAgain = false;
        }
         
        else {
           
          try {               
            username = reply.get("username");
            password = reply.get("password");
             
            try {
              bot.login(username,password);
            } catch (ActionException e) {
              /* error message will be printed */
            }
               
            /* if login failed: ask about giving up */             
            ifbot.isLoggedIn() == false ){
             
              UIRequest tryAgainRequestArray[] = { new UIRequest_Boolean("tryAgain", str("loginFailedTryAgain"), str("helpLoginFailedTryAgain")) };
                   
              try {
                tryAgain = uiForRequests.request(tryAgainRequestArray).<Boolean>get("tryAgain");
              } catch ( NamedDataNotAvailableException ndnae ){ tryAgain = false; /* no further attempts to log in */ }
                       
            }
               
          } catch (NamedDataNotAvailableException ndnae) {
            uiForRequests.request( new UIRequest_Output(str("errorGetAccountInfo")) );
            username = null;
            password = null;
          }
           
        }
View Full Code Here

Examples of net.sf.jeters.componentInterface.dataStructs.UIRequest_Output

   
    if (browserLauncher == null) {
      try {
        browserLauncher = new BrowserLauncher();
      } catch (BrowserLaunchingInitializingException e) {
        uiForRequests.request(new UIRequest_Output(str("errorBrowser")));
      } catch (UnsupportedOperatingSystemException e) {
        uiForRequests.request(
            new UIRequest_Output(str("errorBrowserOS")));
     
    }
   
    browserLauncher.openURLinBrowser(url);   
   
View Full Code Here

Examples of net.sf.jeters.componentInterface.dataStructs.UIRequest_Output

        requestArray = new UIRequest[] {
          new UIRequest_String("regex", str("searchFor"), str("helpSearchFor")),
          new UIRequest_String("rwith", str("replaceWith"), str("helpReplaceWith")),
          new UIRequest_String("summary", str("summary"), str("helpSummary"), defaultSummary),
          new UIRequest_Boolean("ask", str("ask"), str("helpAsk"), confirmChangesByDefault),
          new UIRequest_Output(str("help"))
        };
       
      } else {
       
        RegExReplacement rep = (RegExReplacement)replacements.get(0);
        requestArray = new UIRequest[] {
          new UIRequest_String("regex", str("searchFor"), str("helpSearchFor"), rep.regex),
          new UIRequest_String("rwith", str("replaceWith"), str("helpReplaceWith"), rep.rwith),
          new UIRequest_String("summary", str("summary"), str("helpSummary"), summary),
          new UIRequest_Boolean("ask", str("ask"), str("helpAsk"), rep.rating > 0),
          new UIRequest_Output(str("help"))
        };
       
      }     
     
      String regex = null;
      String rwith = null;
      Boolean ask = false;
     
      while (regex == null || rwith == null) {
     
        NamedDataSet reply = uiForRequests.request(requestArray);
               
        if (reply == null) { //user cancelled request
          return null; // #### !! return-point !! ####
        }
       
        try{       
         
          regex = reply.get("regex");
          rwith = reply.get("rwith");
          summary = reply.get("summary");
          ask = reply.get("ask");

          //test whether the regex is correct
          Pattern.compile(regex);
         
        } catch (NamedDataNotAvailableException e) {
          uiForRequests.request(
              new UIRequest_Output(str("errorUserInput")));
        } catch (PatternSyntaxException e) {
          uiForRequests.request(
              new UIRequest_Output(str("errorRegexSyntax")));
          regex = null;
        }       
         
      }
     
View Full Code Here

Examples of net.sf.jeters.componentInterface.dataStructs.UIRequest_Output

      try {       
        text = reply.get("input");
      } catch (NamedDataNotAvailableException e) {
        //input couldn't be received
        uiForRequests.request(
            new UIRequest_Output(str("errorUserInput")) );
        return null;
      }
     
    }
     
View Full Code Here

Examples of net.sf.jeters.componentInterface.dataStructs.UIRequest_Output

       
        switch( requests[requestIndex].getType() ){
         
          case Request_Output:  {
   
            UIRequest_Output outputRequest = (UIRequest_Output)request;
                       
            //create a not-editable text area (with line wrap at word boundaries)
            //that has the same color as the panel (indicating read-only) 
           
            JTextArea outputTextArea = new JTextArea(outputRequest.label);
View Full Code Here

Examples of net.sf.jeters.componentInterface.dataStructs.UIRequest_Output

      try {
       
        inputFileName = reply.get("path");
       
      } catch (NamedDataNotAvailableException ndnae) {
        uiForRequests.request( new UIRequest_Output(
            str("errorUserInput")));
      }
       
    }
         
    //read text from file
       
    try {
   
      File inputFile = new File(inputFileName);
     
      //check whether the file exists and is readable
     
      if (!inputFile.exists()) {
        uiForRequests.request( new UIRequest_Output(
            str("errorFileDoesNotExist", inputFileName)) );
      } else if (!inputFile.canRead()) {
        uiForRequests.request( new UIRequest_Output(
            str("errorFileNotReadable", inputFileName)) );
      } else {
       
        //Create a buffered reader
       
        BufferedReader reader =
          new BufferedReader( new FileReader(inputFile) );
       
        boolean readingComplete = false;
       
        while (!readingComplete) {
         
          String line = reader.readLine();
         
          if (line == null) {
            readingComplete = true;           
          } else {
           
            //add the line to the text
           
            if (text.equals("")) {
              text = line;
            } else {
              text += "\n" + line;
            }             
           
          }
         
        }
       
        reader.close();
       
        result = new PlainText(text, inputFile.getName());
       
      }
     
    } catch (IOException e) {
      uiForRequests.request( new UIRequest_Output(
          str("errorFileInput", inputFileName, e)) );
    }   
   
    /* this return statement won't be reached if the user
     * cancels the process, in which case null has already been returned
View Full Code Here

Examples of net.sf.jeters.componentInterface.dataStructs.UIRequest_Output

           
            outputFileName = reply.get("path");
           
          } catch (NamedDataNotAvailableException e) {
            uiForRequests.request(
                new UIRequest_Output(str("errorUserInput")) );
          }
       
        }
       
      }
     
      if (tryAgain) {
               
        tryAgain = false;
     
        //create the File object
       
        File outputFile = new File(outputFileName);
       
        try {               
         
          /*
           * check whether the file exists
           * (if yes: ask about overwriting)
           */
                 
          if (outputFile.exists()) {
           
            UIRequest outputRequestArray[] = {
                new UIRequest_Boolean("overwrite",
                    str("requestOverwrite"),
                    str("helpOverwrite")) };
               
            boolean overwrite =
              uiForRequests.request(outputRequestArray)
                .<Boolean>get("overwrite");
           
            if (!overwrite){
              outputFile = null;
              tryAgain = true;
            }
                   
          }
         
          if (outputFile != null) {
           
            //check whether the file is writable
           
            if (!outputFile.canWrite()) {
              uiForRequests.request(
                  new UIRequest_Output(
                      str("errorFileNotWritable")) );
            } else {
         
              outputFile.createNewFile();
               
              FileWriter writer = new FileWriter(outputFile);
             
              writer.write(text.getText());
             
              writer.close();
             
              savingComplete = true;
             
            }
             
          }
         
        } catch (IOException e) {
          uiForRequests.request(
              new UIRequest_Output(
                  str("errorFileOutput", outputFile, e)) );
        } catch (NamedDataNotAvailableException e) {
          uiForRequests.request(
              new UIRequest_Output(
                  str("invaildUserInput", e)) );
        }
       
        if (!tryAgain && !savingComplete) {
         
View Full Code Here

Examples of net.sf.jeters.componentInterface.dataStructs.UIRequest_Output

  private void outputError(String message) {
   
    UIComponent uiComponent = componentManager.getUIComponent();
   
    if (uiComponent != null) {
      uiComponent.request(new UIRequest_Output(message));
    } else {
      System.err.println(message);
    }
   
    //TODO: log
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.