logger.info(String.format("Adding Sone from OwnIdentity: %s", ownIdentity));
synchronized (sones) {
final Sone sone;
- sone = database.newSoneBuilder().by(ownIdentity.getId()).local().build(Optional.<SoneCreated>absent());
+ sone = database.newSoneBuilder().by(ownIdentity.getId()).local().using(new Client("Sone", SonePlugin.VERSION.toString())).build(Optional.<SoneCreated>absent());
sone.modify().setLatestEdition(Numbers.safeParseLong(ownIdentity.getProperty("Sone.LatestEdition"), (long) 0)).update();
- sone.setClient(new Client("Sone", SonePlugin.VERSION.toString()));
sone.setKnown(true);
/* TODO - load posts ’n stuff */
sones.put(ownIdentity.getId(), sone);
return null;
}
- Sone sone = new DefaultSone(new MemoryDatabase(null), originalSone.getId(), originalSone.isLocal());
-
SimpleXML soneXml;
try {
soneXml = SimpleXML.fromDocument(document);
} catch (NullPointerException npe1) {
/* for some reason, invalid XML can cause NPEs. */
- logger.log(Level.WARNING, String.format("XML for Sone %s can not be parsed!", sone), npe1);
+ logger.log(Level.WARNING, String.format("XML for Sone %s can not be parsed!", originalSone), npe1);
return null;
}
+ SimpleXML clientXml = soneXml.getNode("client");
+ Client soneClient = originalSone.getClient();
+ if (clientXml != null) {
+ String clientName = clientXml.getValue("name", null);
+ String clientVersion = clientXml.getValue("version", null);
+ if ((clientName == null) || (clientVersion == null)) {
+ logger.log(Level.WARNING, String.format("Download Sone %s with client XML but missing name or version!", originalSone));
+ return null;
+ }
+ soneClient = new Client(clientName, clientVersion);
+ }
+
+ Sone sone = new DefaultSone(new MemoryDatabase(null), originalSone.getId(), originalSone.isLocal(), soneClient);
+
Integer protocolVersion = null;
String soneProtocolVersion = soneXml.getValue("protocol-version", null);
if (soneProtocolVersion != null) {
return null;
}
- SimpleXML clientXml = soneXml.getNode("client");
- if (clientXml != null) {
- String clientName = clientXml.getValue("name", null);
- String clientVersion = clientXml.getValue("version", null);
- if ((clientName == null) || (clientVersion == null)) {
- logger.log(Level.WARNING, String.format("Download Sone %s with client XML but missing name or version!", sone));
- return null;
- }
- sone.setClient(new Client(clientName, clientVersion));
- }
-
SimpleXML profileXml = soneXml.getNode("profile");
if (profileXml == null) {
/* TODO - mark Sone as bad. */
Client getClient();
/**
- * Sets the client used by this Sone.
- *
- * @param client
- * The client used by this Sone, or {@code null}
- * @return This Sone (for method chaining)
- */
- Sone setClient(Client client);
-
- /**
* Returns whether this Sone is known.
*
* @return {@code true} if this Sone is known, {@code false} otherwise
import static com.google.common.base.Preconditions.checkState;
+import net.pterodactylus.sone.data.Client;
import net.pterodactylus.sone.database.SoneBuilder;
import net.pterodactylus.sone.freenet.wot.Identity;
protected String id;
protected boolean local;
+ protected Client client;
@Override
public SoneBuilder by(String id) {
return this;
}
+ @Override
+ public SoneBuilder using(Client client) {
+ this.client = client;
+ return this;
+ }
+
protected void validate() throws IllegalStateException {
checkState(id != null, "id must not be null");
+ checkState(client != null, "client must not be null");
}
}
private volatile Profile profile = new Profile(this);
/** The client used by the Sone. */
- private volatile Client client;
+ private final Client client;
/** Whether this Sone is known. */
private volatile boolean known;
* @param local
* {@code true} if the Sone is a local Sone, {@code false} otherwise
*/
- public DefaultSone(Database database, String id, boolean local) {
+ public DefaultSone(Database database, String id, boolean local, Client client) {
this.database = database;
this.id = id;
this.local = local;
+ this.client = client;
rootAlbum = new DefaultAlbumBuilder(database, this, null).build();
}
return client;
}
- public Sone setClient(Client client) {
- this.client = client;
- return this;
- }
-
public boolean isKnown() {
return known;
}
@Override
public Sone build(Optional<SoneCreated> soneCreated) throws IllegalStateException {
validate();
- Sone sone = new DefaultSone(database, id, local);
+ Sone sone = new DefaultSone(database, id, local, client);
if (soneCreated.isPresent()) {
soneCreated.get().soneCreated(sone);
}
package net.pterodactylus.sone.database;
+import net.pterodactylus.sone.data.Client;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.freenet.wot.Identity;
SoneBuilder by(String id);
SoneBuilder local();
+ SoneBuilder using(Client client);
Sone build(Optional<SoneCreated> soneCreated) throws IllegalStateException;
* don’t use create=true above, we don’t want
* the empty shell.
*/
- sone = Optional.<Sone>of(new DefaultSone(database, soneId, false));
+ sone = Optional.<Sone>of(new DefaultSone(database, soneId, false, null));
}
parts.add(new SonePart(sone.get()));
line = line.substring(50);