Package org.rssowl.core.connection

Examples of org.rssowl.core.connection.IProtocolHandler


   * Exception.
   */
  public static String getGoogleAuthToken(String email, String pw, IProgressMonitor monitor) throws ConnectionException {
    try {
      URI uri = new URI(GOOGLE_LOGIN);
      IProtocolHandler handler = Owl.getConnectionService().getHandler(uri);
      if (handler != null) {

        /* Google Specific Headers */
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("accountType", "GOOGLE"); //$NON-NLS-1$ //$NON-NLS-2$
        headers.put("Email", email); //$NON-NLS-1$
        headers.put("Passwd", pw); //$NON-NLS-1$
        headers.put("service", "reader"); //$NON-NLS-1$ //$NON-NLS-2$
        headers.put("source", "RSSOwl.org-RSSOwl-" + Activator.getDefault().getVersion()); //$NON-NLS-1$ //$NON-NLS-2$

        Map<Object, Object> properties = new HashMap<Object, Object>();
        properties.put(IConnectionPropertyConstants.HEADERS, headers);
        properties.put(IConnectionPropertyConstants.POST, Boolean.TRUE);

        BufferedReader reader = null;
        try {
          InputStream inS = handler.openStream(uri, monitor, properties);
          reader = new BufferedReader(new InputStreamReader(inS));
          String line;
          while (!monitor.isCanceled() && (line = reader.readLine()) != null) {
            if (line.startsWith(AUTH_IDENTIFIER))
              return line.substring(AUTH_IDENTIFIER.length());
View Full Code Here


        if (feedInput.getMark() instanceof IBookMark) {
          final IBookMark bm = (IBookMark) feedInput.getMark();
          final URI feedLink = bm.getFeedLinkReference().getLink();

          try {
            final IProtocolHandler handler = Owl.getConnectionService().getHandler(feedLink);
            if (handler instanceof org.rssowl.core.internal.connection.DefaultProtocolHandler) {
              Job downloadJob = new Job(Messages.ViewFeedSourceAction_DOWNLOAD_FEED_SOURCE) {
                @Override
                protected IStatus run(IProgressMonitor monitor) {
                  monitor.beginTask(bm.getName(), IProgressMonitor.UNKNOWN);

                  File tmpFile = null;
                  InputStream in = null;
                  FileOutputStream out = null;
                  boolean canceled = false;
                  Exception error = null;
                  try {
                    tmpFile = File.createTempFile("feed", ".txt"); //$NON-NLS-1$ //$NON-NLS-2$
                    tmpFile.deleteOnExit();

                    byte[] buffer = new byte[8192];

                    in = handler.openStream(feedLink, monitor, null);
                    out = new FileOutputStream(tmpFile);
                    while (true) {

                      /* Check for Cancellation and Shutdown */
                      if (monitor.isCanceled() || org.rssowl.ui.internal.Controller.getDefault().isShuttingDown()) {
View Full Code Here

    job.setName(NLS.bind(Messages.DownloadService_DOWNLOADING, downloadFileName));
    job.setProperty(IProgressConstants.ICON_PROPERTY, OwlUI.getAttachmentImage(downloadFileName, attachment.getType()));

    int bytesConsumed = 0;
    try {
      IProtocolHandler handler = Owl.getConnectionService().getHandler(link);
      if (handler != null) {
        Map<Object, Object> properties = new HashMap<Object, Object>();
        properties.put(IConnectionPropertyConstants.CON_TIMEOUT, DEFAULT_CON_TIMEOUT);

        /* Check for Cancellation and Shutdown */
        if (monitor.isCanceled() || Controller.getDefault().isShuttingDown())
          return Status.CANCEL_STATUS;

        /* Initialize Fields */
        long bytesPerSecond = 0;
        long lastTaskNameUpdate = 0;
        long lastBytesCheck = 0;
        int length = attachment.getLength();
        byte[] buffer = new byte[8192];

        /* Begin Task */
        monitor.beginTask(formatTask(bytesConsumed, length, -1), length > 0 ? length : DEFAULT_TASK_LENGTH);

        /* First Download to a temporary File */
        int contentLength = length;
        InputStream in = null;
        FileOutputStream out = null;
        File partFile = new File(folder, downloadFileName + ".part"); //$NON-NLS-1$
        boolean canceled = false;
        Exception error = null;
        try {

          /* Open Stream */
          in = handler.openStream(link, monitor, properties);

          /* Obtain real Content Length from Stream if available */
          if (in instanceof HttpConnectionInputStream) {
            int len = ((HttpConnectionInputStream) in).getContentLength();
            if (len > 0)
View Full Code Here

            /* Return if dialog closed */
            if (monitor.isCanceled() || getShell().isDisposed() || fBrowser.getControl().isDisposed())
              return;

            /* Retrieve Stream */
            IProtocolHandler handler = Owl.getConnectionService().getHandler(feed.getLink());
            InputStream inS = handler.openStream(feed.getLink(), monitor, null);

            /* Return if dialog closed */
            if (monitor.isCanceled() || getShell().isDisposed() || fBrowser.getControl().isDisposed())
              return;

View Full Code Here

   */
  @Test
  public void testHttpConnectionInputStream() throws Exception {
    IConnectionService conManager = Owl.getConnectionService();
    URI url = new URI("http://www.rssowl.org/favicon.ico");
    IProtocolHandler handler = conManager.getHandler(url);
    InputStream stream = handler.openStream(url, null, null);
    if (stream instanceof HttpConnectionInputStream) {
      HttpConnectionInputStream inS = (HttpConnectionInputStream) stream;
      assertTrue(inS.getContentLength() > 0);
      assertNotNull(inS.getIfModifiedSince());
      assertNotNull(inS.getIfNoneMatch());
View Full Code Here

  public void testGoogleReaderSync() throws Exception {
    String authToken = SyncUtils.getGoogleAuthToken("rssowl@mailinator.com", "rssowl.org", new NullProgressMonitor());
    assertNotNull(authToken);

    URI uri = URI.create("https://www.google.com/reader/subscriptions/export");
    IProtocolHandler handler = Owl.getConnectionService().getHandler(uri);

    Map<Object, Object> properties = new HashMap<Object, Object>();

    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Authorization", SyncUtils.getGoogleAuthorizationHeader(authToken)); //$NON-NLS-1$
    properties.put(IConnectionPropertyConstants.HEADERS, headers);

    InputStream inS = handler.openStream(uri, new NullProgressMonitor(), properties);

    List<? extends IEntity> elements = Owl.getInterpreter().importFrom(inS);
    assertTrue(!elements.isEmpty());
  }
View Full Code Here

        in.close();
    }
  }

  private InputStream openStream(URI link, IProgressMonitor monitor, int timeout, boolean setAcceptLanguage, boolean isLocalized, String authToken) throws ConnectionException {
    IProtocolHandler handler = Owl.getConnectionService().getHandler(link);

    Map<Object, Object> properties = new HashMap<Object, Object>();
    properties.put(IConnectionPropertyConstants.CON_TIMEOUT, timeout);

    /* Set Authorization Header if required */
    if (StringUtils.isSet(authToken)) {
      Map<String, String> headers = new HashMap<String, String>();
      headers.put("Authorization", SyncUtils.getGoogleAuthorizationHeader(authToken)); //$NON-NLS-1$
      properties.put(IConnectionPropertyConstants.HEADERS, headers);
    }

    /* Set the Accept-Language Header */
    if (setAcceptLanguage) {
      StringBuilder languageHeader = new StringBuilder();
      String clientLanguage = Locale.getDefault().getLanguage();

      /* Set Both English and Client Locale */
      if (!isLocalized) {
        languageHeader.append(DEFAULT_LANGUAGE);
        if (StringUtils.isSet(clientLanguage) && !DEFAULT_LANGUAGE.equals(clientLanguage))
          languageHeader.append(",").append(clientLanguage); //$NON-NLS-1$
      }

      /* Only set Client Locale */
      else {
        if (StringUtils.isSet(clientLanguage))
          languageHeader.append(clientLanguage);
        else
          languageHeader.append(DEFAULT_LANGUAGE);
      }

      properties.put(IConnectionPropertyConstants.ACCEPT_LANGUAGE, languageHeader.toString());
    }

    return handler.openStream(link, monitor, properties);
  }
View Full Code Here

  /*
   * @see org.rssowl.core.connection.IConnectionService#getLabel(java.net.URI)
   */
  public String getLabel(URI link) throws ConnectionException {
    String protocol = link.getScheme();
    IProtocolHandler handler = fProtocolHandler.get(protocol);

    /* Handler present */
    if (handler != null)
      return handler.getLabel(link);

    /* No Handler present */
    throw new UnknownFeedException(Activator.getDefault().createErrorStatus("Could not find a matching ProtocolHandler for: " + protocol, null)); //$NON-NLS-1$
  }
View Full Code Here

   * @see org.rssowl.core.connection.IConnectionService#reload(java.net.URI,
   * org.eclipse.core.runtime.IProgressMonitor, java.util.Map)
   */
  public Pair<IFeed, IConditionalGet> reload(URI link, IProgressMonitor monitor, Map<Object, Object> properties) throws CoreException {
    String protocol = link.getScheme();
    IProtocolHandler handler = fProtocolHandler.get(protocol);

    /* Make sure to provide a Monitor */
    if (monitor == null)
      monitor = new NullProgressMonitor();

    /* Handler present */
    if (handler != null)
      return handler.reload(link, monitor, properties);

    /* No Handler present */
    throw new UnknownFeedException(Activator.getDefault().createErrorStatus("Could not find a matching ProtocolHandler for: " + protocol, null)); //$NON-NLS-1$
  }
View Full Code Here

  /*
   * @see org.rssowl.core.connection.IConnectionService#getFeedIcon(java.net.URI)
   */
  public byte[] getFeedIcon(URI link) throws ConnectionException {
    String protocol = link.getScheme();
    IProtocolHandler handler = fProtocolHandler.get(protocol);

    /* Handler present */
    if (handler != null)
      return handler.getFeedIcon(link);

    /* No Handler present */
    throw new UnknownFeedException(Activator.getDefault().createErrorStatus("Could not find a matching ProtocolHandler for: " + protocol, null)); //$NON-NLS-1$
  }
View Full Code Here

TOP

Related Classes of org.rssowl.core.connection.IProtocolHandler

Copyright © 2018 www.massapicom. 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.