diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties index 80eb199fa..5944f8b19 100644 --- a/resources/languages/resources.properties +++ b/resources/languages/resources.properties @@ -811,6 +811,14 @@ impl.gui.main.account.DUMMY_PROTOCOL_DESCRIPTION=select network # LDAP impl.ldap.CONFIG_FORM_TITLE=LDAP configuration +impl.ldap.GENERAL=General +impl.ldap.FIELDS=Fields +impl.ldap.QUERY=Query +impl.ldap.QUERY_DEFAULT=Create automatically +impl.ldap.QUERY_CUSTOM=Custom query +impl.ldap.QUERY_CUSTOM_HINT=Use {0} as a placeholder for the search term. +impl.ldap.QUERY_CUSTOM_AUTO_WILDCARD=Automatically add wildcards to the query term +impl.ldap.QUERY_PHOTO_INLINE=Fetch photo along with other attributes impl.ldap.NEW=New impl.ldap.EDIT=edit impl.ldap.REMOVE=Remove diff --git a/src/net/java/sip/communicator/impl/ldap/LdapContactQuery.java b/src/net/java/sip/communicator/impl/ldap/LdapContactQuery.java index 714e9b681..19d74ade3 100644 --- a/src/net/java/sip/communicator/impl/ldap/LdapContactQuery.java +++ b/src/net/java/sip/communicator/impl/ldap/LdapContactQuery.java @@ -269,7 +269,7 @@ private void processLdapResponse(LdapEvent evt) try { - sourceContact.setImage(person.fetchPhoto()); + sourceContact.setImage(person.getPhoto()); } catch (OutOfMemoryError oome) { diff --git a/src/net/java/sip/communicator/impl/ldap/LdapDirectoryImpl.java b/src/net/java/sip/communicator/impl/ldap/LdapDirectoryImpl.java index d0c89a7a2..720c0ac27 100644 --- a/src/net/java/sip/communicator/impl/ldap/LdapDirectoryImpl.java +++ b/src/net/java/sip/communicator/impl/ldap/LdapDirectoryImpl.java @@ -54,7 +54,11 @@ public class LdapDirectoryImpl /** * Name of avatar attribute. */ - private static final String PHOTO_ATTRIBUTE = "jpegPhoto"; + private static final String[] PHOTO_ATTRIBUTES = new String[] + { + "jpegPhoto", + "thumbnailPhoto" + }; /** * data structure used to store the LDAP attributes that @@ -208,6 +212,12 @@ public LdapDirectoryImpl(LdapDirectorySettings settings) { searchableAttrs.add(s); } + + if (settings.isPhotoInline()) + { + retrievableAttributes.add("jpegPhoto"); + retrievableAttributes.add("thumbnailPhoto"); + } } /** @@ -385,7 +395,7 @@ public void run() SearchResult searchResult = (SearchResult) results.next(); - Map> retrievedAttributes = + Map> retrievedAttributes = retrieveAttributes(searchResult); LdapPersonFound person = buildPerson( @@ -411,7 +421,7 @@ public void run() } catch(OperationNotSupportedException e) { - logger.trace( + logger.error( "use bind DN without password during search" + " for real query \"" + realQueryString + "\" (initial query: \"" + @@ -425,7 +435,7 @@ public void run() } catch(AuthenticationException e) { - logger.trace( + logger.error( "authentication failed during search" + " for real query \"" + realQueryString + "\" (initial query: \"" + @@ -439,7 +449,7 @@ public void run() } catch(NamingException e) { - logger.trace( + logger.error( "an external exception was thrown during search" + " for real query \"" + realQueryString + "\" (initial query: \"" + @@ -469,6 +479,19 @@ public void run() // whether sleep was interrupted // is not that important } + catch (Exception e) + { + logger.error("search for real query \"" + realQueryString + + "\" (initial query: \"" + query.toString() + + "\") on " + LdapDirectoryImpl.this + + " cancelled at state " + cancelState, e); + + endEvent = new LdapEvent( + LdapDirectoryImpl.this, + LdapEvent.LdapEventCause.SEARCH_ERROR, + query + ); + } finally { fireLdapEvent(endEvent, caller); @@ -504,9 +527,14 @@ private void checkCancel() searchThread.start(); } - private static String[] + private String[] buildIntermediateQueryStrings(String initialQueryString) { + if (!this.settings.isMangleQuery()) + { + return new String[] { initialQueryString }; + } + // search for "doe john" as well "as john doe" String[] words = initialQueryString.split(" "); String[] intermediateQueryStrings; @@ -534,28 +562,27 @@ private void checkCancel() * @param searchResult the results to browse for attributes * @return the attributes in a Map */ - private Map> + private Map> retrieveAttributes(SearchResult searchResult) throws NamingException { Attributes attributes = searchResult.getAttributes(); - Map> retrievedAttributes = - new HashMap>(); + Map> retrievedAttributes = + new HashMap>(); NamingEnumeration ids = attributes.getIDs(); while(ids.hasMore()) { String id = ids.next(); if(retrievableAttributes.contains(id) || containsAttribute(id)) { - Set valuesSet = new HashSet(); + Set valuesSet = new HashSet(); retrievedAttributes.put(id, valuesSet); Attribute attribute = attributes.get(id); NamingEnumeration values = attribute.getAll(); while(values.hasMore()) { - String value = (String) values.next(); - valuesSet.add(value); + valuesSet.add(values.next()); } } } @@ -574,7 +601,7 @@ private void checkCancel() LdapQuery query, String dn, Map> retrievedAttributes + Set> retrievedAttributes ) { LdapPersonFound person = @@ -584,19 +611,22 @@ private void checkCancel() if(retrievedAttributes.get("givenname") != null) { String firstName = - retrievedAttributes.get("givenname").iterator().next(); + (String) retrievedAttributes.get("givenname") + .iterator().next(); person.setFirstName(firstName); } else if(retrievedAttributes.get("givenName") != null) { String firstName = - retrievedAttributes.get("givenName").iterator().next(); + (String) retrievedAttributes.get("givenName") + .iterator().next(); person.setFirstName(firstName); } else if(retrievedAttributes.get("gn") != null) { String firstName = - retrievedAttributes.get("gn").iterator().next(); + (String) retrievedAttributes.get("gn") + .iterator().next(); person.setFirstName(firstName); } @@ -604,13 +634,15 @@ else if(retrievedAttributes.get("gn") != null) if(retrievedAttributes.get("sn") != null) { String surname = - retrievedAttributes.get("sn").iterator().next(); + (String) retrievedAttributes.get("sn") + .iterator().next(); person.setSurname(surname); } else if(retrievedAttributes.get("surname") != null) { String surname = - retrievedAttributes.get("surname").iterator().next(); + (String) retrievedAttributes.get("surname") + .iterator().next(); person.setSurname(surname); } @@ -618,19 +650,22 @@ else if(retrievedAttributes.get("surname") != null) if(retrievedAttributes.get("displayName") != null) { String displayName = - retrievedAttributes.get("displayName").iterator().next(); + (String) retrievedAttributes.get("displayName") + .iterator().next(); person.setDisplayName(displayName); } else if(retrievedAttributes.get("cn") != null) { String displayName = - retrievedAttributes.get("cn").iterator().next(); + (String) retrievedAttributes.get("cn") + .iterator().next(); person.setDisplayName(displayName); } else if(retrievedAttributes.get("commonname") != null) { String displayName = - retrievedAttributes.get("commonname").iterator().next(); + (String) retrievedAttributes.get("commonname") + .iterator().next(); person.setDisplayName(displayName); } if(person.getDisplayName() == null) @@ -648,20 +683,21 @@ else if(retrievedAttributes.get("commonname") != null) if(retrievedAttributes.get("o") != null) { String organization = - retrievedAttributes.get("o").iterator().next(); + (String) retrievedAttributes.get("o").iterator().next(); person.setOrganization(organization); } else if(retrievedAttributes.get("organizationName") != null) { String organization = - retrievedAttributes.get("organizationName").iterator() - .next(); + (String) retrievedAttributes.get("organizationName") + .iterator().next(); person.setOrganization(organization); } else if(retrievedAttributes.get("company") != null) { String organization = - retrievedAttributes.get("company").iterator().next(); + (String) retrievedAttributes.get("company") + .iterator().next(); person.setOrganization(organization); } @@ -669,42 +705,60 @@ else if(retrievedAttributes.get("company") != null) if(retrievedAttributes.get("company") != null) { String department = - retrievedAttributes.get("company").iterator().next(); + (String) retrievedAttributes.get("company") + .iterator().next(); person.setDepartment(department); } else if(retrievedAttributes.get("ou") != null) { String department = - retrievedAttributes.get("ou").iterator().next(); + (String) retrievedAttributes.get("ou").iterator().next(); person.setDepartment(department); } else if(retrievedAttributes.get("orgunit") != null) { String department = - retrievedAttributes.get("orgunit").iterator().next(); + (String) retrievedAttributes.get("orgunit") + .iterator().next(); person.setDepartment(department); } else if(retrievedAttributes.get("organizationalUnitName") != null) { String department = - retrievedAttributes.get("organizationalUnitName"). + (String) retrievedAttributes.get("organizationalUnitName"). iterator().next(); person.setDepartment(department); } else if(retrievedAttributes.get("department") != null) { String department = - retrievedAttributes.get("department").iterator().next(); + (String) retrievedAttributes.get("department") + .iterator().next(); person.setDepartment(department); } else if(retrievedAttributes.get("departmentNumber") != null) { String department = - retrievedAttributes.get("departmentNumber").iterator(). - next(); + (String) retrievedAttributes.get("departmentNumber") + .iterator().next(); person.setDepartment(department); } + if(retrievedAttributes.get("jpegPhoto") != null) + { + byte[] photo = + (byte[])retrievedAttributes.get("jpegPhoto") + .iterator().next(); + person.setPhoto(photo); + } + else if(retrievedAttributes.get("thumbnailPhoto") != null) + { + byte[] photo = + (byte[])retrievedAttributes.get("thumbnailPhoto") + .iterator().next(); + person.setPhoto(photo); + } + // mail List attrs = attributesMap.get("mail"); @@ -712,8 +766,9 @@ else if(retrievedAttributes.get("departmentNumber") != null) { if(retrievedAttributes.get(attr) != null) { - for(String mail : retrievedAttributes.get(attr)) + for(Object o : retrievedAttributes.get(attr)) { + String mail = o.toString(); if(!mail.contains("@")) { if(settings.getMailSuffix() != null) @@ -736,7 +791,8 @@ else if(retrievedAttributes.get("departmentNumber") != null) if(retrievedAttributes.get(attr) != null) { String phone = - retrievedAttributes.get(attr).iterator().next(); + (String) retrievedAttributes.get(attr) + .iterator().next(); person.addWorkPhone(phone); } } @@ -748,9 +804,9 @@ else if(retrievedAttributes.get("departmentNumber") != null) { if(retrievedAttributes.get(attr) != null) { - for(String phone : retrievedAttributes.get(attr)) + for(Object phone : retrievedAttributes.get(attr)) { - person.addMobilePhone(phone); + person.addMobilePhone(phone.toString()); } } } @@ -762,9 +818,9 @@ else if(retrievedAttributes.get("departmentNumber") != null) { if(retrievedAttributes.get(attr) != null) { - for(String phone : retrievedAttributes.get(attr)) + for(Object phone : retrievedAttributes.get(attr)) { - person.addHomePhone(phone); + person.addHomePhone(phone.toString()); } } } @@ -836,27 +892,21 @@ private boolean textHasContent(String aText) } /** - * Builds an LDAP search filter, base on the query string entered - * e.g. (&(|(mail=*)(telephoneNumber=*))(|(cn=*query*)(sn=*query*)(givenname=*query*))) - * + * Builds an LDAP search filter, based on the query string entered and the + * searchable fields defined in the static constructor. If a custom query is + * defined this is used instead. e.g. + * (|(|(mail=query)(telephoneNumber=query))) + * * @return an LDAP search filter */ private String buildSearchFilter(String query) { - StringBuffer searchFilter = new StringBuffer(); - - /* - searchFilter.append("(&(|"); - - for(String attribute : retrievableAttributes) + if ("custom".equals(settings.getQueryMode())) { - searchFilter.append("("); - searchFilter.append(attribute); - searchFilter.append("=*)"); + return settings.getCustomQuery().replace("", query); } - searchFilter.append(")(|"); - */ + StringBuffer searchFilter = new StringBuffer(); searchFilter.append("(|"); /* cn=*query* OR sn=*query* OR ... */ @@ -966,6 +1016,11 @@ public Collection searchChildren(final String dn) */ byte[] fetchPhotoForPerson(String dn) { + if (this.settings.isPhotoInline()) + { + return null; + } + byte[] photo = null; InitialDirContext dirContext = null; @@ -973,8 +1028,7 @@ byte[] fetchPhotoForPerson(String dn) final SearchControls searchCtl = new SearchControls(); searchCtl.setSearchScope(SearchControls.OBJECT_SCOPE); - String[] returningAttributes = { PHOTO_ATTRIBUTE }; - searchCtl.setReturningAttributes(returningAttributes); + searchCtl.setReturningAttributes(PHOTO_ATTRIBUTES); logger.trace("starting photo retrieval..."); try @@ -991,13 +1045,16 @@ byte[] fetchPhotoForPerson(String dn) { SearchResult searchResult = (SearchResult) result.next(); Attributes attributes = searchResult.getAttributes(); - Attribute attribute = attributes.get(PHOTO_ATTRIBUTE); - if(attribute != null) + for (String a : PHOTO_ATTRIBUTES) { - NamingEnumeration values = attribute.getAll(); - if(values.hasMore()) + Attribute attribute = attributes.get(a); + if(attribute != null) { - photo = (byte[]) values.next(); + NamingEnumeration values = attribute.getAll(); + if(values.hasMore()) + { + photo = (byte[]) values.next(); + } } } } diff --git a/src/net/java/sip/communicator/impl/ldap/LdapDirectorySettingsImpl.java b/src/net/java/sip/communicator/impl/ldap/LdapDirectorySettingsImpl.java index cfa3d3701..1654604a2 100644 --- a/src/net/java/sip/communicator/impl/ldap/LdapDirectorySettingsImpl.java +++ b/src/net/java/sip/communicator/impl/ldap/LdapDirectorySettingsImpl.java @@ -41,6 +41,10 @@ public LdapDirectorySettingsImpl() this.setBaseDN(""); this.setScope(Scope.defaultValue()); this.setGlobalPhonePrefix(""); + this.setQueryMode(""); + this.setCustomQuery(""); + this.setMangleQuery(true); + this.setPhotoInline(false); // mail List lst = new ArrayList(); lst.add("mail"); @@ -93,6 +97,10 @@ public LdapDirectorySettingsImpl(LdapDirectorySettingsImpl settings) this.setGlobalPhonePrefix(settings.getGlobalPhonePrefix()); this.mapAttributes = settings.mapAttributes; this.mailSuffix = settings.mailSuffix; + this.queryMode = settings.queryMode; + this.customQuery = settings.customQuery; + this.mangleQuery = settings.mangleQuery; + this.photoInline = settings.photoInline; } /** @@ -170,6 +178,26 @@ public LdapDirectorySettingsImpl(LdapDirectorySettingsImpl settings) */ private String mailSuffix = null; + /** + * How the query should be constructed. + */ + private String queryMode; + + /** + * The user defined LDAP query. + */ + private String customQuery; + + /** + * Whether the query term should be automatically expanded for wildcards. + */ + private boolean mangleQuery; + + /** + * Whether photos are retrieved along with the other attributes. + */ + private boolean photoInline; + /** * Attributes map. */ @@ -465,7 +493,11 @@ public boolean equals(LdapDirectorySettings other) this.getPassword().equals(other.getPassword()) && this.getBaseDN().equals(other.getBaseDN()) && this.getScope().equals(other.getScope()) && - this.getGlobalPhonePrefix().equals(other.getGlobalPhonePrefix()); + this.getGlobalPhonePrefix().equals(other.getGlobalPhonePrefix()) && + this.getCustomQuery().equals(other.getCustomQuery()) && + this.getQueryMode().equals(other.getQueryMode()) && + this.isMangleQuery() == other.isMangleQuery() && + this.isPhotoInline() == other.isPhotoInline(); } /** @@ -501,6 +533,12 @@ public int hashCode() this.getBaseDN().hashCode()); hash = 31 * hash + (null == this.getGlobalPhonePrefix() ? 0 : this.getGlobalPhonePrefix().hashCode()); + hash = 31 * hash + (null == this.getCustomQuery() ? 0 : + this.getCustomQuery().hashCode()); + hash = 32 * hash + (null == this.getQueryMode() ? 0 : + this.getQueryMode().hashCode()); + hash = 33 * hash + (this.isMangleQuery() ? 1 : 0); + hash = 34 * hash + (this.isPhotoInline() ? 1 : 0); return hash; } @@ -544,6 +582,87 @@ public void setMailSuffix(String suffix) this.mailSuffix = suffix; } + /** + * Gets the mode how the LDAP query is constructed. + * @return the mode how the LDAP query is constructed. + */ + @Override + public String getQueryMode() + { + return this.queryMode; + } + + /** + * Sets the mode how the LDAP query is constructed. + * @param queryMode the mode how the LDAP query is constructed. + */ + @Override + public void setQueryMode(String queryMode) + { + this.queryMode = queryMode; + } + + /** + * Gets the user-defined LDAP query. + * @return the user-defined LDAP query. + */ + @Override + public String getCustomQuery() + { + return this.customQuery; + } + + /** + * Sets the user-defined LDAP query. + * @param query the user-defined LDAP query. + */ + @Override + public void setCustomQuery(String query) + { + this.customQuery = query; + } + + /** + * Gets whether the query term gets mangled with wildcards. + * @return whether the query term gets mangled with wildcards. + */ + @Override + public boolean isMangleQuery() + { + return this.mangleQuery; + } + + /** + * Sets whether the query term gets mangled with wildcards. + * @param mangle whether the query term gets mangled with wildcards. + */ + @Override + public void setMangleQuery(boolean mangle) + { + this.mangleQuery = mangle; + } + + /** + * Gets whether photos are retrieved along with the other attributes. + * @return whether photos are retrieved along with the other attributes. + */ + @Override + public boolean isPhotoInline() + { + return this.photoInline; + } + + /** + * Sets whether photos are retrieved along with the other attributes. + * @param inline whether photos are retrieved along with the other + * attributes. + */ + @Override + public void setPhotoInline(boolean inline) + { + this.photoInline = inline; + } + /** * Returns work phone fields that we will lookup. * @@ -700,6 +819,18 @@ public void persistentSave() configService.setProperty( directoriesPath + "." + node + ".globalPhonePrefix", this.getGlobalPhonePrefix()); + configService.setProperty( + directoriesPath + "." + node + ".querymode", + this.getQueryMode()); + configService.setProperty( + directoriesPath + "." + node + ".customquery", + this.getCustomQuery()); + configService.setProperty( + directoriesPath + "." + node + ".mangle", + this.isMangleQuery()); + configService.setProperty( + directoriesPath + "." + node + ".inlinephoto", + this.isPhotoInline()); } /** @@ -852,6 +983,48 @@ public void persistentLoad(String name) if (ret != null) setGlobalPhonePrefix(ret); } + + if(configService.getProperty(directoriesPath + "." + node + + ".querymode") != null) + { + String ret = (String)configService.getProperty( + directoriesPath + "." + node + ".querymode"); + + if (ret != null) + setQueryMode(ret); + } + + if(configService.getProperty(directoriesPath + "." + node + + ".customquery") != null) + { + String ret = (String)configService.getProperty( + directoriesPath + "." + node + ".customquery"); + + if (ret != null) + setCustomQuery(ret); + } + + if(configService.getProperty(directoriesPath + "." + node + + ".mangle") != null) + { + Boolean ret = Boolean.parseBoolean( + (String)configService.getProperty( + directoriesPath + "." + node + ".mangle")); + + if (ret != null) + setMangleQuery(ret); + } + + if(configService.getProperty(directoriesPath + "." + node + + ".inlinephoto") != null) + { + Boolean ret = Boolean.parseBoolean( + (String)configService.getProperty( + directoriesPath + "." + node + ".inlinephoto")); + + if (ret != null) + setPhotoInline(ret); + } } /** @@ -913,6 +1086,18 @@ public void persistentRemove() configService.setProperty( directoriesPath + "." + node, null); + configService.setProperty( + directoriesPath + "." + node + ".querymode", + null); + configService.setProperty( + directoriesPath + "." + node + ".customquery", + null); + configService.setProperty( + directoriesPath + "." + node + ".mangle", + null); + configService.setProperty( + directoriesPath + "." + node + ".inlinephoto", + null); } /** @@ -932,7 +1117,11 @@ public String toString() this.getBindDN() + ", \n" + this.getPassword() + ", \n" + this.getBaseDN() + ", \n" + - this.getGlobalPhonePrefix() + " \n}"; + this.getGlobalPhonePrefix() + " \n" + + this.queryMode + " \n" + + this.customQuery + " \n" + + this.mangleQuery + " \n" + + this.photoInline + " \n}"; } @Override diff --git a/src/net/java/sip/communicator/impl/ldap/LdapPersonFoundImpl.java b/src/net/java/sip/communicator/impl/ldap/LdapPersonFoundImpl.java index 357e2e630..300222438 100644 --- a/src/net/java/sip/communicator/impl/ldap/LdapPersonFoundImpl.java +++ b/src/net/java/sip/communicator/impl/ldap/LdapPersonFoundImpl.java @@ -62,6 +62,11 @@ public class LdapPersonFoundImpl */ private String department = null; + /** + * the photo found in the directory for this person. + */ + private byte[] photo = null; + /** * the set storing the mail addresses */ @@ -145,11 +150,9 @@ public String getDisplayName() * @return the photo found in the the directory for this person * or null if not found */ - public byte[] fetchPhoto() + public void fetchPhoto() { - byte[] photo; - photo = this.server.fetchPhotoForPerson(this.dn); - return photo; + this.photo = this.server.fetchPhotoForPerson(this.dn); } /** @@ -235,6 +238,31 @@ public String getDepartment() return this.department; } + /** + * Gets the photo found in the directory for this person. + * @return the photo found in the directory for this person. + */ + @Override + public byte[] getPhoto() + { + if (this.photo == null) + { + this.fetchPhoto(); + } + + return this.photo; + } + + /** + * Set the photo found in the directory for this person. + * @param photo the photo found in the directory for this person. + */ + @Override + public void setPhoto(byte[] photo) + { + this.photo = photo; + } + /** * Adds a mail address to this person * diff --git a/src/net/java/sip/communicator/plugin/ldap/configform/DirectorySettingsForm.java b/src/net/java/sip/communicator/plugin/ldap/configform/DirectorySettingsForm.java index 01beefb81..71660d097 100644 --- a/src/net/java/sip/communicator/plugin/ldap/configform/DirectorySettingsForm.java +++ b/src/net/java/sip/communicator/plugin/ldap/configform/DirectorySettingsForm.java @@ -12,6 +12,7 @@ import java.util.List; import javax.swing.*; +import javax.swing.border.*; import net.java.sip.communicator.plugin.ldap.*; import net.java.sip.communicator.service.ldap.*; @@ -66,6 +67,27 @@ public class DirectorySettingsForm */ private JTextField homePhoneField = new JTextField(); + /** Radio button for the default query selection. */ + private JRadioButton rdoDefaultQuery + = new SIPCommRadioButton( + Resources.getString("impl.ldap.QUERY_DEFAULT")); + + /** Radio button for the default query selection. */ + private JRadioButton rdoCustomQuery + = new SIPCommRadioButton( + Resources.getString("impl.ldap.QUERY_CUSTOM")); + + /** Textbox for the custom LDAP query. */ + private JTextArea txtCustomQuery = new JTextArea("", 15, 40); + + /** Checkbox to indicate the automatic wildcard query term expansion */ + private JCheckBox chkMangleQuery = new SIPCommCheckBox( + Resources.getString("impl.ldap.QUERY_CUSTOM_AUTO_WILDCARD")); + + /** Checkbox to indicate whether photos should be retrieved inline */ + private JCheckBox chkPhotoInline = new SIPCommCheckBox( + Resources.getString("impl.ldap.QUERY_PHOTO_INLINE")); + /** * component holding the name */ @@ -190,8 +212,11 @@ public DirectorySettingsForm() setSize(new Dimension(400, 400)); setPreferredSize(new Dimension(400, 400)); - pane.addTab("General", getContentPanel()); - pane.addTab("Fields", getFieldsPanel()); + pane.addTab(Resources.getString("impl.ldap.GENERAL"), + getContentPanel()); + pane.addTab(Resources.getString("impl.ldap.FIELDS"), getFieldsPanel()); + pane.addTab(Resources.getString("impl.ldap.QUERY"), + getCustomQueryPanel()); btnPanel.add(saveBtn); btnPanel.add(cancelBtn); @@ -709,6 +734,42 @@ public JPanel getContentPanel() return contentPanel; } + /** + * Creates the for the definition of a custom query. + * + * @return a panel for a custom query definition. + */ + private JPanel getCustomQueryPanel() + { + rdoDefaultQuery.addActionListener(this); + rdoCustomQuery.addActionListener(this); + + JPanel p = new TransparentPanel(); + p.setLayout(new BorderLayout()); + + JPanel options = new TransparentPanel(); + options.setLayout(new BoxLayout(options, BoxLayout.Y_AXIS)); + options.add(rdoDefaultQuery); + options.add(rdoCustomQuery); + p.add(options, BorderLayout.NORTH); + + p.add(txtCustomQuery, BorderLayout.CENTER); + txtCustomQuery.setBorder(new LineBorder(Color.black)); + txtCustomQuery.setLineWrap(true); + txtCustomQuery.setWrapStyleWord(false); + + JPanel hints = new TransparentPanel(); + hints.setLayout(new BoxLayout(hints, BoxLayout.Y_AXIS)); + hints.add( + new JLabel(Resources.getString("impl.ldap.QUERY_CUSTOM_HINT", + new String[] { "" }))); + hints.add(chkMangleQuery); + hints.add(chkPhotoInline); + p.add(hints, BorderLayout.SOUTH); + + return p; + } + /** * Loads the information from the LdapDirectorySettings instance * into the UI. @@ -758,6 +819,16 @@ public void loadData(LdapDirectorySettings settings) this.homePhoneField.setText( mergeStrings(settings.getHomePhoneSearchFields())); this.prefixField.setText(settings.getGlobalPhonePrefix()); + this.rdoDefaultQuery.setSelected( + !"custom".equals(settings.getQueryMode())); + this.rdoCustomQuery.setSelected( + "custom".equals(settings.getQueryMode())); + this.txtCustomQuery.setText(settings.getCustomQuery()); + this.chkMangleQuery.setSelected(settings.isMangleQuery()); + this.chkPhotoInline.setSelected(settings.isPhotoInline()); + + txtCustomQuery.setEditable(rdoCustomQuery.isSelected()); + txtCustomQuery.setEnabled(rdoCustomQuery.isSelected()); } /** @@ -857,6 +928,12 @@ public void saveData(LdapDirectorySettings settings) settings.setHomePhoneSearchFields( mergeString(homePhoneField.getText())); settings.setGlobalPhonePrefix(prefixField.getText()); + settings.setQueryMode(rdoCustomQuery.isSelected() + ? "custom" + : null); + settings.setCustomQuery(txtCustomQuery.getText()); + settings.setMangleQuery(chkMangleQuery.isSelected()); + settings.setPhotoInline(chkPhotoInline.isSelected()); } /** @@ -925,6 +1002,18 @@ else if(src == authList) bindDNField.setEnabled(authList.getSelectedIndex() == 1); passwordField.setEnabled(authList.getSelectedIndex() == 1); } + else if (src == rdoDefaultQuery) + { + txtCustomQuery.setEnabled(false); + txtCustomQuery.setEditable(false); + rdoCustomQuery.setSelected(false); + } + else if (src == rdoCustomQuery) + { + txtCustomQuery.setEnabled(true); + txtCustomQuery.setEditable(true); + rdoDefaultQuery.setSelected(false); + } } /** diff --git a/src/net/java/sip/communicator/service/ldap/LdapDirectorySettings.java b/src/net/java/sip/communicator/service/ldap/LdapDirectorySettings.java index 1a0e3512c..23004c0e1 100644 --- a/src/net/java/sip/communicator/service/ldap/LdapDirectorySettings.java +++ b/src/net/java/sip/communicator/service/ldap/LdapDirectorySettings.java @@ -263,6 +263,55 @@ public interface LdapDirectorySettings */ public void setGlobalPhonePrefix(String prefix); + /** + * Gets the mode how the LDAP query is constructed. + * @return the mode how the LDAP query is constructed. + */ + public String getQueryMode(); + + /** + * Sets the mode how the LDAP query is constructed. + * @param queryMode the mode how the LDAP query is constructed. + */ + public void setQueryMode(String queryMode); + + /** + * Gets the user-defined LDAP query. + * @return the user-defined LDAP query. + */ + public String getCustomQuery(); + + /** + * Sets the user-defined LDAP query. + * @param query the user-defined LDAP query. + */ + public void setCustomQuery(String query); + + /** + * Gets whether the query term gets mangled with wildcards. + * @return whether the query term gets mangled with wildcards. + */ + public boolean isMangleQuery(); + + /** + * Sets whether the query term gets mangled with wildcards. + * @param mangle whether the query term gets mangled with wildcards. + */ + public void setMangleQuery(boolean mangle); + + /** + * Gets whether photos are retrieved along with the other attributes. + * @return whether photos are retrieved along with the other attributes. + */ + public boolean isPhotoInline(); + + /** + * Sets whether photos are retrieved along with the other attributes. + * @param inline whether photos are retrieved along with the other + * attributes. + */ + public void setPhotoInline(boolean inline); + /** * Saves these settings through the configuration service * @@ -286,26 +335,6 @@ public interface LdapDirectorySettings */ public void persistentRemove(); - /** - * Checks if both LdapDirectorySettings instance have the same content - * - * @param other object to compare - * @return whether both LdapDirectorySettings instance have the same content - * - * @see java.lang.Object#equals - */ - public boolean equals(LdapDirectorySettings other); - - /** - * Returns the hash code for this instance. - * It has to be consistent with equals. - * - * @return the hash code dor this instance - * - * @see java.lang.Object#hashCode - */ - public int hashCode(); - /** * Clone this object. * diff --git a/src/net/java/sip/communicator/service/ldap/LdapPersonFound.java b/src/net/java/sip/communicator/service/ldap/LdapPersonFound.java index 20a6d213e..a11263e76 100644 --- a/src/net/java/sip/communicator/service/ldap/LdapPersonFound.java +++ b/src/net/java/sip/communicator/service/ldap/LdapPersonFound.java @@ -48,12 +48,22 @@ public interface LdapPersonFound public String getDisplayName(); /** - * Tries to fetch the photo in the the directory for this person - * - * @return the photo found in the the directory for this person - * or null if not found + * Tries to fetch the photo in the the directory for this person. If + * successful, the binary photo is available from {@link #getPhoto()} + */ + public void fetchPhoto(); + + /** + * Gets the photo found in the directory for this person. + * @return the photo found in the directory for this person. + */ + public byte[] getPhoto(); + + /** + * Set the photo found in the directory for this person. + * @param photo the photo found in the directory for this person. */ - public byte[] fetchPhoto(); + public void setPhoto(byte[] photo); /** * Sets the first name found in the the directory for this person