Example usage for org.apache.commons.lang StringUtils left

List of usage examples for org.apache.commons.lang StringUtils left

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils left.

Prototype

public static String left(String str, int len) 

Source Link

Document

Gets the leftmost len characters of a String.

Usage

From source file:io.seldon.api.resource.service.UserService.java

private static void truncateUsername(User user) {
    final String username = user.getUsername();
    final String truncated = StringUtils.left(username, USERNAME_MAX_LENGTH);
    user.setUsername(truncated);// ww w  .  j  a v  a 2  s.  c o  m
}

From source file:com.evolveum.midpoint.init.InitialDataImport.java

private int getNumberFromName(File file) {
    String name = file.getName();
    String number = StringUtils.left(name, 3);
    if (number.matches("[\\d]+")) {
        return Integer.parseInt(number);
    }/*w  w  w . ja v a  2 s .  c om*/
    return 0;
}

From source file:com.funambol.foundation.items.dao.PIMNoteDAOTest.java

/**
 * Add a note whose body is bigger than the max size of the body.
 *//*from  w  ww  . jav a2 s .  co  m*/
public void testAddItemBigContent() throws Throwable {

    int index = 100;

    Note note = new Note();
    note.setSubject(new Property(createBigString(BIG_SUBJECT_SIZE, "subject ")));
    note.setTextDescription(new Property(createBigString(BIG_BODY_SIZE, "body ")));
    note.setCategories(new Property(createBigString(BIG_CATEGORIES_SIZE, "cat,")));
    note.setFolder(new Property(createBigString(BIG_FOLDER_SIZE, "folder\\")));
    note.setColor(new Property("1"));
    note.setHeight(new Property("11"));
    note.setWidth(new Property("22"));
    note.setTop(new Property("110"));
    note.setLeft(new Property("220"));

    String uid = Long.toString(index);
    NoteWrapper nw = new NoteWrapper(uid, USER_ID, note);
    nw.setStatus('N');

    pimNoteDao.addItem(nw);
    NoteWrapper result = pimNoteDao.getItem(uid);

    NoteWrapper expected = nw;
    Note expectedNote = nw.getNote();

    String expectedSubject = StringUtils.left(expectedNote.getSubject().getPropertyValueAsString(),
            PIMNoteDAO.SQL_SUBJECT_DIM);
    String expectedTextDescription = StringUtils.left(
            expectedNote.getTextDescription().getPropertyValueAsString(), PIMNoteDAO.SQL_TEXTDESCRIPTION_DIM);

    String expectedFolder = (String) PrivateAccessor.invoke(pimNoteDao, "truncateFolderField",
            new Class[] { String.class, int.class },
            new Object[] { expectedNote.getFolder().getPropertyValueAsString(), PIMNoteDAO.SQL_FOLDER_DIM });
    String expectedCategories = (String) PrivateAccessor.invoke(pimNoteDao, "truncateCategoriesField",
            new Class[] { String.class, int.class }, new Object[] {
                    expectedNote.getCategories().getPropertyValueAsString(), PIMNoteDAO.SQL_CATEGORIES_DIM });

    expectedNote.setSubject(new Property(expectedSubject));
    expectedNote.setTextDescription(new Property(expectedTextDescription));
    expectedNote.setFolder(new Property(expectedFolder));
    expectedNote.setCategories(new Property(expectedCategories));

    ITable expectedItems = new RowFilterTable(getUserDBDataSet().getTable(TABLE_FNBL_PIM_NOTE),
            getRowFilter(USER_ID, new char[] { 'N', 'U' }));
    assertEquals(expectedItems.getRowCount() + 1, pimNoteDao.getAllItems().size());

    NoteWrapperAsserts.assertEquals(expected, result);
}

From source file:io.seldon.api.resource.service.ItemService.java

private static void truncateItemName(ItemBean itemBean, int newLength) {
    final String name = itemBean.getName();
    final String truncatedName = StringUtils.left(name, newLength);
    logger.info("Truncating itemBean name '" + name + "' to '" + truncatedName + "'");
    itemBean.setName(truncatedName);//from   w  w  w.j a v a  2 s.  co m
}

