Skip to content

Commit

Permalink
SAK-44317 StringUtil.limit => (commons-lang3) StringUtils.abbreviate (s…
Browse files Browse the repository at this point in the history
…akaiproject#8583)

StringUtil.trimToZero => (commons-lang3) StringUtils.trimToEmpty
  • Loading branch information
axxter99 authored Sep 18, 2020
1 parent 2e6d7b4 commit ffd8e16
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import java.util.Set;
import java.util.Vector;

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.sakaiproject.alias.api.Alias;
import org.sakaiproject.alias.api.AliasEdit;
import org.sakaiproject.db.api.SqlReader;
Expand All @@ -44,6 +43,8 @@
import org.sakaiproject.util.SingleStorageUser;
import org.sakaiproject.util.StringUtil;

import lombok.extern.slf4j.Slf4j;

/**
* <p>
* DbAliasService is an extension of the BaseAliasService with a database storage. Fields are fully relational. Full properties are not yet supported - core ones are. Code to find and convert records from before, from the XML based CHEF_ALIAS table is
Expand Down Expand Up @@ -538,8 +539,8 @@ protected Object[] fields(String id, AliasEdit edit, boolean idAgain)
{
rv[1] = edit.getTarget();
ResourceProperties props = edit.getProperties();
rv[2] = StringUtil.trimToZero(((BaseAliasEdit) edit).m_createdUserId);
rv[3] = StringUtil.trimToZero(((BaseAliasEdit) edit).m_lastModifiedUserId);
rv[2] = StringUtils.trimToEmpty(((BaseAliasEdit) edit).m_createdUserId);
rv[3] = StringUtils.trimToEmpty(((BaseAliasEdit) edit).m_lastModifiedUserId);
rv[4] = edit.getCreatedTime();
rv[5] = edit.getModifiedTime();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;

import org.sakaiproject.authz.api.AuthzGroup;
import org.sakaiproject.authz.api.AuthzGroup.RealmLockMode;
import org.sakaiproject.authz.api.GroupFullException;
Expand All @@ -62,6 +69,11 @@
import org.sakaiproject.util.BaseResourcePropertiesEdit;
import org.sakaiproject.util.StringUtil;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;

/**
* <p>
* DbAuthzGroupService is an extension of the BaseAuthzGroupService with database storage.
Expand Down Expand Up @@ -1994,10 +2006,10 @@ protected Object[] fields(String id, BaseAuthzGroup edit, boolean idAgain)

else
{
rv[1] = StringUtil.trimToZero(edit.m_providerRealmId);
rv[2] = StringUtil.trimToZero(edit.m_maintainRole);
rv[3] = StringUtil.trimToZero(edit.m_createdUserId);
rv[4] = StringUtil.trimToZero(edit.m_lastModifiedUserId);
rv[1] = StringUtils.trimToEmpty(edit.m_providerRealmId);
rv[2] = StringUtils.trimToEmpty(edit.m_maintainRole);
rv[3] = StringUtils.trimToEmpty(edit.m_createdUserId);
rv[4] = StringUtils.trimToEmpty(edit.m_lastModifiedUserId);
rv[5] = edit.getCreatedTime();
rv[6] = edit.getModifiedTime();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@

package org.sakaiproject.content.impl;

import static org.sakaiproject.content.util.IdUtil.isolateContainingId;
import static org.sakaiproject.content.util.IdUtil.isolateName;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -66,47 +68,27 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import fr.opensagres.odfdom.converter.xhtml.XHTMLConverter;

import org.apache.commons.lang3.StringUtils;
import org.apache.tika.detect.DefaultDetector;
import org.apache.tika.detect.Detector;
import org.apache.tika.io.TikaInputStream;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MimeTypes;
import org.apache.tika.parser.txt.CharsetDetector;
import org.apache.tika.parser.txt.CharsetMatch;

import org.odftoolkit.odfdom.doc.OdfTextDocument;

import org.zwobble.mammoth.DocumentConverter;
import org.zwobble.mammoth.Result;

import org.sakaiproject.authz.api.AuthzRealmLockException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;

import org.sakaiproject.alias.api.AliasService;
import org.sakaiproject.antivirus.api.VirusFoundException;
import org.sakaiproject.antivirus.api.VirusScanIncompleteException;
import org.sakaiproject.antivirus.api.VirusScanner;
import org.sakaiproject.authz.api.AuthzGroup;
import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.authz.api.AuthzPermissionException;
import org.sakaiproject.authz.api.AuthzRealmLockException;
import org.sakaiproject.authz.api.FunctionManager;
import org.sakaiproject.authz.api.GroupAlreadyDefinedException;
import org.sakaiproject.authz.api.GroupIdInvalidException;
Expand All @@ -117,8 +99,22 @@
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.conditions.api.ConditionService;
import org.sakaiproject.content.api.*;
import org.sakaiproject.content.api.ContentChangeHandler;
import org.sakaiproject.content.api.ContentCollection;
import org.sakaiproject.content.api.ContentCollectionEdit;
import org.sakaiproject.content.api.ContentEntity;
import org.sakaiproject.content.api.ContentFilterService;
import org.sakaiproject.content.api.ContentHostingHandler;
import org.sakaiproject.content.api.ContentHostingService;
import org.sakaiproject.content.api.ContentResource;
import org.sakaiproject.content.api.ContentResourceEdit;
import org.sakaiproject.content.api.ContentTypeImageService;
import org.sakaiproject.content.api.FileConversionService;
import org.sakaiproject.content.api.GroupAwareEdit;
import org.sakaiproject.content.api.GroupAwareEntity;
import org.sakaiproject.content.api.GroupAwareEntity.AccessMode;
import org.sakaiproject.content.api.ResourceType;
import org.sakaiproject.content.api.ResourceTypeRegistry;
import org.sakaiproject.content.api.providers.SiteContentAdvisor;
import org.sakaiproject.content.api.providers.SiteContentAdvisorProvider;
import org.sakaiproject.content.api.providers.SiteContentAdvisorTypeRegistry;
Expand Down Expand Up @@ -192,9 +188,19 @@
import org.sakaiproject.util.Web;
import org.sakaiproject.util.Xml;
import org.sakaiproject.util.api.LinkMigrationHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.zwobble.mammoth.DocumentConverter;
import org.zwobble.mammoth.Result;

import static org.sakaiproject.content.util.IdUtil.isolateContainingId;
import static org.sakaiproject.content.util.IdUtil.isolateName;
import fr.opensagres.odfdom.converter.xhtml.XHTMLConverter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
* <p>
Expand Down Expand Up @@ -1222,7 +1228,7 @@ public Object[] storageFields(Entity r)
rv[1] = ((BasicGroupAwareEdit) r).getContext();
rv[2] = Long.valueOf(((ContentResource) r).getContentLength());
rv[3] = ((BasicGroupAwareEdit) r).getResourceType();
rv[4] = StringUtil.trimToZero(((BaseResourceEdit) r).m_filePath);
rv[4] = StringUtils.trimToEmpty(((BaseResourceEdit) r).m_filePath);
return rv;
}

Expand All @@ -1244,7 +1250,7 @@ public Object[] storageFields(Entity r)
{
Object[] rv = new Object[2];
rv[0] = StringUtil.referencePath(((ContentResource) r).getId());
rv[1] = StringUtil.trimToZero(((BaseResourceEdit) r).m_filePath);
rv[1] = StringUtils.trimToEmpty(((BaseResourceEdit) r).m_filePath);
return rv;
}

Expand Down Expand Up @@ -8670,7 +8676,7 @@ public String getEntityDescription(Reference ref)
+ c.getProperties().getPropertyFormatted(ResourceProperties.PROP_CREATION_DATE) + " by "
+ c.getProperties().getPropertyFormatted(ResourceProperties.PROP_CREATOR) + "(User Id:"
+ c.getProperties().getProperty(ResourceProperties.PROP_CREATOR) + ")\n"
+ StringUtil.limit(c.getProperties().getPropertyFormatted(ResourceProperties.PROP_DESCRIPTION), 30);
+ StringUtils.abbreviate(c.getProperties().getPropertyFormatted(ResourceProperties.PROP_DESCRIPTION), 30);
}
else
{
Expand All @@ -8679,7 +8685,7 @@ public String getEntityDescription(Reference ref)
+ ")\n" + " Created: " + r.getProperties().getPropertyFormatted(ResourceProperties.PROP_CREATION_DATE)
+ " by " + r.getProperties().getPropertyFormatted(ResourceProperties.PROP_CREATOR) + "(User Id:"
+ r.getProperties().getProperty(ResourceProperties.PROP_CREATOR) + ")\n"
+ StringUtil.limit(r.getProperties().getPropertyFormatted(ResourceProperties.PROP_DESCRIPTION), 30);
+ StringUtils.abbreviate(r.getProperties().getPropertyFormatted(ResourceProperties.PROP_DESCRIPTION), 30);
}
} catch (PermissionException e) {
log.error("PermissionEception:", e);
Expand Down Expand Up @@ -10022,7 +10028,7 @@ public String getDropboxCollection(String siteId)
if ( userId == null ) return rv;

// form the current user's dropbox collection within this site's
rv += StringUtil.trimToZero(userId) + "/";
rv += StringUtils.trimToEmpty(userId) + "/";
return rv;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,53 @@
package org.sakaiproject.site.impl;

import java.io.PrintWriter;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;
import java.util.Properties;
import java.util.Set;
import java.util.Stack;
import java.util.Vector;
import java.util.concurrent.CopyOnWriteArraySet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.validator.routines.UrlValidator;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import org.sakaiproject.authz.api.*;
import org.sakaiproject.authz.api.AuthzGroup;
import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.authz.api.AuthzPermissionException;
import org.sakaiproject.authz.api.AuthzRealmLockException;
import org.sakaiproject.authz.api.FunctionManager;
import org.sakaiproject.authz.api.GroupNotDefinedException;
import org.sakaiproject.authz.api.Member;
import org.sakaiproject.authz.api.Role;
import org.sakaiproject.authz.api.SecurityAdvisor;
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.entity.api.*;
import org.sakaiproject.entity.api.ContextObserver;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.EntityAccessOverloadException;
import org.sakaiproject.entity.api.EntityCopyrightException;
import org.sakaiproject.entity.api.EntityManager;
import org.sakaiproject.entity.api.EntityNotDefinedException;
import org.sakaiproject.entity.api.EntityPermissionException;
import org.sakaiproject.entity.api.EntityProducer;
import org.sakaiproject.entity.api.HardDeleteAware;
import org.sakaiproject.entity.api.HttpAccess;
import org.sakaiproject.entity.api.Reference;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.entity.api.ResourcePropertiesEdit;
import org.sakaiproject.event.api.Event;
import org.sakaiproject.event.api.EventTrackingService;
import org.sakaiproject.event.api.Notification;
Expand All @@ -53,7 +82,15 @@
import org.sakaiproject.javax.PagingPosition;
import org.sakaiproject.memory.api.Cache;
import org.sakaiproject.memory.api.MemoryService;
import org.sakaiproject.site.api.*;
import org.sakaiproject.site.api.AllowedJoinableAccount;
import org.sakaiproject.site.api.Group;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.SiteAdvisor;
import org.sakaiproject.site.api.SitePage;
import org.sakaiproject.site.api.SiteRemovalAdvisor;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.site.api.SiteTitleAdvisor;
import org.sakaiproject.site.api.ToolConfiguration;
import org.sakaiproject.thread_local.api.ThreadLocalManager;
import org.sakaiproject.time.api.Time;
import org.sakaiproject.time.api.TimeService;
Expand All @@ -63,7 +100,15 @@
import org.sakaiproject.user.api.User;
import org.sakaiproject.user.api.UserDirectoryService;
import org.sakaiproject.user.api.UserNotDefinedException;
import org.sakaiproject.util.*;
import org.sakaiproject.util.BasicConfigItem;
import org.sakaiproject.util.Resource;
import org.sakaiproject.util.ResourceLoader;
import org.sakaiproject.util.StringUtil;
import org.sakaiproject.util.Validator;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import lombok.extern.slf4j.Slf4j;

/**
* <p>
Expand Down Expand Up @@ -2513,7 +2558,7 @@ public String getEntityDescription(Reference ref)
site.getTitle() + " (" + site.getId() + ")",
site.getCreatedTime().toStringLocalFull(),
site.getCreatedBy().getDisplayName() + " (" + site.getCreatedBy().getDisplayId() + ")",
StringUtil.limit((site.getDescription() == null ? "" : site.getDescription()), 30)});
StringUtils.abbreviate((site.getDescription() == null ? "" : site.getDescription()), 30)});
}
catch (IdUnusedException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.sakaiproject.db.api.SqlReader;
import org.sakaiproject.db.api.SqlReaderFinishedException;
import org.sakaiproject.db.api.SqlService;
Expand Down Expand Up @@ -2580,21 +2581,21 @@ protected Object[] fields(String id, Site edit, boolean idAgain)

else
{
rv[1] = StringUtil.trimToZero(((BaseSite) edit).m_title);
rv[2] = StringUtil.trimToZero(((BaseSite) edit).m_type);
rv[3] = StringUtil.trimToZero(((BaseSite) edit).m_shortDescription);
rv[4] = StringUtil.trimToZero(((BaseSite) edit).m_description);
rv[5] = StringUtil.trimToZero(((BaseSite) edit).m_icon);
rv[6] = StringUtil.trimToZero(((BaseSite) edit).m_info);
rv[7] = StringUtil.trimToZero(((BaseSite) edit).m_skin);
rv[1] = StringUtils.trimToEmpty(((BaseSite) edit).m_title);
rv[2] = StringUtils.trimToEmpty(((BaseSite) edit).m_type);
rv[3] = StringUtils.trimToEmpty(((BaseSite) edit).m_shortDescription);
rv[4] = StringUtils.trimToEmpty(((BaseSite) edit).m_description);
rv[5] = StringUtils.trimToEmpty(((BaseSite) edit).m_icon);
rv[6] = StringUtils.trimToEmpty(((BaseSite) edit).m_info);
rv[7] = StringUtils.trimToEmpty(((BaseSite) edit).m_skin);
rv[8] = Integer.valueOf((((BaseSite) edit).m_published) ? 1 : 0);
rv[9] = ((((BaseSite) edit).m_joinable) ? "1" : "0");
rv[10] = ((((BaseSite) edit).m_pubView) ? "1" : "0");
rv[11] = StringUtil.trimToZero(((BaseSite) edit).m_joinerRole);
rv[11] = StringUtils.trimToEmpty(((BaseSite) edit).m_joinerRole);
rv[12] = isSpecialSite(id) ? "1" : "0";
rv[13] = isUserSite(id) ? "1" : "0";
rv[14] = StringUtil.trimToZero(((BaseSite) edit).m_createdUserId);
rv[15] = StringUtil.trimToZero(((BaseSite) edit).m_lastModifiedUserId);
rv[14] = StringUtils.trimToEmpty(((BaseSite) edit).m_createdUserId);
rv[15] = StringUtils.trimToEmpty(((BaseSite) edit).m_lastModifiedUserId);
rv[16] = edit.getCreatedTime();
rv[17] = edit.getModifiedTime();
rv[18] = edit.isCustomPageOrdered() ? "1" : "0";
Expand Down

0 comments on commit ffd8e16

Please sign in to comment.