Package plugins.Freetalk.exceptions

Examples of plugins.Freetalk.exceptions.InvalidParameterException


     */
    public Board(String newName, String description, boolean hasSubscriptions) throws InvalidParameterException {
        if(newName==null || newName.length() == 0)
            throw new IllegalArgumentException("Empty board name.");
        if(!isNameValid(newName))
            throw new InvalidParameterException("Invalid board name."); // TODO: Explain what is invalid

        mID = UUID.randomUUID().toString();
        mName = newName.toLowerCase();
        mDescription = description != null ? description : "";
        mHasSubscriptions = hasSubscriptions;
View Full Code Here


        final String ownIdentityID = getMandatoryParameter(params, "OwnIdentityID");
       
        final boolean sortByMessageIndexAscending = Boolean.parseBoolean(params.get("SortByMessageIndexAscending"));
        final boolean sortByMessageDateAscending = Boolean.parseBoolean(params.get("SortByMessageDateAscending"));
        if (sortByMessageIndexAscending && sortByMessageDateAscending) {
            throw new InvalidParameterException("Only one of SortByMessageIndexAscending and SortByMessageDateAscending is allowed to be true");
        }

        int minimumMessageIndex;
        try {
            minimumMessageIndex = Integer.parseInt(params.get("MinimumMessageIndex"));
        } catch(final NumberFormatException e) {
            minimumMessageIndex = 0;
        }
        long minimumMessageDate;
        try {
            minimumMessageDate = Long.parseLong(params.get("MinimumMessageDate"));
        } catch(final NumberFormatException e) {
            minimumMessageDate = 0;
        }
        if (minimumMessageIndex > 0 && minimumMessageDate > 0) {
            throw new InvalidParameterException("MinimumMessageIndex and MinimumMessageDate must not be specified together");
        }
        final boolean includeMessageText = Boolean.parseBoolean(params.get("IncludeMessageText"));
       
        //throws exception when not found
        final SubscribedBoard board = mFreetalk.getMessageManager().getSubscription(mFreetalk.getIdentityManager().getOwnIdentity(ownIdentityID), boardName);
View Full Code Here

        final String messageIndexString = getMandatoryParameter(params, "MessageIndex");
        final int messageIndex;
        try {
            messageIndex = Integer.parseInt(messageIndexString);
        } catch(final NumberFormatException e) {
            throw new InvalidParameterException("MessageIndex ist not a number");
        }

        final boolean includeMessageText = Boolean.parseBoolean(params.get("IncludeMessageText"));

        //throws exception when not found
View Full Code Here

            final String requestUriString = params.get("RequestURI");
            final String insertUriString = params.get("InsertURI");
            if ((requestUriString == null || insertUriString == null)
                    && requestUriString != insertUriString)
            {
                throw new InvalidParameterException("RequestURI and InsertURI must be set together");
            }
           

            final WoTOwnIdentity id;
            if (requestUriString != null) {
View Full Code Here

    throws PluginNotFoundException, InvalidParameterException
    {
        try {
            final String boardName = getMandatoryParameter(params, "BoardName");
            if (!Board.isNameValid(boardName)) {
                throw new InvalidParameterException("BoardName parameter is not valid");
            }

            Board board;
            synchronized(mFreetalk.getMessageManager()) {

                try {
                    mFreetalk.getMessageManager().getBoardByName(boardName);
                    throw new InvalidParameterException("Board with same name already exists");
                } catch (final NoSuchBoardException e) {
                }

                board = mFreetalk.getMessageManager().getOrCreateBoard(boardName);
            }
View Full Code Here

                final Message parentThread;
                if(parentThreadID != null) {
                    try {
                        parentThread = mFreetalk.getMessageManager().get(parentThreadID);
                    } catch(final NoSuchMessageException e) {
                        throw new InvalidParameterException("Message specified by ParentThreadID was not found.");
                    }
                } else {
                  parentThread = null;
                }
               
                // evaluate parentMessage
                final String parentMsgId = params.get("ParentID"); // may be null
                final Message parentMessage;
                if (parentMsgId != null) {
                    try {
                        parentMessage = mFreetalk.getMessageManager().get(parentMsgId);
                    } catch(final NoSuchMessageException e) {
                        throw new InvalidParameterException("Message specified by ParentID was not found");
                    }
                } else {
                  parentMessage = null;
                }

                // evaluate targetBoards
                final String targetBoardsString = getMandatoryParameter(params, "TargetBoards");
                final String[] targetBoardsArray = targetBoardsString.split(",");
                if (targetBoardsArray.length == 0) {
                    throw new InvalidParameterException("Invalid TargetBoards parameter specified");
                }
                final Set<Board> targetBoards = new HashSet<Board>();
                for(String targetBoardName : targetBoardsArray) {
                    targetBoardName = targetBoardName.trim();
                    if (targetBoardName.length() == 0) {
                        throw new InvalidParameterException("Invalid TargetBoards parameter specified");
                    }
                    try {
                        final Board board = mFreetalk.getMessageManager().getBoardByName(targetBoardName);
                        targetBoards.add(board);
                    } catch(final NoSuchBoardException e) {
                        throw new InvalidParameterException("TargetBoard '"+targetBoardName+"' does not exist");
                    }
                }

                // evaluate replyToBoard
                final String replyToBoardName = params.get("ReplyToBoard"); // may be null
                Board replyToBoard = null;
                if (replyToBoardName != null ) {
                    try {
                        replyToBoard = mFreetalk.getMessageManager().getBoardByName(replyToBoardName);
                    } catch(final NoSuchBoardException e) {
                        throw new InvalidParameterException("ReplyToBoard '"+replyToBoardName+"' does not exist");
                    }
                    if (!targetBoards.contains(replyToBoard)) {
                        throw new InvalidParameterException("ReplyToBoard is not contained in TargetBoards");
                    }
                }

                // evaluate authorIdentity
                final String authorIdentityIDString = getMandatoryParameter(params, "AuthorIdentityID");
                final OwnIdentity authorIdentity;
                try {
                    authorIdentity = mFreetalk.getIdentityManager().getOwnIdentity(authorIdentityIDString);
                } catch(final NoSuchIdentityException e) {
                    throw new InvalidParameterException("No own identity found for AuthorIdentityID");
                }

                // evaluate attachments
                int attachmentCount;
                try {
                    attachmentCount = Integer.parseInt(params.get("FileAttachmentCount"));
                } catch(final Exception e) {
                    attachmentCount = 0;
                }
                final List<Attachment> attachments = new ArrayList<Attachment>(attachmentCount);
                for (int x=1; x <= attachmentCount; x++) {
                    final String uriString = getMandatoryParameter(params, "FileAttachmentURI."+x);
                    final String mimeTypeString = params.get("FileAttachmentMIMEType."+x);
                    final String sizeString = params.get("FileAttachmentSize."+x);
                    long fileSize;
                    FreenetURI freenetUri;
                    MimeType mimeType;
                    try {
                        freenetUri = new FreenetURI(uriString);
                        mimeType = mimeTypeString != null ? new MimeType(mimeTypeString) : null;
                        fileSize = sizeString != null ? Long.parseLong(sizeString) : -1;
                    } catch(final Exception e) {
                        throw new InvalidParameterException("Invalid FileAttachment specified ("+x+")");
                    }
                    attachments.add(new Attachment(freenetUri, mimeType, fileSize));
                }

                // evaluate messageTitle
                final String messageTitle = getMandatoryParameter(params, "Title");
                if (messageTitle.length() > Message.MAX_MESSAGE_TITLE_TEXT_LENGTH) {
                    throw new InvalidParameterException("Message title is longer than 256 characters");
                }

                // evaluate messageText
                // we expect Data containing the message text
                if (data == null) {
                    throw new InvalidParameterException("No Message text sent");
                }
                if (data.size() > Message.MAX_MESSAGE_TEXT_BYTE_LENGTH) {
                    throw new InvalidParameterException("Message text is longer than 64KB");
                }

                // convert to UTF-8
                final byte[] utf8Bytes = new byte[(int)data.size()];
                final InputStream is = data.getInputStream();
                try {
                    if (is.read(utf8Bytes) != utf8Bytes.length) {
                        throw new InvalidParameterException("Internal error reading data from Bucket");
                    }
                } finally {
                    is.close();
                }
View Full Code Here

    || !StringValidityChecker.containsNoInvalidCharacters(newNickname)
    || !StringValidityChecker.containsNoLinebreaks(newNickname)
    || !StringValidityChecker.containsNoControlCharacters(newNickname)
    || !StringValidityChecker.containsNoInvalidFormatting(newNickname)
    || newNickname.contains("@")) // Must not be allowed since we use it to generate "identity@public-key-hash" unique nicknames
      throw new InvalidParameterException("Nickname contains invalid characters"); /* TODO: Tell the user which ones are invalid!!! */
   
    if(newNickname.length() == 0) throw new InvalidParameterException("Blank nickname.");
    if(newNickname.length() > 30) throw new InvalidParameterException("Nickname is too long, the limit is 30 characters.");
  }
View Full Code Here

   * @param mValue Numeric value of this trust relationship. The allowed range is -100 to +100, including both limits. 0 counts as positive.
   * @throws InvalidParameterException if value isn't in the range
   */
  protected synchronized void setValue(byte newValue) throws InvalidParameterException {
    if(newValue < -100 || newValue > 100)
      throw new InvalidParameterException("Invalid trust value ("+mValue+").");
   
    mValue = newValue;
  }
View Full Code Here

   */
  protected synchronized void setComment(String newComment) throws InvalidParameterException {
    assert(newComment != null);
   
    if(newComment != null && newComment.length() > 256)
      throw new InvalidParameterException("Comment is too long (maximum is 256 characters).");
   
    mComment = newComment != null ? newComment : "";
  }
View Full Code Here

    }

    newID.throwIfAuthorDoesNotMatch(newAuthor);

    if(newMessageList != null && newMessageList.getAuthor() != newAuthor)
      throw new InvalidParameterException("The author of the given message list is not the author of this message: " + newURI);

    try {
      if(newFreenetURI != null)
        newMessageList.getReference(newFreenetURI);
    }
    catch(NoSuchMessageException e) {
      throw new InvalidParameterException("The given message list does not contain this message: " + newURI);
    }

    if (newBoards.isEmpty())
      throw new InvalidParameterException("No boards in message " + newURI);

    if (newBoards.size() > MAX_BOARDS_PER_MESSAGE)
      throw new InvalidParameterException("Too many boards in message " + newURI);

    if (newReplyToBoard != null && !newBoards.contains(newReplyToBoard)) {
      Logger.error(this, "Message created with replyToBoard not being in newBoards: " + newURI);
      newBoards.add(newReplyToBoard);
    }

    for(Board board : newBoards) {
      if(board instanceof SubscribedBoard)
        throw new InvalidParameterException("The boards list contains a SubscribedBoard: " + board);
    }
   
    mURI = newURI != null ? newURI.clone() : null;
    mFreenetURI = newFreenetURI != null ? newFreenetURI.clone() : null;
    mMessageList = newMessageList;
    mAuthor = newAuthor;
    mID = newID.toString();

    // There are 4 possible combinations:
    // Thread URI specified, parent URI specified: We are replying to the given message in the given thread.
    // Thread URI specified, parent URI not specified: We are replying to the given thread directly, parent URI will be set to thread URI.
    // Thread URI not specified, parent URI not specified: We are creating a new thread.
    // Thread URI not specified, parent URI specified: Invalid, we throw an exception.
    //
    // The last case is invalid because the thread URI of a message is the primary information which decides in which thread it is displayed
    // and you can link replies into multiple threads by replying to them with different thread URIs... so if there is only a parent URI and
    // no thread URI we cannot decide to which thread the message belongs because the parent might belong to multiple thread.

    if(newParentURI != null && newThreadURI == null)
      Logger.error(this, "Message with parent URI but without thread URI created: " + newURI);

    mParentURI = newParentURI != null ? newParentURI.clone() : (newThreadURI != null ? newThreadURI.clone() : null);
    mParentID = mParentURI != null ? mParentURI.getMessageID() : null;

    /* If the given thread URI is null, the message will be a thread */
    mThreadURI = newThreadURI != null ? newThreadURI.clone() : null;
    mThreadID = newThreadURI != null ? newThreadURI.getMessageID() : null;

    if(mID.equals(mParentID))
      throw new InvalidParameterException("A message cannot be parent of itself.");

    if(mID.equals(mThreadID))
      throw new InvalidParameterException("A message cannot have itself as thread.");

    mBoards = newBoards.toArray(new Board[newBoards.size()]);
    Arrays.sort(mBoards); // We use binary search in some places   
    mReplyToBoard = newReplyToBoard;
    mTitle = makeTitleValid(newTitle);

    if(newDate.after(mCreationDate)) { // mCreationDate == getFetchDate()
      Logger.warning(this, "Received bogus message date: Now = " + mCreationDate + "; message date = " + newDate + "; message=" + mURI);
      mDate = mCreationDate;
    } else {
      mDate = newDate; // TODO: Check out whether Date provides a function for getting the timezone and throw an Exception if not UTC.
    }

    mText = makeTextValid(newText);

    if (!isTitleValid(mTitle)) // TODO: Usability: Change the function to "throwIfTitleIsInvalid" so it can give a reason.
      throw new InvalidParameterException("Invalid message title in message " + newURI);

    if (!isTextValid(mText)) // TODO: Usability: Change the function to "throwIfTextIsInvalid" so it can give a reason.
      throw new InvalidParameterException("Invalid message text in message " + newURI);

    if(newAttachments != null) {
      if(newAttachments.size() > MAX_ATTACHMENTS_PER_MESSAGE)
        throw new InvalidParameterException("Too many attachments in message: " + newAttachments.size());

      mAttachments = newAttachments.toArray(new Attachment[newAttachments.size()]);
     
      for(Attachment a : mAttachments) {
        a.initializeTransient(mFreetalk);
View Full Code Here

TOP

Related Classes of plugins.Freetalk.exceptions.InvalidParameterException

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.