Exemplo n.º 1
0
 private void parseServerExtension(Element serverExt) throws ZimletException {
   assert (serverExt.getName().equals(ZIMLET_TAG_SERVER_EXTENSION));
   String val = serverExt.getAttribute(ZIMLET_ATTR_HAS_KEYWORD, "");
   if (val.length() > 0) {
     mKeyword = val;
   }
   val = serverExt.getAttribute(ZIMLET_ATTR_EXTENSION_CLASS, "");
   if (val.length() > 0) {
     mExtensionClass = val;
   }
   val = serverExt.getAttribute(ZIMLET_ATTR_REGEX, "");
   if (val.length() > 0) {
     mExtensionClass = ZIMLET_REGEX_EXTENSION_CLASS;
     mRegexString = val;
   }
 }
Exemplo n.º 2
0
 protected void validateElement(Element elem) throws ZimletException {
   if (elem.getName().equals(ZIMLET_TAG_CONTENT_OBJECT)) {
     mContentObject = elem.toString();
   } else if (elem.getName().equals(ZIMLET_TAG_PANEL_ITEM)) {
     mPanelItem = elem.toString();
   } else if (elem.getName().equals(ZIMLET_TAG_SERVER_EXTENSION)) {
     parseServerExtension(elem);
   } else if (elem.getName().equals(ZIMLET_TAG_SCRIPT)) {
     parseResource(elem);
   } else if (elem.getName().equals(ZIMLET_TAG_CSS)) {
     parseCss(elem);
   } else if (elem.getName().equals(ZIMLET_TAG_TARGET)) {
     mTargets.add(elem.getText());
   } else if (elem.getName().equals(ZIMLET_DISABLE_UI_UNDEPLOY)) {
     mDisableUIUndeploy = elem.getText();
   }
 }
Exemplo n.º 3
0
  public static ZFilterCondition getCondition(Element condEl) throws ServiceException {
    String name = condEl.getName();
    boolean isNegative = condEl.getAttributeBool(MailConstants.A_NEGATIVE, false);

    if (name.equals(MailConstants.E_HEADER_TEST)) {
      String header = condEl.getAttribute(MailConstants.A_HEADER);
      String s = condEl.getAttribute(MailConstants.A_STRING_COMPARISON);
      s = s.toLowerCase();
      StringComparison comparison = StringComparison.fromString(s);
      boolean caseSensitive = condEl.getAttributeBool(MailConstants.A_CASE_SENSITIVE, false);
      String value = condEl.getAttribute(MailConstants.A_VALUE);
      return new ZHeaderCondition(
          header, HeaderOp.fromStringComparison(comparison, isNegative), caseSensitive, value);
    } else if (name.equals(MailConstants.E_MIME_HEADER_TEST)) {
      String header = condEl.getAttribute(MailConstants.A_HEADER);
      String s = condEl.getAttribute(MailConstants.A_STRING_COMPARISON);
      s = s.toLowerCase();
      StringComparison comparison = StringComparison.fromString(s);
      boolean caseSensitive = condEl.getAttributeBool(MailConstants.A_CASE_SENSITIVE, false);
      String value = condEl.getAttribute(MailConstants.A_VALUE);
      return new ZMimeHeaderCondition(
          header, HeaderOp.fromStringComparison(comparison, isNegative), caseSensitive, value);
    } else if (name.equals(MailConstants.E_HEADER_EXISTS_TEST)) {
      String header = condEl.getAttribute(MailConstants.A_HEADER);
      return new ZHeaderExistsCondition(header, !isNegative);
    } else if (name.equals(MailConstants.E_SIZE_TEST)) {
      String s = condEl.getAttribute(MailConstants.A_NUMBER_COMPARISON);
      s = s.toLowerCase();
      NumberComparison comparison = NumberComparison.fromString(s);
      String size = condEl.getAttribute(MailConstants.A_SIZE);
      return new ZSizeCondition(SizeOp.fromNumberComparison(comparison, isNegative), size);
    } else if (name.equals(MailConstants.E_DATE_TEST)) {
      String s = condEl.getAttribute(MailConstants.A_DATE_COMPARISON);
      s = s.toLowerCase();
      DateComparison comparison = DateComparison.fromString(s);
      Date date = new Date(condEl.getAttributeLong(MailConstants.A_DATE) * 1000);
      return new ZDateCondition(DateOp.fromDateComparison(comparison, isNegative), date);
    } else if (name.equals(MailConstants.E_CURRENT_TIME_TEST)) {
      String s = condEl.getAttribute(MailConstants.A_DATE_COMPARISON);
      s = s.toLowerCase();
      DateComparison comparison = DateComparison.fromString(s);
      String timeStr = condEl.getAttribute(MailConstants.A_TIME);
      return new ZCurrentTimeCondition(DateOp.fromDateComparison(comparison, isNegative), timeStr);
    } else if (name.equals(MailConstants.E_BODY_TEST)) {
      String value = condEl.getAttribute(MailConstants.A_VALUE);
      BodyOp op = (isNegative ? BodyOp.NOT_CONTAINS : BodyOp.CONTAINS);
      boolean caseSensitive = condEl.getAttributeBool(MailConstants.A_CASE_SENSITIVE, false);
      return new ZBodyCondition(op, caseSensitive, value);
    } else if (name.equals(MailConstants.E_CURRENT_DAY_OF_WEEK_TEST)) {
      String value = condEl.getAttribute(MailConstants.A_VALUE);
      SimpleOp op = (isNegative ? SimpleOp.NOT_IS : SimpleOp.IS);
      return new ZCurrentDayOfWeekCondition(op, value);
    } else if (name.equals(MailConstants.E_ADDRESS_BOOK_TEST)) {
      String header = condEl.getAttribute(MailConstants.A_HEADER);
      // String folderPath = condEl.getAttribute(MailConstants.A_FOLDER_PATH);
      // TODO: support path to contacts folder
      AddressBookOp op = (isNegative ? AddressBookOp.NOT_IN : AddressBookOp.IN);
      return new ZAddressBookCondition(op, header);
    } else if (name.equals(MailConstants.E_ATTACHMENT_TEST)) {
      return new ZAttachmentExistsCondition(!isNegative);
    } else if (name.equals(MailConstants.E_INVITE_TEST)) {
      List<Element> eMethods = condEl.listElements(MailConstants.E_METHOD);
      if (eMethods.isEmpty()) {
        return new ZInviteCondition(!isNegative);
      } else {
        List<String> methods = new ArrayList<String>();
        for (Element eMethod : eMethods) {
          methods.add(eMethod.getText());
        }
        return new ZInviteCondition(!isNegative, methods);
      }
    } else if (name.equals(MailConstants.E_TRUE_TEST)) {
      return new ZTrueCondition();
    } else {
      throw ZClientException.CLIENT_ERROR("unknown filter condition: " + name, null);
    }
  }
