Skip to content

Commit

Permalink
SAK-43479 Profile2: Deprecated utils.FormattedText => api.FormattedTe…
Browse files Browse the repository at this point in the history
…xt (sakaiproject#8085)

* SAK-43479 Profile2: Deprecated utils.FormattedText => api.FormattedText

* SAK-43479 Profile2: Deprecated utils.FormattedText => api.FormattedText
  • Loading branch information
axxter99 authored Mar 28, 2020
1 parent 6e1c7fd commit cc41c88
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
import org.sakaiproject.profile2.tool.components.ProfileImage;
import org.sakaiproject.profile2.tool.models.FriendAction;
import org.sakaiproject.profile2.util.ProfileConstants;
import org.sakaiproject.util.FormattedText;
import org.sakaiproject.util.api.FormattedText;


public class AddFriend extends Panel {

Expand All @@ -53,6 +54,9 @@ public class AddFriend extends Panel {
@SpringBean(name="org.sakaiproject.profile2.logic.ProfileConnectionsLogic")
private ProfileConnectionsLogic connectionsLogic;

@SpringBean(name="org.sakaiproject.util.api.FormattedText")
private FormattedText formattedText;

/*
* userX is the current user
* userY is the user to add
Expand All @@ -62,7 +66,7 @@ public AddFriend(String id, final ModalWindow window, final FriendAction friendA
super(id);

//get friendName
final String friendName = FormattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY), new StringBuffer());
final String friendName = formattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY), new StringBuffer());

//window setup
window.setTitle(new StringResourceModel("title.friend.add", null, new Object[]{ friendName } ));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.sakaiproject.profile2.tool.components.ProfileImage;
import org.sakaiproject.profile2.tool.models.FriendAction;
import org.sakaiproject.profile2.util.ProfileConstants;
import org.sakaiproject.util.FormattedText;
import org.sakaiproject.util.api.FormattedText;

public class ConfirmFriend extends Panel {

Expand All @@ -53,6 +53,9 @@ public class ConfirmFriend extends Panel {
@SpringBean(name="org.sakaiproject.profile2.logic.ProfileConnectionsLogic")
private ProfileConnectionsLogic connectionsLogic;

@SpringBean(name="org.sakaiproject.util.api.FormattedText")
private FormattedText formattedText;

/*
* userX is the current user
* userY is the user who's friend request we are accepting
Expand All @@ -62,7 +65,7 @@ public ConfirmFriend(String id, final ModalWindow window, final FriendAction fri
super(id);

//get friendName
final String friendName = FormattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY), new StringBuffer());
final String friendName = formattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY), new StringBuffer());

//window setup
window.setTitle(new StringResourceModel("title.friend.confirm", null, new Object[]{ friendName } ));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.sakaiproject.profile2.tool.components.ProfileImage;
import org.sakaiproject.profile2.tool.models.FriendAction;
import org.sakaiproject.profile2.util.ProfileConstants;
import org.sakaiproject.util.FormattedText;
import org.sakaiproject.util.api.FormattedText;

public class IgnoreFriend extends Panel {

Expand All @@ -52,6 +52,9 @@ public class IgnoreFriend extends Panel {

@SpringBean(name="org.sakaiproject.profile2.logic.ProfileConnectionsLogic")
private ProfileConnectionsLogic connectionsLogic;

@SpringBean(name="org.sakaiproject.util.api.FormattedText")
private FormattedText formattedText;

/*
* userX is the current user
Expand All @@ -62,7 +65,7 @@ public IgnoreFriend(String id, final ModalWindow window, final FriendAction frie
super(id);

//get friendName
final String friendName = FormattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY), new StringBuffer());
final String friendName = formattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY), new StringBuffer());

//window setup
window.setTitle(new ResourceModel("title.friend.ignore"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.sakaiproject.profile2.tool.components.ProfileImage;
import org.sakaiproject.profile2.tool.models.FriendAction;
import org.sakaiproject.profile2.util.ProfileConstants;
import org.sakaiproject.util.FormattedText;
import org.sakaiproject.util.api.FormattedText;

public class RemoveFriend extends Panel {

Expand All @@ -52,6 +52,9 @@ public class RemoveFriend extends Panel {

@SpringBean(name="org.sakaiproject.profile2.logic.ProfileConnectionsLogic")
private ProfileConnectionsLogic connectionsLogic;

@SpringBean(name="org.sakaiproject.util.api.FormattedText")
private FormattedText formattedText;

/*
* userX is the current user
Expand All @@ -62,7 +65,7 @@ public RemoveFriend(String id, final ModalWindow window, final FriendAction frie
super(id);

//get friendName
final String friendName = FormattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY), new StringBuffer());
final String friendName = formattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY), new StringBuffer());

//window setup
window.setTitle(new ResourceModel("title.friend.remove"));
Expand Down
72 changes: 38 additions & 34 deletions profile2/util/pom.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>Profile2 UTIL</name>
<groupId>org.sakaiproject.profile2</groupId>
<artifactId>profile2-util</artifactId>
<modelVersion>4.0.0</modelVersion>
<name>Profile2 UTIL</name>
<groupId>org.sakaiproject.profile2</groupId>
<artifactId>profile2-util</artifactId>

<packaging>jar</packaging>
<parent>
<groupId>org.sakaiproject.profile2</groupId>
<artifactId>profile2</artifactId>
<version>21-SNAPSHOT</version>
</parent>
<dependencies>
<packaging>jar</packaging>
<parent>
<groupId>org.sakaiproject.profile2</groupId>
<artifactId>profile2</artifactId>
<version>21-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand All @@ -22,26 +22,30 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.imgscalr</groupId>
<artifactId>imgscalr-lib</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-api</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-util</artifactId>
</dependency>
</dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.imgscalr</groupId>
<artifactId>imgscalr-lib</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-api</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-util</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-component-manager</artifactId>
</dependency>
</dependencies>

<build>
<resources>
<build>
<resources>
<resource>
<directory>${basedir}/src/java</directory>
<includes>
Expand All @@ -50,7 +54,7 @@
<filtering>false</filtering>
</resource>
</resources>
</build>
</build>
</project>

Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.text.WordUtils;
import org.imgscalr.Scalr;
import org.sakaiproject.util.FormattedText;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.util.ResourceLoader;
import org.sakaiproject.util.api.FormattedText;

import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -403,7 +404,7 @@ public static List<String> getListFromString(String str, char separator) {
* @return
*/
public static String processHtml(String s){
return FormattedText.processFormattedText(s, new StringBuilder(), true, false);
return ComponentManager.get(FormattedText.class).processFormattedText(s, new StringBuilder(), true, false);
}

/**
Expand All @@ -413,7 +414,7 @@ public static String processHtml(String s){
* @return
*/
public static String stripHtml(String s) {
return FormattedText.convertFormattedTextToPlaintext(s);
return ComponentManager.get(FormattedText.class).convertFormattedTextToPlaintext(s);
}

/**
Expand All @@ -426,7 +427,7 @@ public static String stripHtml(String s) {
*/
public static String stripAndCleanHtml(String s) {
//Attempt to strip HTML. This doesn't work on poorly formatted HTML though
String stripped = FormattedText.convertFormattedTextToPlaintext(s);
String stripped = ComponentManager.get(FormattedText.class).convertFormattedTextToPlaintext(s);

//so we escape anything that is left
return StringEscapeUtils.escapeHtml4(stripped);
Expand All @@ -445,7 +446,7 @@ public static String stripAndCleanHtml(String s) {
* @see #convertFormattedTextToPlaintext(String) for alternative mechanism
*/
public static String stripHtmlFromText(String text, boolean smartSpacing, boolean stripEscapeSequences) {
return FormattedText.stripHtmlFromText(text, smartSpacing, stripEscapeSequences);
return ComponentManager.get(FormattedText.class).stripHtmlFromText(text, smartSpacing, stripEscapeSequences);
}

/**
Expand All @@ -466,7 +467,7 @@ public static String truncate(String s, int maxNumOfChars, boolean isHtml) {
//html
if(isHtml) {
StringBuilder trimmedHtml = new StringBuilder();
FormattedText.trimFormattedText(s, maxNumOfChars, trimmedHtml);
ComponentManager.get(FormattedText.class).trimFormattedText(s, maxNumOfChars, trimmedHtml);
return trimmedHtml.toString();
}

Expand Down Expand Up @@ -495,7 +496,7 @@ public static String truncateAndAbbreviate(String s, int maxNumOfChars, boolean
if(isHtml) {
StringBuilder trimmedHtml = new StringBuilder();

boolean trimmed = FormattedText.trimFormattedText(s, maxNumOfChars - 3, trimmedHtml);
boolean trimmed = ComponentManager.get(FormattedText.class).trimFormattedText(s, maxNumOfChars - 3, trimmedHtml);

if (trimmed) {
int index = trimmedHtml.lastIndexOf("</");
Expand Down

0 comments on commit cc41c88

Please sign in to comment.