From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java

/**
 * Adds file data object metadata of an item to the database.
 * @param fdow//from  w w w . jav a 2  s.  c o m
 * @throws com.funambol.foundation.exception.DAOException
 */
public String addItem(FileDataObjectWrapper fdow) throws DAOException {

    Connection con = null;
    PreparedStatement ps = null;

    try {

        // Looks up the data source when the first connection is created
        con = getUserDataSource().getRoutedConnection(userId);

        if (fdow.getId() == null) {
            throw new DAOException("Unable to add item: id should be already defined");
        }

        ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_FILE_DATA_OBJECT);

        int k = 1;

        ps.setLong(k++, Long.parseLong(fdow.getId()));

        ps.setString(k++, userId);

        ps.setString(k++, sourceURI);

        Timestamp currentTime = new Timestamp(System.currentTimeMillis());

        Timestamp lastUpdate = fdow.getLastUpdate();
        if (lastUpdate == null) {
            lastUpdate = currentTime;
        }
        ps.setLong(k++, lastUpdate.getTime());

        ps.setString(k++, String.valueOf(SyncItemState.NEW));

        FileDataObject fdo = fdow.getFileDataObject();

        ps.setString(k++, String.valueOf(fdo.getUploadStatus()));

        String fileName = fdow.getLocalName();
        if (fileName == null || fileName.length() == 0) {
            ps.setNull(k++, Types.VARCHAR);
        } else {
            ps.setString(k++, StringUtils.left(fileName, SQL_LOCAL_NAME_DIM));
        }

        Long crc = Long.valueOf(fdow.getFileDataObject().getCrc());
        ps.setLong(k++, crc);

        ps.setString(k++, StringUtils.left(fdo.getName(), SQL_TRUE_NAME_DIM));

        MediaUtils.setFDODates(fdo, fdo.getCreated(), fdo.getModified());

        Timestamp created = timestamp(fdo.getCreated());
        if (created != null) {
            ps.setTimestamp(k++, created);
        } else {
            ps.setTimestamp(k++, currentTime);
        }

        Timestamp modified = timestamp(fdo.getModified());
        if (modified != null) {
            ps.setTimestamp(k++, modified);
        } else {
            ps.setTimestamp(k++, currentTime);
        }

        ps.setTimestamp(k++, timestamp(fdo.getAccessed()));

        ps.setString(k++, fdo.isHidden() ? ONE : NIL);
        ps.setString(k++, fdo.isSystem() ? ONE : NIL);
        ps.setString(k++, fdo.isArchived() ? ONE : NIL);
        ps.setString(k++, fdo.isDeleted() ? ONE : NIL);
        ps.setString(k++, fdo.isWritable() ? ONE : NIL);
        ps.setString(k++, fdo.isReadable() ? ONE : NIL);
        ps.setString(k++, fdo.isExecutable() ? ONE : NIL);

        if (fdo.getContentType() != null) {
            ps.setString(k++, StringUtils.left(fdo.getContentType(), SQL_CTTYPE_DIM));
        } else {
            ps.setNull(k++, Types.VARCHAR);
        }

        if (fdo.getSize() == null) {
            ps.setNull(k++, Types.BIGINT);
        } else {
            ps.setLong(k++, fdo.getSize());
        }

        if (fdow.getSizeOnStorage() == null) {
            ps.setNull(k++, Types.BIGINT);
        } else {
            ps.setLong(k++, fdow.getSizeOnStorage());
        }

        ps.executeUpdate();
        DBTools.close(null, ps, null);

        // stores file data object properties
        addProperties(fdow);

    } catch (Exception e) {
        throw new DAOException("Error adding file data object.", e);
    } finally {
        DBTools.close(con, ps, null);
    }
    return fdow.getId();
}

From source file:com.skratchdot.electribe.model.esx.provider.SongItemProvider.java