Exemplo n.º 4
0
  public Element sendRequest(
      Element request,
      boolean requiresAuth,
      boolean noSession,
      int timeout,
      SoapProtocol resProto,
      Map<String, ElementHandler> saxHandlers,
      String uri,
      ZAuthToken authToken,
      boolean sendAcctId)
      throws ServiceException {
    OfflineAccount acct = getOfflineAccount();
    SoapHttpTransport transport = new SoapHttpTransport(uri);
    try {
      transport.setUserAgent(OfflineLC.zdesktop_name.value(), OfflineLC.getFullVersion());
      transport.setTimeout(timeout);
      if (requiresAuth) transport.setAuthToken(authToken == null ? getAuthToken() : authToken);
      transport.setRequestProtocol(SoapProtocol.Soap12);
      if (resProto != null) transport.setResponseProtocol(resProto);

      if (acct.isDebugTraceEnabled()) {
        Element elt = null;
        String pswd = null;
        if (request.getName().equals(AccountConstants.AUTH_REQUEST.getName())) {
          elt = request.getElement(AccountConstants.E_PASSWORD);
          pswd = elt.getText();
          elt.setText("*");
        }

        OfflineLog.request.debug(request);

        if (pswd != null) elt.setText(pswd);
      }

      Element response = null;
      if (saxHandlers != null) {
        response =
            transport.invoke(
                request.detach(),
                false,
                true,
                null,
                null,
                null,
                new SoapHttpTransport.SAXResponseHandler(saxHandlers));
      } else if (noSession) {
        if (sendAcctId) response = transport.invoke(request.detach(), false, true, acct.getId());
        else response = transport.invokeWithoutSession(request.detach());
      } else {
        if (mSessionId != null) transport.setSessionId(mSessionId);
        response = transport.invoke(request.detach());
      }
      if (acct.isDebugTraceEnabled() && response != null) OfflineLog.response.debug(response);

      // update sessionId if changed
      if (transport.getSessionId() != null) mSessionId = transport.getSessionId();

      return response;
    } catch (IOException e) {
      throw ServiceException.PROXY_ERROR(e, uri);
    }
  }
  /**
   * Always does a request -- caller is responsible for checking to see if this is necessary or not
   */
  private boolean bufferNextHits() throws ServiceException {
    if (atEndOfList || searchParams.getHopCount() > ZimbraSoapContext.MAX_HOP_COUNT) {
      return false;
    }

    bufferStartOffset = iterOffset;

    int chunkSizeToUse;
    if (singleShotRemoteRequest) {
      chunkSizeToUse = searchParams.getLimit();
    } else {
      chunkSizeToUse = searchParams.getLimit() * 2;
      if (chunkSizeToUse < MIN_BUFFER_CHUNK_SIZE) {
        chunkSizeToUse = MIN_BUFFER_CHUNK_SIZE;
      }
      if (chunkSizeToUse > 500) {
        chunkSizeToUse = 500;
      }
    }

    bufferEndOffset = bufferStartOffset + chunkSizeToUse;
    hitBuffer = new ArrayList<ProxiedHit>(chunkSizeToUse);

    Element searchElt = Element.create(responseProto, MailConstants.SEARCH_REQUEST);

    searchParams.setOffset(bufferStartOffset);
    searchParams.setLimit(chunkSizeToUse);
    searchParams.encodeParams(searchElt);
    if (singleShotRemoteRequest && (searchParams.getCursor() != null)) {
      Element cursorElt = searchElt.addElement(MailConstants.E_CURSOR);
      cursorElt.addAttribute(MailConstants.A_ID, searchParams.getCursor().getItemId().getId());
      if (searchParams.getCursor().getSortValue() != null) {
        cursorElt.addAttribute(MailConstants.A_SORTVAL, searchParams.getCursor().getSortValue());
      }
      if (searchParams.getCursor().getEndSortValue() != null) {
        cursorElt.addAttribute(
            MailConstants.A_ENDSORTVAL, searchParams.getCursor().getEndSortValue());
      }
    }

    // call the remote server now!
    Server targetServer = Provisioning.getInstance().get(Key.ServerBy.name, server);
    String baseurl = null;
    try {
      baseurl = URLUtil.getSoapURL(targetServer, false);
    } catch (ServiceException e) {
    }
    if (baseurl == null) {
      baseurl = URLUtil.getAdminURL(targetServer, AdminConstants.ADMIN_SERVICE_URI, true);
    }
    ProxyTarget proxy =
        new ProxyTarget(targetServer, authToken, baseurl + MailConstants.SEARCH_REQUEST.getName());
    if (mTimeout != -1) {
      proxy.setTimeouts(mTimeout);
    }

    ZimbraSoapContext zscInbound = searchParams.getRequestContext();
    ZimbraSoapContext zscProxy;
    if (zscInbound != null) {
      zscProxy = new ZimbraSoapContext(zscInbound, targetAcctId);
    } else {
      zscProxy =
          new ZimbraSoapContext(
              authToken,
              targetAcctId,
              responseProto,
              responseProto,
              searchParams.getHopCount() + 1);
    }

    long start = System.currentTimeMillis();
    Element searchResp = null;
    try {
      searchResp = DocumentHandler.proxyWithNotification(searchElt, proxy, zscProxy, zscInbound);
    } catch (SoapFaultException sfe) {
      ZimbraLog.index.warn(
          "Unable to (" + sfe + ") fetch search results from remote server " + proxy);
      atEndOfList = true;
      bufferEndOffset = iterOffset;
      return false;
    } catch (ServiceException e) {
      if (ServiceException.PROXY_ERROR.equals(e.getCode())) {
        ZimbraLog.index.warn(
            "Unable to (" + e + ") fetch search results from remote server " + proxy);
        atEndOfList = true;
        bufferEndOffset = iterOffset;
        return false;
      }
      throw e;
    } finally {
      long elapsed = System.currentTimeMillis() - start;
      ZimbraLog.index.debug(
          "Remote query took "
              + elapsed
              + "ms; URL="
              + proxy.toString()
              + "; QUERY="
              + searchElt.toString());
    }

    int hitOffset;
    if (singleShotRemoteRequest) {
      hitOffset =
          (int) searchResp.getAttributeLong(MailConstants.A_QUERY_OFFSET, bufferStartOffset);
    } else {
      hitOffset = (int) searchResp.getAttributeLong(MailConstants.A_QUERY_OFFSET);
    }
    boolean hasMore = searchResp.getAttributeBool(MailConstants.A_QUERY_MORE);

    assert (bufferStartOffset == hitOffset);

    SortBy sb = getSortBy();
    // put these hits into our buffer!
    int bufferIdx = 0;
    int stop = bufferEndOffset - bufferStartOffset;
    for (Iterator<Element> iter = searchResp.elementIterator();
        iter.hasNext() && bufferIdx < stop; ) {
      Element el = iter.next();
      if (el.getName().equalsIgnoreCase(MailConstants.E_INFO)) {
        for (Element info : el.listElements()) {
          queryInfo.add(new ProxiedQueryInfo(info));
        }
      } else {
        if (sb != null
            && ((SortBy.NAME_LOCALIZED_ASC.equals(sb))
                || (SortBy.NAME_LOCALIZED_DESC.equals(sb)))) {
          hitBuffer.add(
              bufferIdx++,
              new ProxiedContactHit(this, el, el.getAttribute(MailConstants.A_FILE_AS_STR)));
        } else {
          hitBuffer.add(
              bufferIdx++, new ProxiedHit(this, el, el.getAttribute(MailConstants.A_SORT_FIELD)));
        }
      }
    }

    // are we at the end of the line here?
    if (bufferIdx < stop || !hasMore) {
      // update the buffer-end-pointer
      bufferEndOffset = bufferStartOffset + bufferIdx;

      if (hasMore) {
        assert (!hasMore); // if bufferIdx < stop then !hasMore should be set...server bug!
      }
      atEndOfList = true;
    } else {
      assert (bufferEndOffset == bufferStartOffset + bufferIdx);
    }
    if (singleShotRemoteRequest) {
      atEndOfList = true;
    }

    assert (bufferStartOffset <= iterOffset);

    // OK, we were successful if we managed to buffer the current hit
    return (bufferEndOffset > iterOffset);
  }