diff --git a/htroot/ViewProfile.java b/htroot/ViewProfile.java index f87d9c667..5c31cee31 100644 --- a/htroot/ViewProfile.java +++ b/htroot/ViewProfile.java @@ -50,6 +50,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Properties; @@ -139,7 +140,7 @@ public class ViewProfile { } Map.Entry entry; // all known keys which should be set as they are - ArrayList knownKeys = new ArrayList(); + HashSet knownKeys = new HashSet(); knownKeys.add("name"); knownKeys.add("nickname"); // knownKeys.add("homepage");//+http @@ -160,7 +161,7 @@ public class ViewProfile { int numUnknown = 0; while (i.hasNext()) { entry = (Map.Entry) i.next(); - String key = (String) entry.getKey(); + String key = ((String) entry.getKey()); String value = new String(); // only comments get "wikified" @@ -172,16 +173,20 @@ public class ViewProfile { } //all known Keys which should be set as they are - if ((knownKeys.contains(key)) && (value.length() > 0)) { - prop.put("success_" + key, 1); - prop.put("success_" + key + "_value", value); - //special handling, hide flower if no icq uin is set - } else if ((key.equals("homepage")) && (value.length() > 0)) { - if (!(value.startsWith("http"))) { - value = "http://" + value; - } - prop.put("success_" + key, 1); - prop.put("success_" + key + "_value", value); + if (knownKeys.contains(key)) { + if (value.length() > 0) { + prop.put("success_" + key, 1); + prop.put("success_" + key + "_value", value); + } + //special handling, hide flower if no icq uin is set + } else if (key.equals("homepage")) { + if (value.length() > 0) { + if (!(value.startsWith("http"))) { + value = "http://" + value; + } + prop.put("success_" + key, 1); + prop.put("success_" + key + "_value", value); + } //This will display unknown items(of newer versions) as plaintext } else { //unknown diff --git a/htroot/ViewProfile.xml b/htroot/ViewProfile.xml new file mode 100644 index 000000000..a4f1e7312 --- /dev/null +++ b/htroot/ViewProfile.xml @@ -0,0 +1,30 @@ + + + + #(success)#Wrong access of this page + ::The requested peer is unknown or a potential peer.The profile can't be fetched. + ::The peer #[peername]# is not online. + ::Peer profile successfully fetched + #(/success)# + + + #(success)#:::::: + #(name)#::#(/name)# + #(nickname)#::#(/nickname)# + #(homepage)#::#(/homepage)# + #(email)#::#(/email)# + #(icq)#::#(/icq)# + #(jabber)#::#(/jabber)# + #(yahoo)#::#(/yahoo)# + #(msn)#::#(/msn)# + #(comment)#::#(/comment)# + + + #{other}# + + + + + #{/other}# + #(/success)# + \ No newline at end of file diff --git a/source/de/anomic/soap/services/AdminService.java b/source/de/anomic/soap/services/AdminService.java index 882b8c5a7..c3780c43e 100644 --- a/source/de/anomic/soap/services/AdminService.java +++ b/source/de/anomic/soap/services/AdminService.java @@ -45,7 +45,12 @@ package de.anomic.soap.services; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.ArrayList; +import java.util.Properties; import java.util.logging.Handler; import java.util.logging.LogRecord; import java.util.logging.Logger; @@ -65,6 +70,7 @@ import de.anomic.server.serverThread; import de.anomic.server.logging.GuiHandler; import de.anomic.soap.AbstractService; import de.anomic.yacy.yacyCore; +import de.anomic.yacy.yacyNewsRecord; import de.anomic.yacy.yacySeed; public class AdminService extends AbstractService { @@ -106,12 +112,25 @@ public class AdminService extends AbstractService { private static final String MSG_FORWARDING_ENABLED = "msgForwardingEnabled"; private static final String MSG_FORWARDING = "msgForwarding"; + // peer profile + private static final String PEERPROFILE_COMMENT = "comment"; + private static final String PEERPROFILE_MSN = "msn"; + private static final String PEERPROFILE_YAHOO = "yahoo"; + private static final String PEERPROFILE_JABBER = "jabber"; + private static final String PEERPROFILE_ICQ = "icq"; + private static final String PEERPROFILE_EMAIL = "email"; + private static final String PEERPROFILE_HOMEPAGE = "homepage"; + private static final String PEERPROFILE_NICKNAME = "nickname"; + private static final String PEERPROFILE_NAME = "name"; + private static final String PEER_PROFILE_FETCH_SUCCESS = "success"; + private static final String PEER_HASH = "hash"; /* ===================================================================== * Used XML Templates * ===================================================================== */ private static final String TEMPLATE_CONFIG_XML = "xml/config_p.xml"; private static final String TEMPLATE_VERSION_XML = "xml/version.xml"; + private static final String TEMPLATE_PROFILE_XML = "ViewProfile.xml"; /** * This function can be used to set a configuration option @@ -665,4 +684,133 @@ public class AdminService extends AbstractService { // convert into dom return convertContentToXML(buffer.toString()); } + + /** + * Function to configure the profile of this peer. + * If a input parameters is null the old value will not be overwritten. + * + * @param name the name of the peer owner + * @param nickname peer owner nick name + * @param homepage + * @param email + * @param icq + * @param jabber + * @param yahoo + * @param msn + * @param comments + * + * @throws AxisFault if authentication failed + */ + public void setLocalPeerProfile( + String name, + String nickname, + String homepage, + String email, + String icq, + String jabber, + String yahoo, + String msn, + String comments + ) throws AxisFault { + // extracting the message context + extractMessageContext(AUTHENTICATION_NEEDED); + + // load peer properties + final Properties profile = new Properties(); + FileInputStream fileIn = null; + try { + fileIn = new FileInputStream(new File("DATA/SETTINGS/profile.txt")); + profile.load(fileIn); + } catch(IOException e) { + throw new AxisFault("Unable to load the peer profile"); + } finally { + if (fileIn != null) try { fileIn.close(); } catch (Exception e) {/* */} + } + + // set all properties + if (name != null) profile.setProperty(PEERPROFILE_NAME,name); + if (nickname != null) profile.setProperty(PEERPROFILE_NICKNAME,nickname); + if (homepage != null) profile.setProperty(PEERPROFILE_HOMEPAGE,homepage); + if (email != null) profile.setProperty(PEERPROFILE_EMAIL,email); + if (icq != null) profile.setProperty(PEERPROFILE_ICQ,icq); + if (jabber != null) profile.setProperty(PEERPROFILE_JABBER,jabber); + if (yahoo != null) profile.setProperty(PEERPROFILE_YAHOO,yahoo); + if (msn != null) profile.setProperty(PEERPROFILE_MSN,msn); + if (comments != null) profile.setProperty(PEERPROFILE_COMMENT,comments); + + // store it + FileOutputStream fileOut = null; + try { + fileOut = new FileOutputStream(new File("DATA/SETTINGS/profile.txt")); + profile.store(fileOut , null ); + + // generate a news message + Properties news = profile; + news.remove(PEERPROFILE_COMMENT); + yacyCore.newsPool.publishMyNews(new yacyNewsRecord("prfleupd", news)); + } catch(IOException e) { + throw new AxisFault("Unable to write profile data to file"); + } finally { + if (fileOut != null) try { fileOut.close(); } catch (Exception e) {/* */} + } + } + + /** + * Returns the peer profile of this peer + * @return a xml document in the same format as returned by function {@link #getPeerProfile(String)} + * @throws Exception + */ + public Document getLocalPeerProfile() throws Exception { + return this.getPeerProfile("localhash"); + } + + /** + * Function to query the profile of a remote peer + * @param peerhash the peer hash + * @return a xml document in the following format + *
+     * <?xml version="1.0" encoding="UTF-8"?>
+     * <profile>
+     * 	<status code="3">Peer profile successfully fetched</status>
+     * 	<name><![CDATA[myName]]></name>
+     * 	<nickname><![CDATA[myNickName]]></nickname>
+     * 	<homepage><![CDATA[http://myhompage.de]]></homepage>
+     * 	<email/>
+     * 	<icq/>
+     * 	<jabber/>
+     * 	<yahoo/>
+     * 	<msn/>
+     * 	<comment><![CDATA[Comments]]></comment>
+     * </profile>
+     * 
+ * @throws Exception if authentication failed + */ + public Document getPeerProfile(String peerhash) throws Exception { + // extracting the message context + extractMessageContext(AUTHENTICATION_NEEDED); + + // generating the template containing the network status information + serverObjects args = new serverObjects(); + args.put(PEER_HASH,peerhash); + + // invoke servlet + serverObjects tp = invokeServlet(TEMPLATE_PROFILE_XML,args); + + // query status + if (tp.containsKey(PEER_PROFILE_FETCH_SUCCESS)) { + String success = tp.get(PEER_PROFILE_FETCH_SUCCESS,"3"); + if (success.equals("0")) throw new AxisFault("Invalid parameters passed to servlet."); + else if (success.equals("1")) throw new AxisFault("The requested peer is unknown or can not be accessed."); + else if (success.equals("2")) throw new AxisFault("The requested peer is offline"); + } else { + throw new AxisFault("Unkown error. Unable to determine profile fetching status."); + } + + + // generate output + byte[] result = buildServletOutput(TEMPLATE_PROFILE_XML, tp); + + // sending back the result to the client + return this.convertContentToXML(result); + } } diff --git a/source/de/anomic/soap/services/admin.wsdl b/source/de/anomic/soap/services/admin.wsdl index d9597a1cd..652765d17 100644 --- a/source/de/anomic/soap/services/admin.wsdl +++ b/source/de/anomic/soap/services/admin.wsdl @@ -33,173 +33,184 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> + + + + - + - + - + - + - + - + - + + + + - + - + - + - + - + - + - + - + - + + + + + - + @@ -208,8 +219,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -218,8 +229,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -228,8 +239,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -238,8 +249,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -248,8 +259,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -258,8 +269,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -268,8 +279,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -278,8 +289,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -288,8 +299,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -298,8 +309,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -308,8 +319,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -318,8 +329,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -328,8 +339,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -338,8 +349,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -348,8 +359,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -358,8 +369,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + @@ -368,18 +379,28 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + + + + + + + + + + + - + @@ -388,8 +409,8 @@ Built on Apr 22, 2006 (06:55:48 PDT)--> - + \ No newline at end of file diff --git a/test/de/anomic/soap/services/AdminServiceTest.java b/test/de/anomic/soap/services/AdminServiceTest.java index e98e58d76..10eb7861b 100644 --- a/test/de/anomic/soap/services/AdminServiceTest.java +++ b/test/de/anomic/soap/services/AdminServiceTest.java @@ -67,4 +67,9 @@ public class AdminServiceTest extends AbstractServiceTest { Document xml = ((AdminService)service).getServerLog(0); System.out.println(XMLUtils.DocumentToString(xml)); } + + public void testGetPeerProfile() throws RemoteException { + Document xml = ((AdminService)service).getPeerProfile("localhash"); + System.out.println(XMLUtils.DocumentToString(xml)); + } } diff --git a/test/de/anomic/soap/services/ServiceTests.java b/test/de/anomic/soap/services/ServiceTests.java index 05a1f752a..fe51621aa 100644 --- a/test/de/anomic/soap/services/ServiceTests.java +++ b/test/de/anomic/soap/services/ServiceTests.java @@ -13,6 +13,7 @@ public class ServiceTests { suite.addTestSuite(StatusServiceTest.class); suite.addTestSuite(BlacklistServiceTest.class); suite.addTestSuite(BookmarkServiceTest.class); + suite.addTestSuite(MessageServiceTest.class); //$JUnit-END$ return suite; }