Implementing new Solution refs #13207

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/social-networking/social-util-library@176745 82a268e6-3cf1-43bd-a215-b396298e98cf
1.7.0-SNAPSHOT
Luca Frosini 5 years ago
parent f69ff631eb
commit 6ad6e357e4

@ -12,10 +12,14 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">

@ -1,4 +1,5 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

@ -76,11 +76,6 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@ -96,10 +91,17 @@
<artifactId>htmlparser</artifactId>
<version>2.1</version>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8</version>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
<scope>test</scope>
</dependency>
</dependencies>

@ -1,9 +1,50 @@
package org.gcube.socialnetworking.token;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.codec.binary.Base64;
public class ReplaceableToken extends Token {
protected String tokenReplacement;
protected String createHref(String baseURL, String attributeName, String attributeValue) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(baseURL);
stringBuilder.append("?");
stringBuilder.append(new String(Base64.encodeBase64(attributeName.getBytes())));
stringBuilder.append("=");
stringBuilder.append(new String(Base64.encodeBase64(attributeValue.getBytes())));
return stringBuilder.toString();
}
protected String createLink(String linkTarget, String linkValue, Map<String, String> additionalAttributes) {
Map<String, String> attributes = new HashMap<>();
if(additionalAttributes!=null) {
attributes.putAll(additionalAttributes);
}
attributes.put("class", "link");
if(!attributes.containsKey("style")) {
attributes.put("style", "font-size:14px;");
}
attributes.put("href", linkTarget);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("<a ");
for(String key : attributes.keySet()) {
stringBuilder.append(key);
stringBuilder.append("=\"");
stringBuilder.append(attributes.get(key));
stringBuilder.append("\" ");
}
stringBuilder.append(">");
stringBuilder.append(linkValue);
stringBuilder.append("</a>");
return stringBuilder.toString();
}
public ReplaceableToken(Token token) {
super(token.token, token.delimiter, token.start, token.end);
this.tokenReplacement = token.token;
@ -14,6 +55,11 @@ public class ReplaceableToken extends Token {
this.tokenReplacement = tokenReplacement;
}
@Override
public String getDelimiter() {
return delimiter.replaceAll("(\r\n|\n)","<br/>");
}
public String getTokenReplacement() {
return tokenReplacement;
}

@ -1,9 +1,23 @@
package org.gcube.socialnetworking.token;
import org.gcube.portal.databook.client.GCubeSocialNetworking;
public class TagToken extends ReplaceableToken {
private boolean replaced;
public TagToken(Token token) {
super(token, "#MY_MASSI_TAG");
super(token);
replaced = false;
}
public String getTokenReplacement() {
if(!replaced) {
String linkTarget = createHref("", GCubeSocialNetworking.HASHTAG_OID, token);
tokenReplacement = createLink(linkTarget, token, null);
replaced = true;
}
return super.getTokenReplacement();
}
}

@ -2,14 +2,12 @@ package org.gcube.socialnetworking.token;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
public class URLToken extends ReplaceableToken {
private String getReplacement(URL url) {
StringBuilder sb = new StringBuilder();
return sb.toString();
}
private boolean replaced;
public URLToken(Token token, URL url) {
super(token);
@ -30,4 +28,14 @@ public class URLToken extends ReplaceableToken {
}
public String getTokenReplacement() {
if(!replaced) {
Map<String, String> anchorAttibutes = new HashMap<>(1);
anchorAttibutes.put("target", "_blank");
tokenReplacement = createLink(token, token, anchorAttibutes);
replaced = true;
}
return super.getTokenReplacement();
}
}

@ -0,0 +1,87 @@
package org.gcube.social_networking.socialutillibrary;
import java.io.StringWriter;
import java.util.List;
import org.apache.commons.codec.binary.Base64;
import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.socialnetworking.token.Token;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MessageParserTest {
private static final Logger logger = LoggerFactory.getLogger(MessageParserTest.class);
public static final String TEST_11 =
"Dear all, this is a test to ignore, to select a week for the upcoming 194th #Tcom event, " +
"hosted by #Apple in #Cupertino, please use this #Doodle: http://Doodle.com/poll/not-existing-poll \n\n" +
"We're closing the poll next Thursday 16th March.";
public static final String TEST_12 =
"Just because I am so happy to have the SPARQL-endpoint available, \n" +
"sharing some sample SPARQL queries: \n\n" +
"* Classes & usage counts: \n" +
"https://virtuoso.parthenos.d4science.org/sparql?default-graph-uri=&query=%09SELECT+%3Fp+%28COUNT%28%3Fp%29+as+%3FpCount%29++%0D%0A%09%09%09%09%09WHERE+%7B%5B%5D+%3Fp+%5B%5D%7D%0D%0A%09%09%09%09%09GROUP+BY+%3Fp&format=text%2Fhtml&timeout=0&debug=on\n" +
"\n" +
"* properties and usage counts: \n" +
"https://virtuoso.parthenos.d4science.org/sparql?default-graph-uri=&query=SELECT+%3Ftype+%28COUNT%28%3Ftype%29+as+%3FtypeCount%29++%0D%0A%09%09%09%09%09WHERE+%7B%5B%5D+a+%3Ftype%7D%0D%0A%09%09%09%09%09GROUP+BY+%3Ftype&format=text%2Fhtml&timeout=0&debug=on\n";
public static final String TEST_LUCA = "Dear members,\n" +
"The item 'just a test with time fields' has been just published by Francesco Mangiacrapa .\n" +
"You can find it here: http://data-d.d4science.org/ctlg/NextNext/just_a_test_with_time_fields\n" +
"#Text_mining #Field_1 #B3";
@Test
public void test() {
String message = "Prova #Pippo Pollo http://google) :) ";
MessageParser messageParser = new MessageParser(message);
logger.debug(messageParser.getParsedMessage());
messageParser = new MessageParser(TEST_11);
logger.debug(messageParser.getParsedMessage());
messageParser = new MessageParser(TEST_12);
logger.debug(messageParser.getParsedMessage());
messageParser = new MessageParser(TEST_LUCA);
logger.debug(messageParser.getParsedMessage());
}
@Test
public void aux() {
String message = "Prova #Pippo Pollo http://google) :) ";
SocialStringTokenizer socialStringTokenizer = new SocialStringTokenizer(message);
List<Token> tokens = socialStringTokenizer.getTokens();
logger.debug("{}", tokens);
StringWriter stringWriter = new StringWriter();
for(Token token : tokens) {
stringWriter.append(token.getToken());
stringWriter.append(token.getDelimiter());
}
Assert.assertTrue(message.compareTo(stringWriter.toString())==0);
logger.debug("\n'{}'\n'{}'", message, stringWriter.toString());
logger.debug(new String(Base64.encodeBase64(GCubeSocialNetworking.HASHTAG_OID.getBytes())));
logger.debug(GCubeSocialNetworking.HASHTAG_OID);
String hashtag = "#B3";
logger.debug(new String(Base64.encodeBase64(hashtag.getBytes())));
String taggedHTML = "<a class=\"link\" style=\"font-size:14px;\" href=\"?"+
new String(Base64.encodeBase64(GCubeSocialNetworking.HASHTAG_OID.getBytes()))+"="+
new String(Base64.encodeBase64(hashtag.getBytes()))+"\">"+hashtag+"</a>";
logger.debug(taggedHTML);
}
}

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n</pattern>
</encoder>
</appender>
<logger name="org.gcube" level="WARN" />
<logger name="org.gcube.social_networking.socialutillibrary" level="TRACE" />
<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Loading…
Cancel
Save