<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:'times new roman', 'new york', times, serif;font-size:12pt"><div>Hello</div><div><br></div><div>I have had a situation like this las year, I needed to import users to Newsletter subscription from external XML file.</div><div><br></div><div>Look into this source , I could help you</div><div><br></div><div><div>import org.openuri.fdadEmailSubscribers.impl.RootDocumentImpl;</div><div>import org.openuri.fdadEmailSubscribers.SubscriberDocument;</div><div>import org.apache.xmlbeans.XmlException;</div><div>import org.apache.xmlbeans.XmlObject;</div><div>import org.opencms.file.CmsUser;</div><div>import org.opencms.file.CmsObject;</div><div>import org.opencms.main.CmsException;</div><div>import org.opencms.main.OpenCms;</div><div>import org.opencms.jsp.CmsJspActionElement;</div><div>import org.opencms.util.CmsStringUtil;</div><div><br></div><div>import
java.io.File;</div><div>import java.io.IOException;</div><div>import java.util.Locale;</div><div>import java.util.Collections;</div><div><br></div><div>import com.alkacon.opencms.newsletter.CmsNewsletterManager;</div><div><br></div><div>import javax.servlet.jsp.JspWriter;</div><div><br></div><div>/**</div><div> * Created by IntelliJ IDEA.</div><div> * User: Vahe Momjyan</div><div> * Date: 03.09.2009</div><div> * Time: 16:55:14</div><div> */</div><div>public class CmsNewsletterUserImport {</div><div><br></div><div> /**</div><div> * The admin CmsObject that is used for user/group operations.</div><div> */</div><div> private CmsObject m_adminCms;</div><div><br></div><div> /**</div><div> * The name of the newsletter module.</div><div> */</div><div> public static final String MODULE_NAME
= CmsNewsletterManager.class.getPackage().getName();</div><div><br></div><div> /**</div><div> * The default password for all newsletter users, can/should be overwritten in the module parameter.</div><div> */</div><div> private static final String PASSWORD_USER = "Uw82-Qn!";</div><div><br></div><div> /**</div><div> * The full name of newletter subscription mailing list.</div><div> */</div><div> private static final String NESLETTER_OFQN = "nl_Newsletter/Mailing List";</div><div><br></div><div><br></div><div> public CmsNewsletterUserImport(CmsJspActionElement jsp) {</div><div> this.m_adminCms = jsp.getCmsObject();</div><div><br></div><div> }</div><div><br></div><div><br></div><div> protected CmsUser
createNewsletterUser(String email, String groupName, boolean activate, Locale locale) {</div><div><br></div><div> CmsUser user = null;</div><div> // create additional infos containing the active flag set to passed parameter</div><div><br></div><div> try {</div><div> String ouFqn = getAdminCms().readGroup(groupName).getOuFqn();</div><div> try {</div><div> // first try to read the user</div><div> user = getAdminCms().readUser(ouFqn + email);</div><div> } catch (CmsException e) {</div><div> // user does not exist</div><div>
}</div><div> if (user == null) {</div><div> // create the user with additional infos</div><div> user = getAdminCms().createUser(</div><div> ouFqn + email,</div><div> getPassword(),</div><div> "Alkacon OpenCms Newsletter",</div><div> Collections.EMPTY_MAP);</div><div> // set the users email address</div><div>
user.setEmail(email);</div><div> if (!activate) {</div><div> // set the additional info as marker that the new user is currently not active at all</div><div> user.setAdditionalInfo(CmsNewsletterManager.USER_ADDITIONALINFO_ACTIVE, Boolean.FALSE);</div><div> }</div><div> } else {</div><div> Object o = user.getAdditionalInfo(CmsNewsletterManager.USER_ADDITIONALINFO_ACTIVE + groupName);</div><div> if (o != null) {</div><div> // user tried to subscribe
to this mailing list group before, return null to show error message</div><div> return null;</div><div> }</div><div> }</div><div> user.setAdditionalInfo(CmsNewsletterManager.USER_ADDITIONALINFO_ACTIVE + groupName, Boolean.valueOf(activate));</div><div> user.setAdditionalInfo("Language", locale.getLanguage());</div><div> if (activate && user.getAdditionalInfo().get(CmsNewsletterManager.USER_ADDITIONALINFO_ACTIVE) != null) {</div><div> // remove flag that this user is not active at all</div><div>
user.deleteAdditionalInfo(CmsNewsletterManager.USER_ADDITIONALINFO_ACTIVE);</div><div> }</div><div> // write the user</div><div> getAdminCms().writeUser(user);</div><div> // add the user to the given mailing list group</div><div> getAdminCms().addUserToGroup(user.getName(), groupName);</div><div> } catch (CmsException e) {</div><div> // error creating user or modifying user</div><div> }</div><div> return user;</div><div> }</div><div><br></div><div> /**</div><div> * Returns the admin CmsObject that is used for user/group
operations.<p></div><div> *</div><div> * @return the admin CmsObject that is used for user/group operations</div><div> */</div><div> private CmsObject getAdminCms() {</div><div><br></div><div> return m_adminCms;</div><div> }</div><div><br></div><div> /**</div><div> * Returns the password to use for all newsletter users.<p></div><div> *</div><div> * @return the password to use for all newsletter users</div><div> */</div><div> public static String getPassword() {</div><div><br></div><div> return OpenCms.getModuleManager().getModule(CmsNewsletterManager.MODULE_NAME).getParameter(CmsNewsletterManager.MODULE_PARAM_PASSWORD_USER, PASSWORD_USER);</div><div>
}</div><div><br></div><div> public void ImportUsersFromXML(String xmlfilename, JspWriter out) throws XmlException, IOException {</div><div> // Input XML</div><div> File xmlFile = new File(xmlfilename);</div><div><br></div><div> // Bind the instance to the generated XMLBeans type.</div><div> RootDocumentImpl document = null;</div><div><br></div><div> document = (RootDocumentImpl) XmlObject.Factory.parse(xmlFile);</div><div><br></div><div> int counter = 0;</div><div> SubscriberDocument.Subscriber[] allNewSubscribers = document.getRoot().getSubscriberArray();</div><div><br></div><div> //get default locale</div><div> Locale defLocale =
OpenCms.getWorkplaceManager().getDefaultLocale();</div><div> for (SubscriberDocument.Subscriber each : allNewSubscribers) {</div><div><br></div><div> if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(each.getEmail())) {</div><div> createNewsletterUser(each.getEmail(), NESLETTER_OFQN, true, defLocale);</div><div> counter++;</div><div> }</div><div> else</div><div> {</div><div> out.write("User not imported<BR><b>" + each.getEmail() + "</b><br>");</div><div> }</div><div>
}</div><div> out.write("Total users imported: " + counter);</div><div> }</div><div>}</div></div><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><br><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Ruben Martín <ruben.martin.ramos@gmail.com><br><b><span style="font-weight: bold;">To:</span></b> opencms-dev@opencms.org<br><b><span style="font-weight: bold;">Sent:</span></b> Thu, April 8, 2010 1:22:00 PM<br><b><span style="font-weight: bold;">Subject:</span></b> [opencms-dev] IMPORT USERS FROM EXTERNAL DATABASE TO OPENCMS<br></font><br>
Hi guys ,<br><br>Is There any way of import users from an external database and mapping to the fields of the OAMP register module fields ? We could use LDAP but it is mandatory to import every data of the users into the opencms.<br>
<br>Is there any way ?<br><br>Thanks in advance<br><br><br>
</div></div><div style="position:fixed"></div>
</div><br>
</body></html>