@Override
protected Command createSetCommand(EditingDomain domain, EObject owner, EStructuralFeature feature,
        Object value) {/*w w  w.  ja  va2s  .  c  o m*/

    // When setting name, only allow 8 characters
    if (feature == EsxPackage.Literals.SONG__NAME) {
        value = StringUtils.left((String) value, 8);
    }
    return super.createSetCommand(domain, owner, feature, value);
}

From source file:com.funambol.foundation.items.dao.PIMNoteDAO.java

public String updateItem(NoteWrapper nw) throws DAOException {

    Connection con = null;/*from   ww w .  j  av a  2  s  .  c o  m*/
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {

        //
        // Note fields
        //
        Note note = nw.getNote();

        StringBuilder updateQuery = new StringBuilder();

        updateQuery.append(SQL_UPDATE_FNBL_PIM_NOTE_BEGIN);

        updateQuery.append(SQL_FIELD_LAST_UPDATE + SQL_EQUALS_QUESTIONMARK_COMMA);
        updateQuery.append(SQL_FIELD_STATUS + SQL_EQUALS_QUESTIONMARK_COMMA);

        String subject = note.getSubject().getPropertyValueAsString();
        if (subject != null) {
            updateQuery.append(SQL_FIELD_SUBJECT + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String textDescription = note.getTextDescription().getPropertyValueAsString();
        if (textDescription != null) {
            updateQuery.append(SQL_FIELD_TEXTDESCRIPTION + SQL_EQUALS_QUESTIONMARK_COMMA);

            updateQuery.append(SQL_FIELD_CRC + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String categories = note.getCategories().getPropertyValueAsString();
        if (categories != null) {
            updateQuery.append(SQL_FIELD_CATEGORIES + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String folder = note.getFolder().getPropertyValueAsString();
        if (folder != null) {
            updateQuery.append(SQL_FIELD_FOLDER + SQL_EQUALS_QUESTIONMARK_COMMA);
        }
        String color = note.getColor().getPropertyValueAsString();
        if (color != null) {
            updateQuery.append(SQL_FIELD_COLOR + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String height = note.getHeight().getPropertyValueAsString();
        if (height != null) {
            updateQuery.append(SQL_FIELD_HEIGHT + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String width = note.getWidth().getPropertyValueAsString();
        if (width != null) {
            updateQuery.append(SQL_FIELD_WIDTH + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String top = note.getTop().getPropertyValueAsString();
        if (top != null) {
            updateQuery.append(SQL_FIELD_TOP + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String left = note.getLeft().getPropertyValueAsString();
        if (left != null) {
            updateQuery.append(SQL_FIELD_LEFT_MARGIN + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (updateQuery.charAt(updateQuery.length() - 2) == ',') {
            updateQuery.deleteCharAt(updateQuery.length() - 2);
        }

        updateQuery.append(SQL_UPDATE_FNBL_PIM_NOTE_END);

        // Looks up the data source when the first connection is created
        con = getUserDataSource().getRoutedConnection(userId);

        ps = con.prepareStatement(updateQuery.toString());

        int k = 1;

        //
        // last update
        //
        Timestamp lastUpdate = (nw.getLastUpdate() == null) ? new Timestamp(System.currentTimeMillis())
                : nw.getLastUpdate();
        ps.setLong(k++, lastUpdate.getTime());

        //
        // status
        //
        ps.setString(k++, String.valueOf(Def.PIM_STATE_UPDATED));

        //
        // subject
        //
        if (subject != null) {
            ps.setString(k++, StringUtils.left(subject, SQL_SUBJECT_DIM));
        }

        //
        // textDescription
        //
        if (textDescription != null) {
            textDescription = textDescription.replace('\0', ' ');
            String truncatedTextDescription = StringUtils.left(textDescription, SQL_TEXTDESCRIPTION_DIM);

            ps.setString(k++, truncatedTextDescription);
            ps.setLong(k++, calculateCrc(truncatedTextDescription));
        }

        //
        // categories
        //
        if (categories != null) {
            ps.setString(k++, truncateCategoriesField(categories, SQL_CATEGORIES_DIM));
        }

        //
        // folder
        //
        if (folder != null) {
            ps.setString(k++, truncateFolderField(folder, SQL_FOLDER_DIM));
        }

        //
        // color
        //
        if (color != null) {
            if (color.length() == 0) {
                ps.setNull(k++, Types.INTEGER);
            } else {
                ps.setInt(k++, Integer.parseInt(color));
            }
        }

        //
        // height
        //
        if (height != null) {
            if (height.length() == 0) {
                ps.setNull(k++, Types.INTEGER);
            } else {
                ps.setInt(k++, Integer.parseInt(height));
            }
        }

        //
        // width
        //
        if (width != null) {
            if (width.length() == 0) {
                ps.setNull(k++, Types.INTEGER);
            } else {
                ps.setInt(k++, Integer.parseInt(width));
            }
        }

        //
        // top
        //
        if (top != null) {
            if (top.length() == 0) {
                ps.setNull(k++, Types.INTEGER);
            } else {
                ps.setInt(k++, Integer.parseInt(top));
            }
        }

        //
        // left
        //
        if (left != null) {
            if (left.length() == 0) {
                ps.setNull(k++, Types.INTEGER);
            } else {
                ps.setInt(k++, Integer.parseInt(left));
            }
        }

        //
        // id
        //
        ps.setLong(k++, Long.parseLong(nw.getId()));
        //
        // userId
        //
        ps.setString(k++, userId);

        ps.executeUpdate();

        DBTools.close(null, ps, null);
    } catch (Exception e) {
        throw new DAOException("Error updating note.", e);
    } finally {
        DBTools.close(con, ps, rs);
    }

    return nw.getId();
}

From source file:com.bluexml.side.Integration.alfresco.xforms.webscript.XFormsWork.java

/**
 * Finds the node (of the given datatype) that has the given id value on the
 * identifier property//from w  w  w .j a  v  a  2s  .c  o m
 * and formats its noderef id, label and qname into a string that has the
 * format
 * "id{SEPARATOR}label{SEPARATOR}prefixed_qname".
 * 
 * @param datatype
 *            a prefixed content type, e.g. "cm:person"
 * @param identifier
 *            the local name of a property present in the datatype's
 *            definition, e.g. "userName"
 * @param format
 *            the pattern for formatting the label. e.g.
 *            "format=firstName@lastName@{ (}@email@{)}"
 * @param labelLength
 *            the length at which to truncate the label that will be
 *            computed. If "0", no
 *            truncation happens.
 * @param idValue
 *            the value which, when found on the identifier property, elects
 *            the node as the one
 *            being looked for. e.g. "johndoe"
 * @return <code>null</code> if either no identifier property was found or
 *         no node was found
 *         with the id value on that property. Otherwise, returns the info
 *         string for the node,
 *         e.g."workspace://SpacesStore/ca151555-95e0-4361-aa4e-0050adb7027d{::}John Doe (johndoe@email.com){::}cm:person"
 */
private String resolveObjectInfo(String datatype, String identifier, String format, String labelLength,
        String idValue, boolean includeSystemProperties) {
    // get the identifier property's qname
    QName idQName = resolveIdentifierQName(identifier, datatype);
    if (idQName == null) {
        return null;
    }

    // get all objects of the datatype
    ResultSet luceneResultSet = getResultSet(datatype, new ArrayList<String>(), 0, null,
            includeSystemProperties);
    int nbResults = luceneResultSet.length();
    NodeRef electedNode = null;

    // test each object against the id value
    for (int i = 0; i < nbResults; i++) {
        NodeRef nodeRef = luceneResultSet.getNodeRef(i);
        String nodeValue = resolveIdentifierValue(nodeRef, idQName);
        if (StringUtils.equals(nodeValue, idValue)) {
            electedNode = nodeRef;
            break;
        }
    }

    luceneResultSet.close();

    // build the label for the elected node
    if (electedNode == null) {
        return null;
    }
    // include system properties as this function is likely to be used for system types
    String label = dataLayer.getLabelForNode(electedNode, format, true);

    String trimmedLabel = label;
    try {
        int length = Integer.parseInt(labelLength);
        trimmedLabel = StringUtils.left(label, length);
    } catch (Exception e) {
        // nothing to do, the trimmed label remains the same as the initial label
    }
    QName qName = serviceRegistry.getNodeService().getType(electedNode);

    String objectInfo = electedNode.toString() + WEBSCRIPT_SEPARATOR + trimmedLabel + WEBSCRIPT_SEPARATOR
            + qName.toPrefixString();
    return objectInfo;
}

From source file:com.funambol.foundation.items.dao.PIMCalendarDAO.java

/**
 * Adds a calendar. If necessary, a new ID is generated and set in the
 * CalendarWrapper./*from ww  w.  j ava  2s  .c om*/
 *
 * @param c as a CalendarWrapper object, usually without an ID set.
 * @throws DAOException
 *
 * @see CalendarWrapper
 */
public void addItem(CalendarWrapper cw) throws DAOException {

    if (log.isTraceEnabled()) {
        log.trace("PIMCalendarDAO addItem begin");
    }

    Connection con = null;
    PreparedStatement ps = null;

    long id = 0;
    String allDay = null;
    String body = null;
    Short busyStatus = null;
    String categories = null;
    String companies = null;
    int duration = 0;
    Date dend = null;
    short importance = 0;
    String location = null;
    Short meetingStatus = null;
    String mileage = null;
    Date replyTime = null;
    short sensitivity = 0;
    Date dstart = null;
    String subject = null;
    int interval = 0;
    short monthOfYear = 0;
    short dayOfMonth = 0;
    String dayOfWeekMask = null;
    short instance = 0;
    String startDatePattern = null;
    String endDatePattern = null;
    Reminder reminder = null;
    RecurrencePattern rp = null;
    short recurrenceType = -1;
    String sId = null;
    int occurrences = -1;
    String folder = null;
    String dstartTimeZone = null;
    String dendTimeZone = null;
    String reminderTimeZone = null;
    Date completed = null;
    short percentComplete = -1;

    Timestamp lastUpdate = cw.getLastUpdate();
    if (lastUpdate == null) {
        lastUpdate = new Timestamp(System.currentTimeMillis());
    }

    try {

        sId = cw.getId();
        if (sId == null || sId.length() == 0) { // ...as it should be
            sId = getNextID();
            cw.setId(sId);
        }
        id = Long.parseLong(sId);

        CalendarContent c = cw.getCalendar().getCalendarContent();

        rp = c.getRecurrencePattern();

        boolean allDayB;
        if (c.getAllDay() != null && c.getAllDay().booleanValue()) {
            allDayB = true;
            allDay = "1";
        } else {
            allDayB = false;
            allDay = "0";
        }

        String sd = null;
        if (c.getDtStart() != null) {
            sd = c.getDtStart().getPropertyValueAsString();
            dstart = getDateFromString(allDayB, sd, "000000");
        }

        String ed = null;
        if ((sd != null && sd.length() > 0) || c.getDtEnd() != null) {
            ed = c.getDtEnd().getPropertyValueAsString();

            //
            // Fix for Siemens S56 end date issue only for event
            // @todo: verify if is really need to do this
            //
            if (c instanceof Event) {
                if (ed == null || ed.length() == 0) {
                    ed = sd;
                }
            }

            dend = getDateFromString(allDayB, ed, "235900");
        }

        body = Property.stringFrom(c.getDescription());

        if (c.getBusyStatus() != null) {
            busyStatus = new Short(c.getBusyStatus().shortValue());
        }

        categories = Property.stringFrom(c.getCategories());
        companies = Property.stringFrom(c.getOrganizer());
        location = Property.stringFrom(c.getLocation());
        folder = Property.stringFrom(c.getFolder());
        dstartTimeZone = timeZoneFrom(c.getDtStart());
        dendTimeZone = timeZoneFrom(c.getDtEnd());
        reminderTimeZone = timeZoneFrom(c.getReminder());
        meetingStatus = c.getMeetingStatus();

        Integer mileageInteger = c.getMileage(); // NB: not an int...
        if (mileageInteger != null) { // ...therefore it may be null
            mileage = String.valueOf(mileageInteger);
        }

        if (c instanceof Event) {
            replyTime = getDateFromString(allDayB, // @todo or false?
                    Property.stringFrom(((Event) c).getReplyTime()), "000000");
        }

        try {
            sensitivity = Short.parseShort(Property.stringFrom(c.getAccessClass()));
        } catch (NumberFormatException nfe) {
            sensitivity = 0;
            // The short must go on
        }

        if ((subject = Property.stringFrom(c.getSummary())) == null && body != null) {
            int endOfSentence = body.indexOf('.');
            if (endOfSentence == -1) {
                endOfSentence = body.length();
            }
            if (endOfSentence > SQL_SUBJECT_DIM) {
                endOfSentence = SQL_SUBJECT_DIM;
            }
            subject = body.substring(0, endOfSentence);
        }

        String isInfinite = "0";
        if (rp != null) {
            interval = rp.getInterval();
            recurrenceType = rp.getTypeId();
            monthOfYear = rp.getMonthOfYear();
            dayOfMonth = rp.getDayOfMonth();
            dayOfWeekMask = String.valueOf(rp.getDayOfWeekMask());
            instance = rp.getInstance();
            startDatePattern = rp.getStartDatePattern();
            endDatePattern = rp.getEndDatePattern();
            if (rp.isNoEndDate()) {
                isInfinite = "1";
            }
            occurrences = rp.getOccurrences();
        }

        if (c instanceof Task) {
            Task t = (Task) c;
            if (t.getDateCompleted() != null) {
                completed = getDateFromString(allDayB, ((Task) c).getDateCompleted().getPropertyValueAsString(),
                        "000000");
            }

            try {
                String complete = Property.stringFrom(t.getComplete());
                if (complete != null && complete.equals("1")) {
                    percentComplete = 100;
                } else {
                    percentComplete = Short.parseShort(Property.stringFrom(t.getPercentComplete()));
                }
                if (percentComplete < 0 || percentComplete > 100) {
                    throw new NumberFormatException("A percentage can't be " + percentComplete);
                }
            } catch (NumberFormatException nfe) {
                percentComplete = -1; // the short must go on
            }

            meetingStatus = getTaskStatus(t);
        }

        con = getUserDataSource().getRoutedConnection(userId);

        ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_CALENDAR);

        ps.setLong(1, id);
        ps.setString(2, userId);
        ps.setLong(3, lastUpdate.getTime());
        ps.setString(4, String.valueOf(Def.PIM_STATE_NEW));
        ps.setString(5, allDay);
        ps.setString(6, StringUtils.left(body, SQL_BODY_DIM));
        if (busyStatus != null) {
            ps.setShort(7, busyStatus.shortValue());
        } else {
            ps.setNull(7, Types.SMALLINT);
        }
        ps.setString(8, StringUtils.left(categories, SQL_CATEGORIES_DIM));
        ps.setString(9, StringUtils.left(companies, SQL_COMPANIES_DIM));
        ps.setInt(10, duration);
        if (dend != null) {
            ps.setTimestamp(11, new Timestamp(dend.getTime()));
        } else {
            ps.setNull(11, Types.TIMESTAMP);
        }

        if (c.getPriority() != null) {

            String priority = c.getPriority().getPropertyValueAsString();

            if (priority != null && priority.length() > 0) {
                importance = Short.parseShort(priority);
                ps.setShort(12, importance);
            } else {
                ps.setNull(12, Types.SMALLINT);
            }

        } else {
            ps.setNull(12, Types.SMALLINT);
        }

        ps.setString(13, StringUtils.left(location, SQL_LOCATION_DIM));

        if (meetingStatus != null) {
            ps.setShort(14, meetingStatus.shortValue());
        } else {
            ps.setNull(14, Types.SMALLINT);
        }

        ps.setString(15, mileage);

        reminder = c.getReminder();
        if (reminder != null && reminder.isActive()) {
            Timestamp reminderTime = getReminderTime(dstart, reminder);
            if (reminderTime == null) {
                ps.setNull(16, Types.TIMESTAMP);
            } else {
                ps.setTimestamp(16, reminderTime);
            }
            ps.setInt(17, reminder.getRepeatCount());
            ps.setString(18, (reminder.isActive()) ? "1" : "0");

            String soundFileValue = reminder.getSoundFile();
            ps.setString(19, StringUtils.left(soundFileValue, SQL_SOUNDFILE_DIM));
            ps.setInt(20, reminder.getOptions());
        } else {
            ps.setNull(16, Types.TIMESTAMP);
            ps.setInt(17, 0);
            ps.setString(18, "0");
            ps.setString(19, null);
            ps.setInt(20, 0);
        }

        if (replyTime != null) {
            ps.setTimestamp(21, new Timestamp(replyTime.getTime()));
        } else {
            ps.setNull(21, Types.TIMESTAMP);
        }

        ps.setShort(22, sensitivity);

        if (dstart != null) {
            ps.setTimestamp(23, new Timestamp(dstart.getTime()));
        } else {
            ps.setNull(23, Types.TIMESTAMP);
        }
        ps.setString(24, StringUtils.left(subject, SQL_SUBJECT_DIM));
        ps.setShort(25, recurrenceType);
        ps.setInt(26, interval);
        ps.setShort(27, monthOfYear);
        ps.setShort(28, dayOfMonth);
        ps.setString(29, StringUtils.left(dayOfWeekMask, SQL_DAYOFWEEKMASK_DIM));
        ps.setShort(30, instance);
        ps.setString(31, StringUtils.left(startDatePattern, SQL_STARTDATEPATTERN_DIM));
        ps.setString(32, isInfinite);
        ps.setString(33, StringUtils.left(endDatePattern, SQL_ENDDATEPATTERN_DIM));
        ps.setInt(34, occurrences);

        if (c instanceof Event) {
            ps.setInt(35, CALENDAR_EVENT_TYPE);
            ps.setNull(36, Types.TIMESTAMP); // completed
            ps.setNull(37, Types.SMALLINT); // percent_complete
        } else {
            ps.setInt(35, CALENDAR_TASK_TYPE);

            if (completed != null) {
                ps.setTimestamp(36, new Timestamp(completed.getTime()));
            } else {
                ps.setNull(36, Types.TIMESTAMP);
            }

            if (percentComplete != -1) {
                ps.setShort(37, percentComplete);
            } else {
                ps.setNull(37, Types.SMALLINT);
            }
        }

        ps.setString(38, StringUtils.left(folder, SQL_FOLDER_DIM));
        ps.setString(39, StringUtils.left(dstartTimeZone, SQL_TIME_ZONE_DIM));
        ps.setString(40, StringUtils.left(dendTimeZone, SQL_TIME_ZONE_DIM));
        ps.setString(41, StringUtils.left(reminderTimeZone, SQL_TIME_ZONE_DIM));

        ps.executeUpdate();
        DBTools.close(null, ps, null);

        if (recurrenceType != -1) {
            List<ExceptionToRecurrenceRule> exceptions = rp.getExceptions();
            for (ExceptionToRecurrenceRule etrr : exceptions) {
                ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_CALENDAR_EXCEPTION);

                ps.setLong(1, id);
                ps.setString(2, (etrr.isAddition() ? "1" : "0"));
                ps.setTimestamp(3,
                        new Timestamp(getDateFromString(allDayB, etrr.getDate(), "000000").getTime()));

                ps.executeUpdate();
                DBTools.close(null, ps, null);
            }
        }

    } catch (Exception e) {
        throw new DAOException("Error adding a calendar item: " + e.getMessage(), e);
    } finally {
        DBTools.close(con, ps, null);
    }
}

From source file:eu.europeana.portal2.web.presentation.model.FullDocPage.java

public String getObjectTitle() {
    return StringUtils.left(getBaseTitle(), 250);
}