Example #1
0
 private void LoadQueriesBtnMouseClicked(
     java.awt.event.MouseEvent evt) { // GEN-FIRST:event_LoadQueriesBtnMouseClicked
   // Algorithm
   /*
    * Goto queries' directory and load all queryfile.query to Combobox
    * Change local directory to repository diretory
    * List all file there
    * Try to load all file and add to combobox
    *
    *
    */
   String sQueryRepositoryPath = "/home/natuan/Documents/OntologyMysql/QueriesRepository/";
   File dir = new File(sQueryRepositoryPath);
   String[] children = dir.list();
   if (children == null) {
     // Either dir does not exist or is not a directory
   } else {
     System.out.println("list files");
     for (int i = 0; i < children.length; i++) {
       // Get filename of file or directory
       String filename = children[i];
       String sContent = ReadWholeFileToString(sQueryRepositoryPath + filename);
       queryList.add(sContent);
       QueriesCmb.addItem(filename);
       SparqlTxtArea.setText(sContent);
       //   System.out.println(filename);
     }
     QueriesCmb.setSelectedIndex(children.length - 1);
   }
 } // GEN-LAST:event_LoadQueriesBtnMouseClicked
  /**
   * Запрос с указанием параметров.
   *
   * @see MoneyDownloader#login
   * @see MoneyDownloader#password
   * @see MoneyDownloader#dateStart
   * @see MoneyDownloader#dateEnd
   */
  public final void run() {
    File file = new File(directory + "/Results.tsv");
    //        File test = new File(directory + "/tmp/result.tsv");

    try {
      if (!file.exists()) {
        file.createNewFile();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    String request = "https://rt.miran.ru?user="******"&pass="******"http://rt.miran.ru/rt/Search/Results.tsv?user="******"&pass="******"&Format=%27__Created__%2FTITLE%3A%D0%94%D0%B0%D1%82%D0%B0%27%2C%0A%27%20%20%20%3Cb%3E%3Ca%20href%3D%22%2Frt%2FTicket%2FDisplay.html%3Fid%3D__id__%22%3E__id__%3C%2Fa%3E%3C%2Fb%3E%2FTITLE%3A%23%27%2C%0A%27__Subject__%2FTITLE%3A%D0%A2%D0%B5%D0%BC%D0%B0%27%2C%0A%27__QueueName__%2FTITLE%3A%D0%9E%D1%87%D0%B5%D1%80%D0%B5%D0%B4%D1%8C%27%2C%0A%27__CustomField.%7Binteraction%20type%7D__%2FTITLE%3A%D0%A2%D0%B8%D0%BF%27%2C%0A%27__CustomField.%7Bbussines%7D__%2FTITLE%3A%D0%91%D0%B8%D0%B7%D0%BD%D0%B5%D1%81%27%2C%0A%27__CustomField.%7Bdirection%7D__%2FTITLE%3A%D0%9D%D0%B0%D0%BF%D1%80%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5%27%2C%0A%27__CustomField.%7Bservice%7D__%2FTITLE%3A%D0%A3%D1%81%D0%BB%D1%83%D0%B3%D0%B0%27%2C%0A%27__CustomField.%7BSD%20Type%7D__%2FTITLE%3A%D0%9A%D0%B0%D1%82%D0%B5%D0%B3%D0%BE%D1%80%D0%B8%D1%8F%27%2C%0A%27__CustomField.%7BSD%20Detail%7D__%2FTITLE%3A%D0%91%D0%BE%D0%BD%D1%83%D1%81%27%2C%0A%27__CustomField.%7BQA%7D__%2FTITLE%3A%D0%92%D1%8B%D0%BF%D0%BE%D0%BB%D0%BD%D0%B8%D0%BB%27&Order=DESC%7CASC%7CASC%7CASC&OrderBy=Created%7C%7C%7C&Page=1&Query=Created%20%3E%20%27"
            + dateStart
            + "%27%20AND%20Created%20%3C%20%27"
            + dateEnd
            + "%27%20AND%20Status%20%3D%20%27closed%27%20AND%20Queue%20!%3D%20%27manager%27%20AND%20Queue%20!%3D%20%27sales%27%20AND%20%27CF.%7BQA%7D%27%20%3D%20%27__CurrentUser__%27&RowsPerPage=0&SavedChartSearchId=new&SavedSearchId=";

    System.out.println(tickets);

    ListCookieHandler cookieHandler = new ListCookieHandler();
    CookieHandler.setDefault(cookieHandler);
    try {
      URL url = new URL(request);

      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.getResponseCode();

      GetMethod method = new GetMethod(tickets);
      method.addRequestHeader("Cookie", cookieHandler.getCookiez());
      method.addRequestHeader("Referer", "http://rt.miran.ru/");
      HttpClient httpClient = new HttpClient();

      httpClient.executeMethod(method);

      InputStream in = method.getResponseBodyAsStream();
      System.out.println(in.available());

    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Example #3
0
 // ���� URL ָ�����ҳ
 public String downloadFile(String url) {
   String filePath = null;
   // 1.���� HttpClinet��������
   HttpClient httpClient = new HttpClient();
   // ���� HTTP���ӳ�ʱ 5s
   httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
   // 2.���� GetMethod��������
   GetMethod getMethod = new GetMethod(url);
   // ���� get����ʱ 5s
   getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 5000);
   // �����������Դ���
   getMethod
       .getParams()
       .setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
   // 3.ִ��GET����
   try {
     int statusCode = httpClient.executeMethod(getMethod);
     // �жϷ��ʵ�״̬��
     if (statusCode != HttpStatus.SC_OK) {
       System.err.println("Method failed: " + getMethod.getStatusLine());
       filePath = null;
     }
     // 4.���� HTTP ��Ӧ����
     byte[] responseBody = getMethod.getResponseBody(); // ��ȡΪ�ֽ�����
     // ������ҳ url ���ɱ���ʱ���ļ���
     filePath =
         "temp\\" + getFileNameByUrl(url, getMethod.getResponseHeader("Content-Type").getValue());
     File file = new File(filePath);
     if (!file.getParentFile().exists()) {
       file.getParentFile().mkdir();
     }
     saveToLocal(responseBody, filePath);
   } catch (HttpException e) {
     // �����������쳣��������Э�鲻�Ի��߷��ص�����������
     System.out.println("�������http��ַ�Ƿ���ȷ");
     e.printStackTrace();
   } catch (IOException e) {
     // ���������쳣
     e.printStackTrace();
   } finally {
     // �ͷ�����
     getMethod.releaseConnection();
   }
   return filePath;
 }
Example #4
0
 /**
  * Creates an instance bound to url. If <code>acceptDeflate</code> is true then HTTP Request
  * headers will indicate to servers that this client can accept compressed documents.
  *
  * @param urlString Connect to this URL.
  * @param acceptCompress true if this client will accept compressed responses
  * @throws FileNotFoundException thrown if <code>urlString</code> is not a valid URL, or a
  *     filename which exists on the system.
  */
 public DConnect2(String urlString, boolean acceptCompress) throws FileNotFoundException {
   int ceIndex = urlString.indexOf('?');
   if (ceIndex != -1) {
     this.urlString = urlString.substring(0, ceIndex);
     String expr = urlString.substring(ceIndex);
     int selIndex = expr.indexOf('&');
     if (selIndex != -1) {
       this.projString = expr.substring(0, selIndex);
       this.selString = expr.substring(selIndex);
     } else {
       this.projString = expr;
       this.selString = "";
     }
   } else {
     this.urlString = urlString;
     this.projString = this.selString = "";
   }
   this.acceptCompress = acceptCompress;
   // capture encoded url
   this.urlStringEncoded = EscapeStrings.escapeURL(this.urlString);
   // Check out the URL to see if it is file://
   try {
     URL testURL = new URL(urlString);
     if ("file".equals(testURL.getProtocol())) {
       filePath = testURL.getPath();
       // See if .dds and .dods files exist
       File f = new File(filePath + ".dds");
       if (!f.canRead()) {
         throw new FileNotFoundException("file not readable: " + urlString + ".dds");
       }
       f = new File(filePath + ".dods");
       if (!f.canRead()) {
         throw new FileNotFoundException("file not readable: " + urlString + ".dods");
       }
     }
     /* Set the server version cause we won't get it from anywhere */
     ver = new ServerVersion(ServerVersion.DAP2_PROTOCOL_VERSION, ServerVersion.XDAP);
   } catch (DAP2Exception ex) {
     throw new FileNotFoundException("Cannot set server version");
   } catch (MalformedURLException e) {
     throw new FileNotFoundException("Malformed URL: " + urlString);
   }
 }
Example #5
0
 /**
  * Returns the DAS object from the dataset referenced by this object's URL. The DAS object is
  * referred to by appending `.das' to the end of a DODS URL.
  *
  * @return the DAS associated with the referenced dataset.
  * @throws MalformedURLException if the URL given to the constructor has an error
  * @throws IOException if an error connecting to the remote server
  * @throws ParseException if the DAS parser returned an error
  * @throws DASException on an error constructing the DAS
  * @throws DAP2Exception if an error returned by the remote server
  */
 public DAS getDAS() throws IOException, ParseException, DAP2Exception {
   DASCommand command = new DASCommand();
   if (filePath != null) { // url was file:
     File daspath = new File(filePath + ".das");
     // See if the das file exists
     if (daspath.canRead()) {
       command.process(new FileInputStream(daspath));
     }
   } else if (stream != null) {
     command.process(stream);
   } else { // assume url is remote
     try {
       openConnection(urlStringEncoded + ".das" + projString + selString, command);
     } catch (DAP2Exception de) {
       // if(de.getErrorCode() != DAP2Exception.NO_SUCH_FILE)
       // throw de;  // rethrow
     }
   }
   return command.das;
 }
Example #6
0
  /**
   * Returns the `Data object' from the dataset referenced by this object's URL given the constraint
   * expression CE. Note that the Data object is really just a DDS object with data bound to the
   * variables. The DDS will probably contain fewer variables (and those might have different types)
   * than in the DDS returned by getDDS() because that method returns the entire DDS (but without
   * any data) while this method returns only those variables listed in the projection part of the
   * constraint expression.
   *
   * <p>Note that if CE is an empty String then the entire dataset will be returned, unless a
   * "sticky" CE has been specified in the constructor.
   *
   * @param CE The constraint expression to be applied to this request by the server. This is
   *     combined with any CE given in the constructor.
   * @param statusUI the <code>StatusUI</code> object to use for GUI updates and user cancellation
   *     notification (may be null).
   * @param btf The <code>BaseTypeFactory</code> to build the member variables in the DDS with.
   * @return The <code>DataDDS</code> object that results from applying the given CE, combined with
   *     this object's sticky CE, on the referenced dataset.
   * @throws MalformedURLException if the URL given to the constructor has an error
   * @throws IOException if any error connecting to the remote server
   * @throws ParseException if the DDS parser returned an error
   * @throws DDSException on an error constructing the DDS
   * @throws DAP2Exception if any error returned by the remote server
   */
  public DataDDS getData(String CE, StatusUI statusUI, BaseTypeFactory btf)
      throws MalformedURLException, IOException, ParseException, DDSException, DAP2Exception {

    DataDDS dds = new DataDDS(ver, btf);
    DataDDSCommand command = new DataDDSCommand(dds, statusUI);
    command.setURL(urlString + "?" + CE);
    if (filePath != null) { // url is file:
      File dodspath = new File(filePath + ".dods");
      // See if the dods file exists
      if (dodspath.canRead()) {
        /* WARNING: any constraints are ignored in reading the file */
        command.process(new FileInputStream(dodspath));
      }
    } else if (stream != null) {
      command.process(stream);
    } else {
      String urls = urlStringEncoded + ".dods" + EscapeStrings.escapeURLQuery(getCompleteCE(CE));
      openConnection(urls, command);
    }
    return command.dds;
  }
Example #7
0
  public void init() throws ServletException {

    final String CONFIG_PATH = getServletContext().getRealPath("/") + "config.ini";
    final String APPLICATION_NAME = getServletContext().getServletContextName();

    BasicConfigurator.configure();

    FileInputStream config_file = null;
    File config = new File(CONFIG_PATH);

    if (config.canRead()) {
      log.debug("Parsing " + CONFIG_PATH);
      try {
        config_file = new FileInputStream(CONFIG_PATH);
      } catch (java.io.FileNotFoundException e) {
        throw new ServletException(e);
      }

      Properties config_prop = new Properties();

      try {
        config_prop.load(config_file);
      } catch (java.io.IOException e) {
        throw new ServletException(e);
      }
      this.config = config_prop;

      log.debug("Parsing finished");
    } else {
      log.fatal("Error, cannot read " + CONFIG_PATH);
    }

    log.debug("maximumRecords : " + this.config.getProperty("default_maximumRecords"));
    log.debug("srw_header_file: " + this.config.getProperty("srw_header_file"));
    log.debug("srw_diag: " + this.config.getProperty("srw_diag_file"));
    // log.debug("server_list:     " + this.config.getProperty("server_list"));

    try {
      FileReader fis =
          new FileReader(
              getServletContext().getRealPath("/") + this.config.getProperty("srw_header_file"));
      BufferedReader in1 = new BufferedReader(fis);
      fis =
          new FileReader(
              getServletContext().getRealPath("/") + this.config.getProperty("srw_footer_file"));
      BufferedReader in2 = new BufferedReader(fis);
      fis =
          new FileReader(
              getServletContext().getRealPath("/") + this.config.getProperty("srw_diag_file"));
      BufferedReader in3 = new BufferedReader(fis);
      try {
        String line = null;

        while ((line = in1.readLine()) != null) {
          this.SRW_HEADER = this.SRW_HEADER + line;
        }
        while ((line = in2.readLine()) != null) {
          this.SRW_FOOTER = this.SRW_FOOTER + line;
        }
        while ((line = in3.readLine()) != null) {
          this.SRW_DIAG = this.SRW_DIAG + line;
        }
      } finally {
        in1.close();
        in2.close();
        in3.close();
      }

    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }