Commit 3da93c8d authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

1) VCard mapping is now allowing multiple fields. JM-885

2) Loaded vcards are now updated when LDAP mapping is modified. JM-886

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5899 b35dd754-fafc-0310-a699-88a17e54d16e
parent 2d47858b
......@@ -2,7 +2,7 @@
<module version="4" relativePaths="true" type="JAVA_MODULE">
<component name="ModuleRootManager" />
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output url="file://$MODULE_DIR$/work/classes" />
<exclude-output />
<exclude-exploded />
<content url="file://$MODULE_DIR$">
......@@ -148,10 +148,10 @@
<CLASSES>
<root url="jar://$MODULE_DIR$/build/lib/merge/dom4j.jar!/" />
</CLASSES>
<JAVADOC>
<root url="http://www.dom4j.org/apidocs/" />
</JAVADOC>
<SOURCES />
<JAVADOC />
<SOURCES>
<root url="file://$MODULE_DIR$/../../java/dom4j-1.6.1/src/java" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library" exported="">
......@@ -334,6 +334,15 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../Documents and Settings/gato/.IntelliJIdea60/config/plugins/Clover_for_IDEA_2848.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntryProperties />
</component>
</module>
......
......@@ -300,7 +300,8 @@
<module fileurl="file://$PROJECT_DIR$/Wildfire.iml" filepath="$PROJECT_DIR$/Wildfire.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="true" project-jdk-name="JDK 1.5.0" />
<component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="true" project-jdk-name="JDK 1.5.0" project-jdk-type="JavaSDK" />
<component name="ProjectRunConfigurationManager" />
<component name="ProjectRunConfigurationManager" />
<component name="RmicSettings">
<option name="IS_EANABLED" value="false" />
......
......@@ -470,8 +470,8 @@ public class LdapUserProfile {
JiveGlobals.setXMLProperty("provider.vcard.className", LdapVCardProvider.class.getName());
// Save duplicated fields in LdapManager (should be removed in the future)
LdapManager.getInstance().setNameField(name.replaceAll("(\\{)([\\d\\D]+)(})", "$2"));
LdapManager.getInstance().setEmailField(email.replaceAll("(\\{)([\\d\\D]+)(})", "$2"));
LdapManager.getInstance().setNameField(name.replaceAll("(\\{)([\\d\\D&&[^}]]+)(})", "$2"));
LdapManager.getInstance().setEmailField(email.replaceAll("(\\{)([\\d\\D&&[^}]]+)(})", "$2"));
}
/**
......
......@@ -282,10 +282,9 @@ public class LdapUserTester {
public PropertyMapping(String displayFormat) {
this.displayFormat = displayFormat;
for (String field : displayFormat.trim().split(",")) {
if (field.trim().startsWith("{")) {
fields.add(field.trim().replaceAll("(\\{)([\\d\\D]+)(})", "$2"));
}
StringTokenizer st = new StringTokenizer(displayFormat.trim(), ", //{}");
while (st.hasMoreTokens()) {
fields.add(st.nextToken().replaceFirst("(\\{)([\\d\\D&&[^}]]+)(})", "$2"));
}
}
......
......@@ -14,20 +14,14 @@ import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Node;
import org.jivesoftware.util.AlreadyExistsException;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.NotFoundException;
import org.jivesoftware.util.*;
import org.jivesoftware.wildfire.vcard.VCardManager;
import org.jivesoftware.wildfire.vcard.VCardProvider;
import org.xmpp.packet.JID;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* Read-only LDAP provider for vCards.Configuration consists of adding a provider:<p/>
......@@ -103,13 +97,19 @@ import java.util.Set;
*
* @author rkelly
*/
public class LdapVCardProvider implements VCardProvider {
public class LdapVCardProvider implements VCardProvider, PropertyEventListener {
private LdapManager manager;
private VCardTemplate template;
public LdapVCardProvider() {
manager = LdapManager.getInstance();
initTemplate();
// Listen to property events so that the template is always up to date
PropertyEventDispatcher.addListener(this);
}
private void initTemplate() {
String property = JiveGlobals.getXMLProperty("ldap.vcard-mapping");
Log.debug("Found vcard mapping: '" + property);
try {
......@@ -143,8 +143,7 @@ public class LdapVCardProvider implements VCardProvider {
javax.naming.directory.Attribute attr = attrs.get(attribute);
String value;
if (attr == null) {
Log.debug("No ldap value found for attribute '" + attribute
+ "'");
Log.debug("No ldap value found for attribute '" + attribute + "'");
value = "";
}
else {
......@@ -197,6 +196,27 @@ public class LdapVCardProvider implements VCardProvider {
return true;
}
public void propertySet(String property, Map params) {
//Ignore
}
public void propertyDeleted(String property, Map params) {
//Ignore
}
public void xmlPropertySet(String property, Map params) {
if ("ldap.vcard-mapping".equals(property)) {
initTemplate();
// Reset cache of vCards
VCardManager.getInstance().reset();
}
}
public void xmlPropertyDeleted(String property, Map params) {
//Ignore
}
/**
* Class to hold a <code>Document</code> representation of a vcard mapping
* and unique attribute placeholders. Used by <code>VCard</code> to apply
......@@ -231,10 +251,11 @@ public class LdapVCardProvider implements VCardProvider {
Node node = element.node(i);
if (node instanceof Element) {
Element emement = (Element) node;
String[] attrs = emement.getTextTrim().split(",");
for (String string : attrs) {
StringTokenizer st = new StringTokenizer(emement.getTextTrim(), ", //{}");
while (st.hasMoreTokens()) {
// Remove enclosing {}
string = string.replaceAll("(\\{)([\\d\\D]+)(})", "$2");
String string = st.nextToken().replaceAll("(\\{)([\\d\\D&&[^}]]+)(})", "$2");
Log.debug("VCardTemplate: found attribute " + string);
set.add(string);
}
......@@ -267,16 +288,20 @@ public class LdapVCardProvider implements VCardProvider {
if (node instanceof Element) {
Element emement = (Element) node;
String[] attrs = emement.getTextTrim().split(",");
Object[] values = new String[attrs.length];
String format = emement.getStringValue();
for (int j = 0; j < attrs.length; j++) {
// Remove enclosing {}
String attrib = attrs[j].replaceAll("(\\{)([\\d\\D]+)(})", "$2");
values[j] = map.get(attrib);
format = format.replaceFirst("(\\{)([\\d\\D]+)(})", "$1" + j + "$3");
String elementText = emement.getTextTrim();
if (elementText != null && !"".equals(elementText)) {
String format = emement.getStringValue();
StringTokenizer st = new StringTokenizer(elementText, ", //{}");
while (st.hasMoreTokens()) {
// Remove enclosing {}
String field = st.nextToken();
String attrib = field.replaceAll("(\\{)(" + field + ")(})", "$2");
String value = map.get(attrib);
format = format.replaceFirst("(\\{)(" + field + ")(})", value);
}
emement.setText(format);
}
emement.setText(MessageFormat.format(format, values));
treeWalk(emement, map);
}
}
......
......@@ -286,6 +286,13 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
UserEventDispatcher.removeListener(eventHandler);
}
/**
* Resets the manager state. The cache where loaded vCards are stored will be flushed.
*/
public void reset() {
vcardCache.clear();
}
public Iterator<String> getFeatures() {
ArrayList<String> features = new ArrayList<String>();
features.add("vcard-temp");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment