List of usage examples for org.apache.commons.lang StringUtils left
public static String left(String str, int len)
Gets the leftmost len
characters of a String.
From source file:com.skratchdot.electribe.model.esx.provider.PatternItemProvider.java
@Override protected Command createSetCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, Object value) {//from w w w. j av a 2s . co m // When setting name, only allow 8 characters if (feature == EsxPackage.Literals.PATTERN__NAME) { value = StringUtils.left((String) value, 8); } return super.createSetCommand(domain, owner, feature, value); }
From source file:eu.europeana.portal2.web.presentation.model.FullDocPage.java
/** * Returns the title of the page/*from w ww . ja v a 2s. c o m*/ * * @return page title */ @Override public String getPageTitle() { StringBuilder title = new StringBuilder(getBaseTitle()); String creator = getShortcutFirstValue("DcCreator"); if (creator != null) { // clean up creator first (..), [..], <..>, {..} creator = creator.replaceAll("[\\<({\\[].*?[})\\>\\]]", ""); // strip , from begin or end creator = StringUtils.strip(creator, ","); // strip spaces creator = StringUtils.trim(creator); if (StringUtils.isNotBlank(creator)) { title.append(" | ").append(creator); } } return StringUtils.left(title.toString(), 250); }
From source file:eu.europeana.portal2.web.presentation.model.FullDocPage.java
private String getBaseTitle() { String dcTitle = ""; if (document == null) { return dcTitle; }/*from w ww . ja va 2s.com*/ if (StringArrayUtils.isNotBlank(getDocument().getDcTitle())) { dcTitle = getDocument().getDcTitle()[0]; } else if (getShortcutFirstValue("DctermsAlternative") != null) { dcTitle = getShortcutFirstValue("DctermsAlternative"); } else if (StringArrayUtils.isNotBlank(getDocument().getDcDescription())) { dcTitle = getDocument().getDcDescription()[0]; if (dcTitle.indexOf("<br/>\n") > 0) { dcTitle = dcTitle.substring(0, dcTitle.indexOf("<br/>\n")); } if (dcTitle.length() > 50) { dcTitle = StringUtils.left(dcTitle, 50) + "..."; } } else if (StringArrayUtils.isNotBlank(document.getTitle())) { dcTitle = document.getTitle()[0]; } return dcTitle; }
From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java
/** * Updates file data object metadata. <code>content</code> is not used. * @param fdow/* w w w . j a v a2 s . c o m*/ * @throws com.funambol.foundation.exception.DAOException */ public void updateItem(FileDataObjectWrapper fdow) throws DAOException { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { FileDataObject fdo = fdow.getFileDataObject(); Long fdoId = Long.valueOf(fdow.getId()); Timestamp currentTime = new Timestamp(System.currentTimeMillis()); StringBuilder updateQuery = new StringBuilder(); updateQuery.append(SQL_UPDATE_FNBL_FILE_DATA_OBJECT_BEGIN); updateQuery.append(SQL_FIELD_LAST_UPDATE).append(SQL_EQUALS_QUESTIONMARK_COMMA); updateQuery.append(SQL_FIELD_STATUS).append(SQL_EQUALS_QUESTIONMARK_COMMA); updateQuery.append(SQL_FIELD_UPLOAD_STATUS).append(SQL_EQUALS_QUESTIONMARK_COMMA); String localName = fdow.getLocalName(); if (localName != null) { updateQuery.append(SQL_FIELD_LOCAL_NAME).append(SQL_EQUALS_QUESTIONMARK_COMMA); } else { // if the item was deleted and readded again with a sync // considering only the metadata, the local name must be set to // null, since the previous file was already deleted and the new // file would be uploaded later. updateQuery.append(SQL_FIELD_LOCAL_NAME).append(SQL_EQUALS_NULL_COMMA); } Long crc = Long.valueOf(fdow.getFileDataObject().getCrc()); updateQuery.append(SQL_FIELD_CRC).append(SQL_EQUALS_QUESTIONMARK_COMMA); String trueName = fdo.getName(); if (trueName != null) { updateQuery.append(SQL_FIELD_TRUE_NAME).append(SQL_EQUALS_QUESTIONMARK_COMMA); } MediaUtils.setFDODates(fdo, fdo.getCreated(), fdo.getModified()); Timestamp created = timestamp(fdo.getCreated()); if (created == null) { created = currentTime; } Timestamp modified = timestamp(fdo.getModified()); if (modified == null) { modified = currentTime; } updateQuery.append(SQL_FIELD_CREATED).append(SQL_EQUALS_QUESTIONMARK_COMMA); updateQuery.append(SQL_FIELD_MODIFIED).append(SQL_EQUALS_QUESTIONMARK_COMMA); Timestamp accessed = timestamp(fdo.getAccessed()); if (accessed != null) { updateQuery.append(SQL_FIELD_ACCESSED).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean hidden = fdo.getHidden(); if (hidden != null) { updateQuery.append(SQL_FIELD_H).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean system = fdo.getSystem(); if (system != null) { updateQuery.append(SQL_FIELD_S).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean archived = fdo.getArchived(); if (archived != null) { updateQuery.append(SQL_FIELD_A).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean deleted = fdo.getDeleted(); if (deleted != null) { updateQuery.append(SQL_FIELD_D).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean writable = fdo.getWritable(); if (writable != null) { updateQuery.append(SQL_FIELD_W).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean readable = fdo.getReadable(); if (readable != null) { updateQuery.append(SQL_FIELD_R).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean executable = fdo.getExecutable(); if (executable != null) { updateQuery.append(SQL_FIELD_X).append(SQL_EQUALS_QUESTIONMARK_COMMA); } String contentType = fdo.getContentType(); if (contentType != null) { updateQuery.append(SQL_FIELD_CTTYPE).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Long size = fdo.getSize(); if (size != null) { updateQuery.append(SQL_FIELD_SIZE).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Long sizeOnStorage = fdow.getSizeOnStorage(); if (sizeOnStorage != null) { updateQuery.append(SQL_FIELD_SIZE_ON_STORAGE).append(SQL_EQUALS_QUESTIONMARK_COMMA); } if (updateQuery.charAt(updateQuery.length() - 2) == ',') { updateQuery.deleteCharAt(updateQuery.length() - 2); } updateQuery.append(SQL_UPDATE_FNBL_FILE_DATA_OBJECT_END); // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); ps = con.prepareStatement(updateQuery.toString()); int k = 1; Timestamp lastUpdate = (fdow.getLastUpdate() == null) ? currentTime : fdow.getLastUpdate(); ps.setLong(k++, lastUpdate.getTime()); ps.setString(k++, String.valueOf(Def.PIM_STATE_UPDATED)); ps.setString(k++, String.valueOf(fdo.getUploadStatus())); if (localName != null) { ps.setString(k++, StringUtils.left(localName, SQL_LOCAL_NAME_DIM)); } ps.setLong(k++, crc); if (trueName != null) { ps.setString(k++, StringUtils.left(trueName, SQL_TRUE_NAME_DIM)); } // cannot be null ps.setTimestamp(k++, created); ps.setTimestamp(k++, modified); if (accessed != null) { ps.setTimestamp(k++, accessed); } if (hidden != null) { ps.setString(k++, hidden ? ONE : NIL); } if (system != null) { ps.setString(k++, system ? ONE : NIL); } if (archived != null) { ps.setString(k++, archived ? ONE : NIL); } if (deleted != null) { ps.setString(k++, deleted ? ONE : NIL); } if (writable != null) { ps.setString(k++, writable ? ONE : NIL); } if (readable != null) { ps.setString(k++, readable ? ONE : NIL); } if (executable != null) { ps.setString(k++, executable ? ONE : NIL); } if (contentType != null) { ps.setString(k++, StringUtils.left(contentType, SQL_CTTYPE_DIM)); } if (size != null) { ps.setLong(k++, size); } if (sizeOnStorage != null) { ps.setLong(k++, sizeOnStorage); } ps.setLong(k++, fdoId); ps.setString(k++, userId); ps.setString(k++, sourceURI); ps.executeUpdate(); // delete and add the properties associated to the new FDO removeAllProperties(fdow.getId()); addProperties(fdow); } catch (Exception e) { throw new DAOException("Error updating file data object.", e); } finally { DBTools.close(con, ps, rs); } }
From source file:com.skratchdot.electribe.model.esx.provider.SampleItemProvider.java
@Override protected Command createSetCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, Object value) {/*from w ww.j ava 2 s. c om*/ // When setting name, only allow 8 characters if (feature == EsxPackage.Literals.SAMPLE__NAME) { value = StringUtils.left((String) value, 8); } // Start cannot be negative, greater than getEnd(), // or greater than getNumberOfSampleFrames() // If it's greater than getLoopStart(), then we need to adjust loopStart() if (feature == EsxPackage.Literals.SAMPLE__START) { int loopStart = ((Sample) owner).getLoopStart(); int end = ((Sample) owner).getEnd(); int maxEnd = ((Sample) owner).getNumberOfSampleFrames() - 1; maxEnd = maxEnd < 0 ? 0 : maxEnd; // Start cannot be negative if ((Integer) value < 0) { value = new Integer(0); } // Start cannot be greater than getEnd() if ((Integer) value > end) { value = new Integer(end); } // Start cannot be greater than getNumberOfSampleFrames() if ((Integer) value > maxEnd) { value = new Integer(maxEnd); } // If End is less than getLoopStart(), we need to adjust loopStart if ((Integer) value > loopStart) { CompoundCommand cmd = new CompoundCommand(); // Change getLoopStart() cmd.append(new SetCommand(domain, owner, EsxPackage.Literals.SAMPLE__LOOP_START, (Integer) value)); // Change getEnd() cmd.append(new SetCommand(domain, owner, feature, (Integer) value)); return cmd; } } // End cannot be negative, less than getStart(), // or greater than getNumberOfSampleFrames() // If it's less than getLoopStart(), then we need to adjust loopStart() if (feature == EsxPackage.Literals.SAMPLE__END) { int loopStart = ((Sample) owner).getLoopStart(); int start = ((Sample) owner).getStart(); int maxEnd = ((Sample) owner).getNumberOfSampleFrames() - 1; maxEnd = maxEnd < 0 ? 0 : maxEnd; // End cannot be negative if ((Integer) value < 0) { value = new Integer(0); } // End cannot be less than getStart() if ((Integer) value < start) { value = new Integer(start); } // End cannot be greater than getNumberOfSampleFrames() if ((Integer) value > maxEnd) { value = new Integer(maxEnd); } // If End is less than getLoopStart(), we need to adjust loopStart if ((Integer) value < loopStart) { CompoundCommand cmd = new CompoundCommand(); // Change getLoopStart() cmd.append(new SetCommand(domain, owner, EsxPackage.Literals.SAMPLE__LOOP_START, (Integer) value)); // Change getEnd() cmd.append(new SetCommand(domain, owner, feature, (Integer) value)); return cmd; } } // LoopStart cannot be negative, less than getStart(), // greater than getEnd(), or greater than getNumberOfSampleFrames() if (feature == EsxPackage.Literals.SAMPLE__LOOP_START) { int start = ((Sample) owner).getStart(); int end = ((Sample) owner).getEnd(); int maxEnd = ((Sample) owner).getNumberOfSampleFrames() - 1; maxEnd = maxEnd < 0 ? 0 : maxEnd; // LoopStart cannot be negative if ((Integer) value < 0) { value = new Integer(0); } // LoopStart cannot be less that getStart() if ((Integer) value < start) { value = new Integer(start); } // LoopStart cannot be greater than getEnd() if ((Integer) value > end) { value = new Integer(end); } // LoopStart cannot be greater than getNumberOfSampleFrames() if ((Integer) value > maxEnd) { value = new Integer(maxEnd); } } return super.createSetCommand(domain, owner, feature, value); }
From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java
/** * Updates metadata fields when FileDataObject body changes, like crc, size, * localname etc and the properties associated to it. * * @param fdow the wrapper with the new body file * @throws DAOException if an error occurs *///from w w w . ja v a2s . c om public void updateItemWhenBodyChanges(FileDataObjectWrapper fdow) throws DAOException { Connection con = null; PreparedStatement ps = null; try { Long fdoId = Long.valueOf(fdow.getId()); FileDataObject fdo = fdow.getFileDataObject(); Timestamp currentTime = new Timestamp(System.currentTimeMillis()); StringBuilder updateQuery = new StringBuilder(); updateQuery.append(SQL_UPDATE_FNBL_FILE_DATA_OBJECT_BEGIN); updateQuery.append(SQL_FIELD_LAST_UPDATE).append(SQL_EQUALS_QUESTIONMARK_COMMA); String localName = fdow.getLocalName(); if (localName != null) { updateQuery.append(SQL_FIELD_LOCAL_NAME).append(SQL_EQUALS_QUESTIONMARK_COMMA); } updateQuery.append(SQL_FIELD_UPLOAD_STATUS).append(SQL_EQUALS_QUESTIONMARK_COMMA); Long crc = Long.valueOf(fdow.getFileDataObject().getCrc()); updateQuery.append(SQL_FIELD_CRC).append(SQL_EQUALS_QUESTIONMARK_COMMA); Long size = fdo.getSize(); if (size != null) { updateQuery.append(SQL_FIELD_SIZE).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Long sizeOnStorage = fdow.getSizeOnStorage(); if (sizeOnStorage != null) { updateQuery.append(SQL_FIELD_SIZE_ON_STORAGE).append(SQL_EQUALS_QUESTIONMARK_COMMA); } // set always created and modified dates updateQuery.append(SQL_FIELD_CREATED).append(SQL_EQUALS_QUESTIONMARK_COMMA); updateQuery.append(SQL_FIELD_MODIFIED).append(SQL_EQUALS_QUESTIONMARK_COMMA); if (updateQuery.charAt(updateQuery.length() - 2) == ',') { updateQuery.deleteCharAt(updateQuery.length() - 2); } updateQuery.append(SQL_UPDATE_FNBL_FILE_DATA_OBJECT_END); // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); ps = con.prepareStatement(updateQuery.toString()); int k = 1; Timestamp lastUpdate = (fdow.getLastUpdate() == null) ? currentTime : fdow.getLastUpdate(); ps.setLong(k++, lastUpdate.getTime()); if (localName != null) { ps.setString(k++, StringUtils.left(localName, SQL_LOCAL_NAME_DIM)); } ps.setString(k++, "" + fdo.getUploadStatus()); ps.setLong(k++, crc); if (size != null) { ps.setLong(k++, size); } if (sizeOnStorage != null) { ps.setLong(k++, sizeOnStorage); } 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.setLong(k++, fdoId); ps.setString(k++, userId); ps.setString(k++, sourceURI); ps.executeUpdate(); DBTools.close(con, ps, null); // delete and add the properties associated to the new FDO removeAllProperties(fdow.getId()); addProperties(fdow); } catch (Exception e) { throw new DAOException("Error updating file data object and its properties.", e); } finally { DBTools.close(con, ps, null); } }
From source file:com.funambol.foundation.items.dao.PIMContactDAO.java
/** * Adds a contact. If necessary, a new ID is generated and set in the * ContactWrapper.//w w w. j a v a 2s.c om * * @param cw as a ContactWrapper object, usually without an ID set. * @throws DAOException * * @see ContactWrapper */ public void addItem(ContactWrapper cw) throws DAOException { if (log.isTraceEnabled()) { log.trace("Storing a contact item..."); } Connection con = null; PreparedStatement ps = null; long id = 0; int type = 0; PersonalDetail personalDetail = null; BusinessDetail businessDetail = null; Address homeAddressBook = null; Address workAddressBook = null; Address otherAddressBook = null; Name name = null; Phone phone = null; Email email = null; WebPage webPage = null; List<WebPage> webPages = new ArrayList<WebPage>(); List<Email> emails = new ArrayList<Email>(); List<Phone> phones = new ArrayList<Phone>(); List<String[]> labels = new ArrayList<String[]>(); String webPageType = null; Short importance = null; Short sensitivity = null; String mileage = null; String subject = null; String folder = null; String anniversary = null; String firstName = null; String middleName = null; String lastName = null; String displayName = null; String birthday = null; String categories = null; String gender = null; String hobbies = null; String initials = null; String languages = null; String nickName = null; String spouse = null; String suffix = null; String assistant = null; String officeLocation = null; String company = null; String companies = null; String department = null; String manager = null; String role = null; String children = null; String salutation = null; String sId = null; Timestamp lastUpdate = cw.getLastUpdate(); if (lastUpdate == null) { lastUpdate = new Timestamp(System.currentTimeMillis()); } try { // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); sId = cw.getId(); if (sId == null) { // ...as it should be sId = getNextID(); cw.setId(sId); } id = Long.parseLong(sId); Contact c = cw.getContact(); personalDetail = c.getPersonalDetail(); businessDetail = c.getBusinessDetail(); name = c.getName(); if (personalDetail != null) { homeAddressBook = personalDetail.getAddress(); otherAddressBook = personalDetail.getOtherAddress(); webPages.addAll(personalDetail.getWebPages()); emails.addAll(personalDetail.getEmails()); phones.addAll(personalDetail.getPhones()); } if (businessDetail != null) { workAddressBook = businessDetail.getAddress(); webPages.addAll(businessDetail.getWebPages()); emails.addAll(businessDetail.getEmails()); phones.addAll(businessDetail.getPhones()); companies = businessDetail.getCompanies(); } importance = c.getImportance(); sensitivity = c.getSensitivity(); mileage = c.getMileage(); subject = c.getSubject(); languages = c.getLanguages(); categories = Property.stringFrom(c.getCategories()); folder = c.getFolder(); if (personalDetail != null) { anniversary = personalDetail.getAnniversary(); birthday = personalDetail.getBirthday(); children = personalDetail.getChildren(); spouse = personalDetail.getSpouse(); hobbies = personalDetail.getHobbies(); gender = personalDetail.getGender(); } if (businessDetail != null) { assistant = businessDetail.getAssistant(); manager = businessDetail.getManager(); officeLocation = businessDetail.getOfficeLocation(); company = Property.stringFrom(businessDetail.getCompany()); department = Property.stringFrom(businessDetail.getDepartment()); role = Property.stringFrom(businessDetail.getRole()); } if (name != null) { firstName = Property.stringFrom(name.getFirstName()); middleName = Property.stringFrom(name.getMiddleName()); lastName = Property.stringFrom(name.getLastName()); displayName = Property.stringFrom(name.getDisplayName()); initials = Property.stringFrom(name.getInitials()); nickName = Property.stringFrom(name.getNickname()); suffix = Property.stringFrom(name.getSuffix()); salutation = Property.stringFrom(name.getSalutation()); } ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_CONTACT); // // GENERAL // if (log.isTraceEnabled()) { log.trace("Preparing statement with ID " + id); } ps.setLong(1, id); if (log.isTraceEnabled()) { log.trace("Preparing statement with user ID " + userId); } ps.setString(2, userId); ps.setLong(3, lastUpdate.getTime()); ps.setString(4, String.valueOf(Def.PIM_STATE_NEW)); boolean hasPhoto = false; Photo photo = personalDetail.getPhotoObject(); if (photo != null && (photo.getImage() != null || photo.getUrl() != null)) { hasPhoto = true; ps.setShort(5, photo.getImage() != null ? ContactWrapper.PHOTO_IMAGE : ContactWrapper.PHOTO_URL); } else if (photo != null) { ps.setShort(5, ContactWrapper.EMPTY_PHOTO); } else { ps.setNull(5, Types.SMALLINT); } // // CONTACT DETAILS // if (importance != null) { ps.setShort(6, importance.shortValue()); } else { ps.setNull(6, Types.SMALLINT); } if (sensitivity != null) { ps.setShort(7, sensitivity.shortValue()); } else { ps.setNull(7, Types.SMALLINT); } ps.setString(8, StringUtils.left(subject, SQL_SUBJECT_DIM)); ps.setString(9, StringUtils.left(folder, SQL_FOLDER_DIM)); // // PERSONAL DETAILS // ps.setString(10, StringUtils.left(anniversary, SQL_ANNIVERSARY_DIM)); ps.setString(11, StringUtils.left(firstName, SQL_FIRSTNAME_DIM)); ps.setString(12, StringUtils.left(middleName, SQL_MIDDLENAME_DIM)); ps.setString(13, StringUtils.left(lastName, SQL_LASTNAME_DIM)); ps.setString(14, StringUtils.left(displayName, SQL_DISPLAYNAME_DIM)); ps.setString(15, StringUtils.left(birthday, SQL_BIRTHDAY_DIM)); if (c.getNotes() != null && c.getNotes().size() > 0) { String noteValue = ((Note) c.getNotes().get(0)).getPropertyValueAsString(); ps.setString(16, StringUtils.left(noteValue, SQL_NOTE_DIM)); } else { ps.setString(16, null); } ps.setString(17, StringUtils.left(categories, SQL_CATEGORIES_DIM)); ps.setString(18, StringUtils.left(children, SQL_CHILDREN_DIM)); ps.setString(19, StringUtils.left(hobbies, SQL_HOBBIES_DIM)); ps.setString(20, StringUtils.left(initials, SQL_INITIALS_DIM)); ps.setString(21, StringUtils.left(languages, SQL_LANGUAGES_DIM)); ps.setString(22, StringUtils.left(nickName, SQL_NICKNAME_DIM)); ps.setString(23, StringUtils.left(spouse, SQL_SPOUSE_DIM)); ps.setString(24, StringUtils.left(suffix, SQL_SUFFIX_DIM)); ps.setString(25, StringUtils.left(salutation, SQL_SALUTATION_DIM)); // // BUSINESS DETAILS // ps.setString(26, StringUtils.left(assistant, SQL_ASSISTANT_DIM)); ps.setString(27, StringUtils.left(company, SQL_COMPANY_DIM)); ps.setString(28, StringUtils.left(department, SQL_DEPARTMENT_DIM)); if (businessDetail.getTitles() != null && businessDetail.getTitles().size() > 0) { String titleValue = ((Title) businessDetail.getTitles().get(0)).getPropertyValueAsString(); ps.setString(29, StringUtils.left(titleValue, SQL_TITLE_DIM)); } else { ps.setString(29, null); } ps.setString(30, StringUtils.left(manager, SQL_MANAGER_DIM)); if (mileage != null && mileage.length() > SQL_MILEAGE_DIM) { mileage = mileage.substring(0, SQL_MILEAGE_DIM); } ps.setString(31, StringUtils.left(mileage, SQL_MILEAGE_DIM)); ps.setString(32, StringUtils.left(officeLocation, SQL_OFFICELOCATION_DIM)); ps.setString(33, StringUtils.left(role, SQL_ROLE_DIM)); ps.setString(34, StringUtils.left(companies, SQL_COMPANIES_DIM)); ps.setString(35, StringUtils.left(gender, SQL_GENDER_DIM)); ps.executeUpdate(); DBTools.close(null, ps, null); // // emails // if (!emails.isEmpty()) { ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_CONTACT_ITEM); for (int i = 0, l = emails.size(); i < l; i++) { email = emails.get(i); type = getContactEmailItemTypeFromEmailPropertyType(email.getEmailType()); // Unknown property: saves nothing if (TYPE_UNDEFINED == type) continue; String emailValue = email.getPropertyValueAsString(); if (emailValue != null && emailValue.length() != 0) { if (emailValue.length() > SQL_EMAIL_DIM) { emailValue = emailValue.substring(0, SQL_EMAIL_DIM); } ps.setLong(1, id); ps.setInt(2, type); ps.setString(3, emailValue); ps.executeUpdate(); } } DBTools.close(null, ps, null); } // // phones // if (!phones.isEmpty()) { ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_CONTACT_ITEM); for (int i = 0, l = phones.size(); i < l; i++) { phone = phones.get(i); type = getContactPhoneItemTypeFromPhonePropertyType(phone.getPhoneType()); // Unknown property: saves nothing if (TYPE_UNDEFINED == type) continue; String phoneValue = phone.getPropertyValueAsString(); if (phoneValue != null && phoneValue.length() != 0) { if (phoneValue.length() > SQL_PHONE_DIM) { phoneValue = phoneValue.substring(0, SQL_PHONE_DIM); } ps.setLong(1, id); ps.setInt(2, type); ps.setString(3, phoneValue); ps.executeUpdate(); } } DBTools.close(null, ps, null); } // // webPages // if (!webPages.isEmpty()) { ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_CONTACT_ITEM); for (int i = 0, l = webPages.size(); i < l; i++) { webPage = webPages.get(i); webPageType = webPage.getWebPageType(); if ((FIELD_WEB_PAGE).equals(webPageType)) { type = TYPE_WEB_PAGE; } else if ((FIELD_HOME_WEB_PAGE).equals(webPageType)) { type = TYPE_HOME_WEB_PAGE; } else if ((FIELD_BUSINESS_WEB_PAGE).equals(webPageType)) { type = TYPE_BUSINESS_WEB_PAGE; } else { // // Unknown property: saves nothing // continue; } String webPageValue = webPage.getPropertyValueAsString(); if (webPageValue != null && webPageValue.length() != 0) { if (webPageValue.length() > SQL_WEBPAGE_DIM) { webPageValue = webPageValue.substring(0, SQL_WEBPAGE_DIM); } ps.setLong(1, id); ps.setInt(2, type); ps.setString(3, webPageValue); ps.executeUpdate(); } } DBTools.close(null, ps, null); } if (homeAddressBook != null) { String homeStreet = Property.stringFrom(homeAddressBook.getStreet()); String homeCity = Property.stringFrom(homeAddressBook.getCity()); String homePostalCode = Property.stringFrom(homeAddressBook.getPostalCode()); String homeState = Property.stringFrom(homeAddressBook.getState()); String homeCountry = Property.stringFrom(homeAddressBook.getCountry()); String homePostalOfficeAddress = Property.stringFrom(homeAddressBook.getPostOfficeAddress()); String homeExtendedAddress = Property.stringFrom(homeAddressBook.getExtendedAddress()); String homeLabel = Property.stringFrom(homeAddressBook.getLabel()); if (homeLabel != null) { String[] label = { homeLabel, FIELD_HOME_LABEL }; labels.add(label); } String[] homeAddressFields = { homeStreet, homeCity, homePostalCode, homeCountry, homeState, homePostalOfficeAddress, homeExtendedAddress }; if (!hasOnlyEmptyOrNullContent(homeAddressFields)) { ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_ADDRESS); ps.setLong(1, id); ps.setInt(2, ADDRESS_TYPE_HOME); ps.setString(3, replaceNewLine(StringUtils.left(homeStreet, SQL_STREET_DIM))); ps.setString(4, StringUtils.left(homeCity, SQL_CITY_DIM)); ps.setString(5, StringUtils.left(homeState, SQL_STATE_DIM)); ps.setString(6, StringUtils.left(homePostalCode, SQL_POSTALCODE_DIM)); ps.setString(7, StringUtils.left(homeCountry, SQL_COUNTRY_DIM)); ps.setString(8, StringUtils.left(homePostalOfficeAddress, SQL_POSTALOFFICEADDRESS_DIM)); ps.setString(9, StringUtils.left(homeExtendedAddress, SQL_EXTENDEDADDRESS_DIM)); ps.executeUpdate(); DBTools.close(null, ps, null); } } if (otherAddressBook != null) { String otherStreet = Property.stringFrom(otherAddressBook.getStreet()); String otherCity = Property.stringFrom(otherAddressBook.getCity()); String otherPostalCode = Property.stringFrom(otherAddressBook.getPostalCode()); String otherState = Property.stringFrom(otherAddressBook.getState()); String otherCountry = Property.stringFrom(otherAddressBook.getCountry()); String otherPostalOfficeAddress = Property.stringFrom(otherAddressBook.getPostOfficeAddress()); String otherExtendedAddress = Property.stringFrom(otherAddressBook.getExtendedAddress()); String otherLabel = Property.stringFrom(otherAddressBook.getLabel()); if (otherLabel != null) { String[] label = { otherLabel, FIELD_OTHER_LABEL }; labels.add(label); } String[] otherAddressFields = { otherStreet, otherCity, otherPostalCode, otherCountry, otherState, otherPostalOfficeAddress, otherExtendedAddress }; if (!hasOnlyEmptyOrNullContent(otherAddressFields)) { ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_ADDRESS); ps.setLong(1, id); ps.setInt(2, ADDRESS_TYPE_OTHER); ps.setString(3, replaceNewLine(StringUtils.left(otherStreet, SQL_STREET_DIM))); ps.setString(4, StringUtils.left(otherCity, SQL_CITY_DIM)); ps.setString(5, StringUtils.left(otherState, SQL_STATE_DIM)); ps.setString(6, StringUtils.left(otherPostalCode, SQL_POSTALCODE_DIM)); ps.setString(7, StringUtils.left(otherCountry, SQL_COUNTRY_DIM)); ps.setString(8, StringUtils.left(otherPostalOfficeAddress, SQL_POSTALOFFICEADDRESS_DIM)); ps.setString(9, StringUtils.left(otherExtendedAddress, SQL_EXTENDEDADDRESS_DIM)); ps.executeUpdate(); DBTools.close(null, ps, null); } } if (workAddressBook != null) { String workStreet = Property.stringFrom(workAddressBook.getStreet()); String workCity = Property.stringFrom(workAddressBook.getCity()); String workPostalCode = Property.stringFrom(workAddressBook.getPostalCode()); String workState = Property.stringFrom(workAddressBook.getState()); String workCountry = Property.stringFrom(workAddressBook.getCountry()); String workPostalOfficeAddress = Property.stringFrom(workAddressBook.getPostOfficeAddress()); String workExtendedAddress = Property.stringFrom(workAddressBook.getExtendedAddress()); String workLabel = Property.stringFrom(workAddressBook.getLabel()); if (workLabel != null) { String[] label = { workLabel, FIELD_BUSINESS_LABEL }; labels.add(label); } String[] workAddressFields = { workStreet, workCity, workPostalCode, workCountry, workState, workPostalOfficeAddress, workExtendedAddress }; if (!hasOnlyEmptyOrNullContent(workAddressFields)) { ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_ADDRESS); ps.setLong(1, id); ps.setInt(2, ADDRESS_TYPE_WORK); ps.setString(3, replaceNewLine(StringUtils.left(workStreet, SQL_STREET_DIM))); ps.setString(4, StringUtils.left(workCity, SQL_CITY_DIM)); ps.setString(5, StringUtils.left(workState, SQL_STATE_DIM)); ps.setString(6, StringUtils.left(workPostalCode, SQL_POSTALCODE_DIM)); ps.setString(7, StringUtils.left(workCountry, SQL_COUNTRY_DIM)); ps.setString(8, StringUtils.left(workPostalOfficeAddress, SQL_POSTALOFFICEADDRESS_DIM)); ps.setString(9, StringUtils.left(workExtendedAddress, SQL_EXTENDEDADDRESS_DIM)); ps.executeUpdate(); DBTools.close(null, ps, null); } } // // labels // if (!labels.isEmpty()) { ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_CONTACT_ITEM); for (int i = 0, l = labels.size(); i < l; i++) { String[] label = labels.get(i); String labelType = label[1]; if ((FIELD_HOME_LABEL).equals(labelType)) { type = TYPE_HOME_LABEL; } else if ((FIELD_BUSINESS_LABEL).equals(labelType)) { type = TYPE_BUSINESS_LABEL; } else if ((FIELD_OTHER_LABEL).equals(labelType)) { type = TYPE_OTHER_LABEL; } else { // // Unknown property: saves nothing // continue; } String labelValue = label[0]; if (labelValue != null && labelValue.length() != 0) { if (labelValue.length() > SQL_LABEL_DIM) { labelValue = labelValue.substring(0, SQL_LABEL_DIM); } ps.setLong(1, id); ps.setInt(2, type); ps.setString(3, labelValue); ps.executeUpdate(); } } DBTools.close(null, ps, null); } if (hasPhoto) { insertPhoto(con, Long.parseLong(cw.getId()), photo); } } catch (Exception e) { throw new DAOException("Error adding contact.", e); } finally { DBTools.close(con, ps, null); } if (log.isTraceEnabled()) { log.trace("Added item with ID '" + id + "'"); } }
From source file:com.funambol.foundation.items.dao.PIMNoteDAOTest.java
/** * Update fields with a big content.// w w w.ja va 2 s .co m */ public void testUpdateItemBigContent() throws Throwable { NoteWrapper nw = pimNoteDao.getItem("1"); Note note = nw.getNote(); String subject = note.getSubject().getPropertyValueAsString(); String textDescription = note.getTextDescription().getPropertyValueAsString(); String categories = note.getCategories().getPropertyValueAsString(); String folder = note.getFolder().getPropertyValueAsString(); String color = note.getColor().getPropertyValueAsString(); String height = note.getHeight().getPropertyValueAsString(); String width = note.getWidth().getPropertyValueAsString(); String top = note.getTop().getPropertyValueAsString(); String left = note.getLeft().getPropertyValueAsString(); String upd = " UPD"; String bigString = createBigString(1000 * 2, "a"); Property expectedSubject = new Property(StringUtils.left(bigString, PIMNoteDAO.SQL_SUBJECT_DIM)); Property expectedTextDescription = new Property( StringUtils.left(bigString, PIMNoteDAO.SQL_TEXTDESCRIPTION_DIM)); Property expectedCategories = new Property((String) PrivateAccessor.invoke(pimNoteDao, "truncateCategoriesField", new Class[] { String.class, int.class }, new Object[] { bigString, PIMNoteDAO.SQL_FOLDER_DIM })); Property expectedFolder = new Property((String) PrivateAccessor.invoke(pimNoteDao, "truncateFolderField", new Class[] { String.class, int.class }, new Object[] { bigString, PIMNoteDAO.SQL_FOLDER_DIM })); Property expectedColor = new Property("1"); Property expectedHeight = new Property(height + "1"); Property expectedWidth = new Property(width + "1"); Property expectedTop = new Property(top + "1"); Property expectedLeft = new Property(left + "1"); note.setSubject(expectedSubject); note.setTextDescription(expectedTextDescription); note.setCategories(expectedCategories); note.setFolder(expectedFolder); note.setColor(expectedColor); note.setHeight(expectedHeight); note.setWidth(expectedWidth); note.setTop(expectedTop); note.setLeft(expectedLeft); pimNoteDao.updateItem(nw); NoteWrapper resultNoteWrapper = pimNoteDao.getItem("1"); assertEquals("1", resultNoteWrapper.getId()); assertEquals(USER_ID, resultNoteWrapper.getUserId()); assertEquals('U', resultNoteWrapper.getStatus()); Note expectedNote = new Note(); expectedNote.setSubject(expectedSubject); expectedNote.setTextDescription(expectedTextDescription); expectedNote.setCategories(expectedCategories); expectedNote.setFolder(expectedFolder); expectedNote.setColor(expectedColor); expectedNote.setHeight(expectedHeight); expectedNote.setWidth(expectedWidth); expectedNote.setTop(expectedTop); expectedNote.setLeft(expectedLeft); assertEquals(expectedNote, resultNoteWrapper.getNote()); }
From source file:com.skratchdot.electribe.model.esx.impl.SampleImpl.java
/** * @param file//from w w w .j av a 2 s. c o m * @throws EsxException */ protected SampleImpl(File file) throws EsxException { super(); init(); // Declare our streams and formats AudioFormat audioFormatEncoded; AudioFormat audioFormatDecoded; AudioInputStream audioInputStreamEncoded; AudioInputStream audioInputStreamDecoded; try { // Initialize our streams and formats audioInputStreamEncoded = AudioSystem.getAudioInputStream(file); audioFormatEncoded = audioInputStreamEncoded.getFormat(); audioFormatDecoded = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, audioFormatEncoded.getSampleRate(), 16, audioFormatEncoded.getChannels(), audioFormatEncoded.getChannels() * 2, audioFormatEncoded.getSampleRate(), true); audioInputStreamDecoded = AudioSystem.getAudioInputStream(audioFormatDecoded, audioInputStreamEncoded); // We have a decoded stereo audio stream // Now we need to get the stream info into a list we can manipulate byte[] audioData = new byte[4096]; int nBytesRead = 0; long nTotalBytesRead = 0; List<Byte> audioDataListChannel1 = new ArrayList<Byte>(); List<Byte> audioDataListChannel2 = new ArrayList<Byte>(); boolean isAudioDataStereo = false; // Set isAudioDataStereo if (audioFormatEncoded.getChannels() == 1) { isAudioDataStereo = false; } else if (audioFormatEncoded.getChannels() == 2) { isAudioDataStereo = true; } else { throw new EsxException("Sample has too many channels: " + file.getAbsolutePath()); } // Convert stream to list. This needs to be optimized. Converting // a byte at a time is probably too slow... while (nBytesRead >= 0) { nBytesRead = audioInputStreamDecoded.read(audioData, 0, audioData.length); // If we aren't at the end of the stream if (nBytesRead > 0) { for (int i = 0; i < nBytesRead; i++) { // MONO if (!isAudioDataStereo) { audioDataListChannel1.add(audioData[i]); audioDataListChannel2.add(audioData[i]); } // STEREO (LEFT) else if (nTotalBytesRead % 4 < 2) { audioDataListChannel1.add(audioData[i]); } // STEREO (RIGHT) else { audioDataListChannel2.add(audioData[i]); } // Update the total amount of bytes we've read nTotalBytesRead++; } } // Throw Exception if sample is too big if (nTotalBytesRead > EsxUtil.MAX_SAMPLE_MEM_IN_BYTES) { throw new EsxException("Sample is too big: " + file.getAbsolutePath()); } } // Set member variables int frameLength = audioDataListChannel1.size() / 2; this.setNumberOfSampleFrames(frameLength); this.setEnd(frameLength - 1); this.setLoopStart(frameLength - 1); this.setSampleRate((int) audioFormatEncoded.getSampleRate()); this.setAudioDataChannel1(EsxUtil.listToByteArray(audioDataListChannel1)); this.setAudioDataChannel2(EsxUtil.listToByteArray(audioDataListChannel2)); this.setStereoOriginal(isAudioDataStereo); // Set calculated Sample Tune (from Sample Rate) SampleTune newSampleTune = EsxFactory.eINSTANCE.createSampleTune(); float newFloat = newSampleTune.calculateSampleTuneFromSampleRate(this.getSampleRate()); newSampleTune.setValue(newFloat); this.setSampleTune(newSampleTune); // Set name String newSampleName = new String(); newSampleName = StringUtils.left(StringUtils.trim(file.getName()), 8); this.setName(newSampleName); // Attempt to set loopStart and End from .wav smpl chunk if (file.getAbsolutePath().toLowerCase().endsWith(".wav")) { try { RIFFWave riffWave = WavFactory.eINSTANCE.createRIFFWave(file); ChunkSampler chunkSampler = (ChunkSampler) riffWave .getFirstChunkByEClass(WavPackage.Literals.CHUNK_SAMPLER); if (chunkSampler != null && chunkSampler.getSampleLoops().size() > 0) { SampleLoop sampleLoop = chunkSampler.getSampleLoops().get(0); Long tempLoopStart = sampleLoop.getStart(); Long tempLoopEnd = sampleLoop.getEnd(); if (tempLoopStart < this.getEnd() && tempLoopStart >= 0) { this.setLoopStart(tempLoopStart.intValue()); } if (tempLoopEnd < this.getEnd() && tempLoopEnd > this.getLoopStart()) { this.setEnd(tempLoopEnd.intValue()); } } } catch (Exception e) { e.printStackTrace(); } } } catch (UnsupportedAudioFileException e) { e.printStackTrace(); throw new EsxException("Invalid audio file: " + file.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); throw new EsxException("Invalid audio file: " + file.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); throw new EsxException("Invalid audio file: " + file.getAbsolutePath()); } }
From source file:com.bluexml.side.Integration.alfresco.xforms.webscript.XFormsWork.java
/** * Provides the items to be listed in a selection widget. Returns an XML * string with root/*from ww w .j a va 2s. c om*/ * '<results>':<br> * <ul> * <li>query (appears once)</li> * <ul> * <li>count: the total number of objects available in the Lucene result set * </li> * <li>maxResults: if non-zero, sets the maximum number of objects requested * by the client. Returned as received.</li> * <li>returned: the number of result items returned to the client</li> * <li>filteredOut: if a filtering association was given, tells the number * of items that have been filtered out because they already have a * reference on that association.</li> * <li>typeFound: if <code>false</code>, the type is unknown to Alfresco.</li> * <li>query: a string to filter the items. The value returned is the * TrimToEmpty'ed version of the value that was received.</li> * </ul> * <li>item (number of occurrences is 0..*)</li> * <ul> * <li>id: the complete Alfresco id, including protocol and workspace</li> * <li>value: the display label for the item</li> * </ul> * </ul> Parameters: ("NULL-able" means that an empty value is accepted.)<br/> * "type": the data type to search. This parameter is MANDATORY.<br/> * "query": the search keyword string. NULL-able.<br/> * "queryFilter": an additional search keyword string. NULL-able.<br/> * "format": the format pattern for the label of objects. NULL-able.<br/> * "maxLength": the length at which labels computed using the format are * truncated. NULL-able.<br/> * "maxResults": the max number of items allowed in the result set. * NULL-able.<br/> * "identifier": the local name of a property whose value will be used as * the id of results. * NULL-able. Quite obviously, that field MUST 1- be non-null, 2- be an * actual identifier (i.e. * no value is duplicated in the value set)<br/> * "filterAssoc": the qualified name of an association by which it will be * determined whether * nodes are referenced. If present, nodes that are already pointed to by * that association will * be filtered out of the results. NULL-able.<br/> * "isComposition": if "1" and "filterAssoc" is given, denotes that the * association is a * composition. NULL-able.<br/> * "isSearchMode": if "1", an empty item list will be returned on an empty * "query". NULL-able.<br/> * "luceneQuery": a Lucene query that overrides the one that's normally * built here. NULL-able.<br/> * * @return * @throws Exception */ protected String list() throws Exception { class ResultBean { // #1406 String id; String label; String qname; ResultBean(String nodeId, String nodeLabel, String nodeQName) { this.id = nodeId; this.label = nodeLabel; this.qname = nodeQName; } } logger.debug("Initialization of system time: " + System.nanoTime()); Timer globalTimer = new Timer(); Timer luceneTimer = new Timer(); Timer noderefLuceneTimer = new Timer(); Timer noderefTimer = new Timer(); Timer labelTimer = new Timer(); Timer qnameTimer = new Timer(); Timer filteringTimer = new Timer(); Timer referenceTimer = new Timer(); Timer sortTimer = new Timer(); globalTimer.start(); // // collect parameters. Some of these are not necessary before the filtering/limiting/sorting // part but for convenience, all parameters are collected with, possibly, some work done // here that will come out as useless, but it makes this function more readable. // String type = parameters.get("type"); if (StringUtils.trimToNull(type) == null) { return getListOpcodeDefaultResult("<Invalid type>", false); } String identifier = parameters.get("identifier"); // #1529 String format = parameters.get("format"); // URL-decode the format pattern if (StringUtils.trimToNull(format) != null) { try { format = URLDecoder.decode(format, "UTF-8"); } catch (UnsupportedEncodingException e) { logger.error("UTF-8 is unsupported. Format is defaulted to 'uuid'."); format = null; } } int maxResults = 10; // arbitrary default value String maxParam = parameters.get("maxResults"); try { maxResults = Integer.parseInt(maxParam); } catch (NumberFormatException ne) { logger.error("'list' op: wrong number in parameter 'maxResults' (" + maxParam + ")"); } int maxLength = 0; // arbitrary default value String lengthParam = parameters.get("maxLength"); try { maxLength = Integer.parseInt(lengthParam); } catch (NumberFormatException nfe) { logger.error("'list' op: wrong number in parameter 'maxLength' (" + lengthParam + ")"); } // ** #1310 String filterAssoc = parameters.get("filterAssoc"); boolean applyFilterAssoc = (StringUtils.trimToNull(filterAssoc) != null); String isCompositionParam = parameters.get("isComposition"); boolean isComposition = StringUtils.equals(isCompositionParam, "1"); // ** #1310 String isSearchModeParam = parameters.get("isSearchMode"); boolean isSearchMode = StringUtils.equals(isSearchModeParam, "1"); List<String> searchedValues = new ArrayList<String>(); String query = StringUtils.trimToNull(parameters.get("query")); if (query != null) { searchedValues.add(query); } else { if (isSearchMode) { return getListOpcodeDefaultResult(query, true); // empty list for search widgets } } String queryFilter = parameters.get("queryFilter"); if (StringUtils.trimToNull(queryFilter) != null) { searchedValues.add(queryFilter); } String userLuceneQuery = StringUtils.trimToNull(parameters.get("luceneQuery")); if (userLuceneQuery != null) { try { // double-decoded because the string was double-encoded. userLuceneQuery = URLDecoder.decode(userLuceneQuery, "UTF-8"); userLuceneQuery = URLDecoder.decode(userLuceneQuery, "UTF-8"); } catch (UnsupportedEncodingException e) { logger.error("UTF-8 is unsupported. User Lucene expression will be ignored."); userLuceneQuery = null; } } // configure the filtering/limiting QName identifierQName = null; boolean includeSystemProperties = FORCE_SYSTEM_PROPERTIES_RESOLUTION; if (StringUtils.trimToNull(identifier) != null) { identifierQName = resolveIdentifierQName(identifier, type); includeSystemProperties = (identifierQName != null); } // perform the search luceneTimer.start(); ResultSet luceneResultSet = getResultSet(type, searchedValues, maxResults, userLuceneQuery, includeSystemProperties); luceneTimer.stop(); if (luceneResultSet == null) { // result for the pathological case when the type is unknown to Alfresco. return getListOpcodeDefaultResult(query, false); } int luceneResultLength = luceneResultSet.length(); if (luceneResultLength == 0) { return getListOpcodeDefaultResult(query, true); } // // // collect items and apply filtering and/or limiting. Node names/labels are also computed. // // /** * whether we need to collect all elements before applying the filtering * & limiting */ boolean collectAllNodes = false; if ((includeSystemProperties) && (query != null)) { // when searching system datatypes (e.g. "cm:permson"), we may have to collect all nodes // before filtering (happens when no property of the datatype is indexed) List<QName> subTypes = formsWebscript.getSubTypes(type); Set<QName> attributes = getSearchableAttributes(subTypes.get(0), includeSystemProperties); if (attributes.size() == 0) { // the datatype is not indexed collectAllNodes = true; } } int returnAtMost; if (collectAllNodes == false) { if (maxResults > 0) { returnAtMost = Math.min(luceneResultLength, maxResults); } else { returnAtMost = luceneResultLength; } } else { returnAtMost = luceneResultLength; } int effectivelyReturned = 0; int filteredOut = 0; // collect items and apply filtering and/or limiting filteringTimer.start(); List<ResultBean> resultBeanList = new ArrayList<ResultBean>(returnAtMost); noderefLuceneTimer.start(); List<NodeRef> resultSet = luceneResultSet.getNodeRefs(); noderefLuceneTimer.stop(); luceneResultSet.close(); for (int i = 0; i < returnAtMost; i++) { noderefTimer.start(); NodeRef nodeRef = resultSet.get(i); noderefTimer.stop(); labelTimer.start(); String label = resolveNodeName(nodeRef, format, includeSystemProperties); labelTimer.stop(); if (maxLength > 0) { label = StringUtils.left(label, maxLength); } qnameTimer.start(); QName qname = serviceRegistry.getNodeService().getType(nodeRef); // #1510 String id; if (identifierQName == null) { id = nodeRef.toString(); } else { id = resolveIdentifierValue(nodeRef, identifierQName); } String qnameStr = qname.toPrefixString(formsWebscript.getNamespacePrefixResolver()); qnameTimer.stop(); ResultBean aBean = new ResultBean(id, label, qnameStr); boolean isAddableBean = true; // whether the result will be added to the item list if (includeSystemProperties) { // for system datatypes, search the label (in case indexing is off for that type) if ((collectAllNodes == false) && (query != null) && (aBean.label.contains(query) == false)) { isAddableBean = false; filteredOut++; } } else { // retrieving objects of a standard BlueXML generated type if (applyFilterAssoc) { referenceTimer.start(); if (dataLayer.isRefencenced(nodeRef, filterAssoc, isComposition) == true) { // do not add if already referenced via the filtering association isAddableBean = false; filteredOut++; } referenceTimer.stop(); } } if (isAddableBean) { resultBeanList.add(aBean); effectivelyReturned++; } } filteringTimer.stop(); // // sort the result list by computed labels. #1406 sortTimer.start(); Collections.sort(resultBeanList, new Comparator<ResultBean>() { public int compare(ResultBean o1, ResultBean o2) { return o1.label.compareTo(o2.label); } }); sortTimer.stop(); // // write all results in the items string buffer // StringBuffer itemsBuf = new StringBuffer(""); if (collectAllNodes == true) { // in case all nodes were collected, the filtering and limiting takes place here filteredOut = 0; effectivelyReturned = 0; for (ResultBean aBean : resultBeanList) { if ((query != null) && StringUtils.contains(aBean.label.toLowerCase(), query.toLowerCase()) == false) { filteredOut++; } else { appendResult(itemsBuf, aBean.id, aBean.label, aBean.qname); effectivelyReturned++; if (effectivelyReturned == returnAtMost) { break; } } } } else { // filtering and limiting already happened for (ResultBean aBean : resultBeanList) { appendResult(itemsBuf, aBean.id, aBean.label, aBean.qname); } } StringBuffer xmlResult = new StringBuffer(""); xmlResult.append("<results>\n"); xmlResult.append("<query>\n"); xmlResult.append(" <count>").append(luceneResultLength).append("</count>\n"); xmlResult.append(" <maxResults>").append(maxResults).append("</maxResults>\n"); xmlResult.append(" <returned>").append(effectivelyReturned).append("</returned>\n"); xmlResult.append(" <filteredOut>").append(filteredOut).append("</filteredOut>\n"); xmlResult.append(" <typeFound>true</typeFound>\n"); xmlResult.append(" <query>").append(StringUtils.trimToEmpty(query)).append("</query>\n"); xmlResult.append("</query>\n"); xmlResult.append(itemsBuf); xmlResult.append("</results>"); globalTimer.stop(); logger.debug(">>><<< Timing:"); logger.debug("Total : " + globalTimer.getTotalTime() + " ns."); logger.debug(" Lucene : " + luceneTimer.getTotalTime() + " ns."); logger.debug(" Filtering : " + filteringTimer.getTotalTime() + " ns."); logger.debug(" Nref Lucene : " + noderefLuceneTimer.getTotalTime() + " ns."); logger.debug(" Nref SIDE: " + noderefTimer.getTotalTime() + " ns."); logger.debug(" Labels : " + labelTimer.getTotalTime() + " ns."); logger.debug(" QName : " + qnameTimer.getTotalTime() + " ns."); logger.debug(" Ref? : " + referenceTimer.getTotalTime() + " ns."); logger.debug(" Sort : " + sortTimer.getTotalTime() + " ns."); logger.debug(">>><<<"); return xmlResult.toString(); }