diff options
author | Vitaly Takmazov | 2018-03-16 10:46:23 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-03-16 10:46:23 +0300 |
commit | 9ef168a03b75aeca0c2f7dda9ce87d4014c703a9 (patch) | |
tree | 8ace0ada0f576d97592f8bc84803a2dcf3e7a244 /juick-core/src/main/java | |
parent | 7cadae166b103182d7d1daaafe602cd8fb145c53 (diff) |
merge common projects
Diffstat (limited to 'juick-core/src/main/java')
15 files changed, 0 insertions, 1410 deletions
diff --git a/juick-core/src/main/java/com/juick/Attachment.java b/juick-core/src/main/java/com/juick/Attachment.java deleted file mode 100644 index 76f2995a..00000000 --- a/juick-core/src/main/java/com/juick/Attachment.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.juick; - -public class Attachment { - private String url; - private Integer height; - private Integer width; - private Attachment small; - private Attachment medium; - private Attachment thumbnail; - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public Integer getHeight() { - return height; - } - - public void setHeight(Integer height) { - this.height = height; - } - - public Integer getWidth() { - return width; - } - - public void setWidth(Integer width) { - this.width = width; - } - - public Attachment getSmall() { - return small; - } - - public void setSmall(Attachment small) { - this.small = small; - } - - public Attachment getMedium() { - return medium; - } - - public void setMedium(Attachment medium) { - this.medium = medium; - } - - public Attachment getThumbnail() { - return thumbnail; - } - - public void setThumbnail(Attachment thumbnail) { - this.thumbnail = thumbnail; - } -} diff --git a/juick-core/src/main/java/com/juick/ExternalToken.java b/juick-core/src/main/java/com/juick/ExternalToken.java deleted file mode 100644 index f6094478..00000000 --- a/juick-core/src/main/java/com/juick/ExternalToken.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Created by vitalyster on 22.11.2016. - */ -public class ExternalToken { - private String name; - private String type; - private String token; - private String secret; - - @JsonCreator - public ExternalToken(@JsonProperty("name") String name, - @JsonProperty("type") String type, - @JsonProperty("token") String token, - @JsonProperty("secret") String secret) { - this.name = name; - this.type = type; - this.token = token; - this.secret = secret; - if (this.type == null) { - throw new IllegalStateException("Token must have type"); - } - if (this.token == null) { - throw new IllegalStateException("Token must have value"); - } - } - - public String getType() { - return type; - } - - public String getToken() { - return token; - } - - public String getName() { - return name; - } - - public String getSecret() { - return secret; - } -} diff --git a/juick-core/src/main/java/com/juick/Message.java b/juick-core/src/main/java/com/juick/Message.java deleted file mode 100644 index 699920f6..00000000 --- a/juick-core/src/main/java/com/juick/Message.java +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -package com.juick; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.juick.xml.adapters.SimpleDateAdapter; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; - -import javax.xml.bind.annotation.*; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Ugnich Anton - */ -@XmlRootElement(name = "juick", namespace = "http://juick.com/message") -@XmlAccessorType() -public class Message implements Comparable { - private int mid = 0; - private int rid = 0; - private int replyto = 0; - private String text = null; - private User user = null; - private final List<Tag> tags; - private Instant ts; - private Instant updated; - @XmlTransient - @JsonIgnore - public int TimeAgo = 0; - @JsonIgnore - private int privacy = 1; - @XmlTransient - @JsonIgnore - public boolean FriendsOnly = false; - @XmlTransient - @JsonIgnore - public boolean ReadOnly = false; - @XmlTransient - @JsonIgnore - public boolean Hidden = false; - @JsonIgnore - @XmlTransient - public boolean VisitorCanComment = true; - private int replies = 0; - private String repliesBy; - private String attachmentType; - @XmlTransient - private Photo photo; - @XmlTransient - private Attachment attachment; - private int likes; - private User to; - private Recommendation Recommendation; - private String replyQuote; - - public Message() { - tags = new ArrayList<>(); - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("mid", mid) - .append("rid", rid) - .append("replyto", replyto) - .append("TimeAgo", TimeAgo) - .append("privacy", privacy) - .append("FriendsOnly", FriendsOnly) - .append("ReadOnly", ReadOnly) - .append("Hidden", Hidden) - .append("VisitorCanComment", VisitorCanComment) - .append("replies", replies) - .append("likes", likes) - .toString(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) - return true; - - if (!(obj instanceof Message)) - return false; - - Message jmsg = (Message) obj; - return (this.getMid() == jmsg.getMid() && this.getRid() == jmsg.getRid()); - } - - @Override - public int compareTo(Object obj) throws ClassCastException { - if (obj == this) - return 0; - - if (!(obj instanceof Message)) - throw new ClassCastException(); - - Message jmsg = (Message) obj; - - int cmp = Integer.compare(jmsg.getMid(), getMid()); - - if (cmp == 0) - cmp = Integer.compare(getRid(), jmsg.getRid()); - - return cmp; - } - - @JsonProperty("mid") - @XmlAttribute(name = "mid") - public int getMid() { - return mid; - } - - public void setMid(int mid) { - this.mid = mid; - } - - @JsonProperty("rid") - @XmlAttribute(name = "rid") - public int getRid() { - return rid; - } - - public void setRid(int rid) { - this.rid = rid; - } - - @XmlElement(name = "user", namespace = "http://juick.com/user") - public com.juick.User getUser() { - return user; - } - - public void setUser(com.juick.User user) { - this.user = user; - } - - @JsonProperty("body") - @XmlElement(name = "body") - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - @JsonProperty("timestamp") - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "UTC") - @XmlAttribute(name = "ts") - @XmlJavaTypeAdapter(SimpleDateAdapter.class) - public Instant getTimestamp() { - return ts; - } - - public void setTimestamp(Instant timestamp) { - this.ts = timestamp; - } - - @XmlElement(name = "to", namespace = "http://juick.com/user") - public User getTo() { - return to; - } - - public void setTo(User to) { - this.to = to; - } - - public Recommendation getRecommendation() { - return Recommendation; - } - - public void setRecommendation(Recommendation recommendation) { - this.Recommendation = recommendation; - } - - @XmlAttribute(name = "quote") - public String getReplyQuote() { - return replyQuote; - } - - public void setReplyQuote(String quote) { - replyQuote = quote; - } - - @JsonProperty("replyto") - @XmlAttribute(name = "replyto") - public int getReplyto() { - return replyto; - } - - public void setReplyto(int replyto) { - this.replyto = replyto; - } - - @JsonProperty("tags") - @XmlElement(name = "tag") - public List<Tag> getTags() { - return tags; - } - - public void setTags(List<Tag> tags) { - this.tags.clear(); - if (CollectionUtils.isNotEmpty(tags)) - this.tags.addAll(tags); - } - - @XmlAttribute - public int getPrivacy() { - return privacy; - } - - public void setPrivacy(int privacy) { - this.privacy = privacy; - } - - public Photo getPhoto() { - return photo; - } - - public void setPhoto(Photo photo) { - this.photo = photo; - } - - @XmlAttribute(name = "attach") - @JsonProperty("attach") - public String getAttachmentType() { - return attachmentType; - } - - public void setAttachmentType(String attachmentType) { - this.attachmentType = attachmentType; - } - - @XmlTransient - public int getReplies() { - return replies; - } - - public void setReplies(int replies) { - this.replies = replies; - } - - @XmlTransient - public int getLikes() { - return likes; - } - - public void setLikes(int likes) { - this.likes = likes; - } - - @JsonProperty("repliesby") - public String getRepliesBy() { - return repliesBy; - } - - public void setRepliesBy(String repliesBy) { - this.repliesBy = repliesBy; - } - - public Attachment getAttachment() { - return attachment; - } - public void setAttachment(Attachment attachment) { - this.attachment = attachment; - } - - public Instant getUpdated() { - return updated; - } - - public void setUpdated(Instant updated) { - this.updated = updated; - } -} diff --git a/juick-core/src/main/java/com/juick/Photo.java b/juick-core/src/main/java/com/juick/Photo.java deleted file mode 100644 index 06299610..00000000 --- a/juick-core/src/main/java/com/juick/Photo.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick; - -/** - * Created by vitalyster on 30.11.2016. - */ -// used for compatibility -@Deprecated -public class Photo { - private String small; - private String medium; - private String thumbnail; - - public String getSmall() { - return small; - } - - public void setSmall(String small) { - this.small = small; - } - - public String getMedium() { - return medium; - } - - public void setMedium(String medium) { - this.medium = medium; - } - - public String getThumbnail() { - return thumbnail; - } - - public void setThumbnail(String thumbnail) { - this.thumbnail = thumbnail; - } -} diff --git a/juick-core/src/main/java/com/juick/Recommendation.java b/juick-core/src/main/java/com/juick/Recommendation.java deleted file mode 100644 index 0a74b9ea..00000000 --- a/juick-core/src/main/java/com/juick/Recommendation.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick; - -/** - * Created by vt on 08/02/16. - */ -public class Recommendation { - private final User from; - - - public Recommendation(User from) { - this.from = from; - } - - public User getFrom() { - return from; - } -} diff --git a/juick-core/src/main/java/com/juick/Status.java b/juick-core/src/main/java/com/juick/Status.java deleted file mode 100644 index d7983536..00000000 --- a/juick-core/src/main/java/com/juick/Status.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Created by vitalyster on 25.07.2016. - */ -public class Status { - private final String value; - - public static final Status OK = new Status("ok"); - public static final Status FAIL = new Status("Fail"); - public static final Status ERROR = new Status("Error"); - - public static Status getStatus(final String stringStatus) { - return new Status(stringStatus); - } - - private Status(String value) { - this.value = value; - } - - @JsonProperty("status") - public String getValue() { - return value; - } - - @Override - public String toString() { - return "value = " + value; - } -} diff --git a/juick-core/src/main/java/com/juick/Tag.java b/juick-core/src/main/java/com/juick/Tag.java deleted file mode 100644 index 29e5c767..00000000 --- a/juick-core/src/main/java/com/juick/Tag.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -package com.juick; - -import com.fasterxml.jackson.annotation.JsonValue; - -import javax.xml.bind.annotation.*; -import java.util.Comparator; -import java.util.Objects; - -/** - * @author Ugnich Anton - */ -@XmlRootElement(name = "tag", namespace = "http://juick.com/message") -@XmlAccessorType(XmlAccessType.FIELD) -public class Tag implements Comparable<Tag> { - @XmlValue - private String name; - - @XmlTransient - public int TID = 0; - @XmlTransient - public int SynonymID = 0; - - public Tag() { - // required for (de)serialization - } - - public Tag(String name) { - this.name = name; - } - - @Override - public boolean equals(Object o) { - return o == this || - (o instanceof Tag) && Objects.equals(name, ((Tag) o).name); - } - - @XmlTransient - @JsonValue - public String getName() { - return name; - } - - @Override - public String toString() { - return name; - } - - @Override - public int compareTo(Tag o) { - return Objects.compare(name, o.getName(), Comparator.naturalOrder()); - } -} diff --git a/juick-core/src/main/java/com/juick/User.java b/juick-core/src/main/java/com/juick/User.java deleted file mode 100644 index 478c6a48..00000000 --- a/juick-core/src/main/java/com/juick/User.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -package com.juick; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.ToStringBuilder; - -import javax.annotation.Nonnull; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Ugnich Anton - */ -@XmlRootElement(name = "user", namespace = "http://juick.com/user") -@XmlAccessorType() -public class User implements Serializable { - private int uid; - private String name; - private Object avatar; - private String fullName; - private int messagesCount; - private String authHash; - private boolean banned; - private String credentials; - private String lang; - private List<ExternalToken> tokens; - - public User() { - tokens = new ArrayList<>(); - } - - @Override - public boolean equals(Object obj) { - return obj == this || - (obj instanceof User && ((User) obj).getUid() == this.getUid()); - } - - @Override - public int hashCode() { - return new HashCodeBuilder() - .append(getUid()) - .toHashCode(); - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("uid", uid) - .append("name", name) - .append("fullName", fullName) - .append("messagesCount", messagesCount) - .append("lang", lang) - .append("banned", banned) - .toString(); - } - - @JsonProperty("uid") - @XmlAttribute(name = "uid") - public int getUid() { - return uid; - } - - public void setUid(int uid) { - this.uid = uid; - } - - @JsonProperty("uname") - @XmlAttribute(name = "uname") - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @JsonProperty("fullname") - @XmlTransient - public String getFullName() { - return fullName; - } - - public void setFullName(String fullName) { - this.fullName = fullName; - } - - @XmlTransient - @JsonIgnore - public String getAuthHash() { - return authHash; - } - - public void setAuthHash(String authHash) { - this.authHash = authHash; - } - - @JsonProperty("unreadCount") - @XmlTransient - public Integer getUnreadCount() { - return messagesCount; - } - - public void setUnreadCount(Integer count) { - this.messagesCount = count; - } - - @XmlTransient - public boolean isBanned() { - return banned; - } - - public void setBanned(boolean banned) { - this.banned = banned; - } - - public Object getAvatar() { - return avatar; - } - - public void setAvatar(Object avatar) { - this.avatar = avatar; - } - - @XmlTransient - @JsonIgnore - public String getCredentials() { - return credentials; - } - - public void setCredentials(String credentials) { - this.credentials = credentials; - } - - public String getLang() { - return lang; - } - - public void setLang(String lang) { - this.lang = lang; - } - - @XmlTransient - public int getMessagesCount() { - return messagesCount; - } - - public void setMessagesCount(int messagesCount) { - this.messagesCount = messagesCount; - } - - @XmlTransient - @JsonIgnore - public boolean isAnonymous() { - return false; - } - - @Nonnull - public List<ExternalToken> getTokens() { - return tokens; - } - - public void setTokens(List<ExternalToken> tokens) { - this.tokens = tokens; - } -} diff --git a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java deleted file mode 100644 index c599d33b..00000000 --- a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.formatters; - -import com.juick.Message; -import com.juick.util.MessageUtils; -import org.apache.commons.lang3.StringUtils; -import org.ocpsoft.prettytime.PrettyTime; - -import java.util.Date; -import java.util.Locale; - -/** - * Created by vitalyster on 12.10.2016. - */ -public class PlainTextFormatter { - static PrettyTime pt = new PrettyTime(new Locale("ru")); - - public static String formatPost(Message jmsg) { - return formatPost(jmsg, false); - } - - public static String formatPost(Message jmsg, boolean markdown) { - StringBuilder sb = new StringBuilder(); - boolean isReply = jmsg.getRid() > 0; - String title = isReply ? "Reply by @" : "@"; - String subtitle = isReply ? markdown ? MessageUtils.escapeMarkdown(StringUtils.defaultString(jmsg.getReplyQuote())) - : jmsg.getReplyQuote() - : markdown ? MessageUtils.getMarkdownTags(jmsg) : MessageUtils.getTagsString(jmsg); - sb.append(title).append(markdown ? MessageUtils.getMarkdownUser(jmsg) : jmsg.getUser().getName()).append(":\n") - .append(subtitle).append("\n"); - if (markdown) { - sb.append(MessageUtils.escapeMarkdown(StringUtils.defaultString(jmsg.getText()))); - } else { - sb.append(StringUtils.defaultString(jmsg.getText())); - } - sb.append("\n"); - if (!markdown && StringUtils.isNotEmpty(jmsg.getAttachmentType())) { - sb.append(MessageUtils.attachmentUrl(jmsg)); - } - return sb.toString(); - } - - public static String formatPostSummary(Message m) { - int cropLength = 384; - String timeAgo = pt.format(Date.from(m.getTimestamp())); - String repliesCount = m.getReplies() == 1 ? "; 1 reply" : m.getReplies() == 0 ? "" - : String.format("; %d replies", m.getReplies()); - StringBuilder sb = new StringBuilder(); - String txt = StringUtils.defaultString(m.getText()); - String attachmentUrl = MessageUtils.attachmentUrl(m); - if (StringUtils.isNotEmpty(attachmentUrl)) { - sb.append(attachmentUrl).append("\n"); - } - if (txt.length() >= cropLength) { - sb.append(StringUtils.substring(txt, 0, cropLength)).append(" [...]"); - } else { - sb.append(txt); - } - return String.format("@%s:%s\n%s\n#%s (%s%s) %s", - m.getUser().getName(), MessageUtils.getTagsString(m), sb.toString(), formatPostNumber(m), timeAgo, repliesCount, formatUrl(m)); - } - - public static String formatUrl(com.juick.Message jmsg) { - if (jmsg.getRid() > 0) { - return String.format("https://juick.com/%d#%d", jmsg.getMid(), jmsg.getRid()); - } - return "https://juick.com/" + jmsg.getMid(); - } - - public static String formatPostNumber(com.juick.Message jmsg) { - if (jmsg.getRid() > 0) { - return String.format("%d/%d", jmsg.getMid(), jmsg.getRid()); - } - return String.format("%d", jmsg.getMid()); - } - - public static String formatTwitterCard(Message jmsg) { - return MessageUtils.getMessageHashTags(jmsg) + StringUtils.defaultString(jmsg.getText()); - } -} diff --git a/juick-core/src/main/java/com/juick/package-info.java b/juick-core/src/main/java/com/juick/package-info.java deleted file mode 100644 index c9023417..00000000 --- a/juick-core/src/main/java/com/juick/package-info.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/** - * Created by vitalyster on 15.11.2016. - */ -@XmlSchema( - namespace="http://juick.com/message", - elementFormDefault = XmlNsForm.QUALIFIED, - xmlns={ - @XmlNs(prefix= StringUtils.EMPTY, namespaceURI="http://juick.com/message"), - @XmlNs(prefix="user", namespaceURI="http://juick.com/user") - } -) -package com.juick; - -import org.apache.commons.lang3.StringUtils; - -import javax.xml.bind.annotation.XmlNs; -import javax.xml.bind.annotation.XmlNsForm; -import javax.xml.bind.annotation.XmlSchema;
\ No newline at end of file diff --git a/juick-core/src/main/java/com/juick/util/DateFormatter.java b/juick-core/src/main/java/com/juick/util/DateFormatter.java deleted file mode 100644 index f9e23a91..00000000 --- a/juick-core/src/main/java/com/juick/util/DateFormatter.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.util; - -import org.apache.commons.lang3.StringUtils; - -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; -import java.util.Locale; - -/** - * Created by aalexeev on 12/7/16. - */ -public class DateFormatter { - private final DateTimeFormatter formatter; - - public DateFormatter(String pattern) { - formatter = DateTimeFormatter.ofPattern(pattern, Locale.ENGLISH); - } - - public String format(final Instant ts) { - if (ts == null) - return null; - - LocalDateTime ldt = LocalDateTime.ofInstant(ts, ZoneOffset.UTC); - - return ldt.format(formatter); - } - - - public Instant parse(final String v) { - if (StringUtils.isBlank(v)) - return null; - - LocalDateTime ldt = LocalDateTime.parse(v, formatter); - - return ldt.toInstant(ZoneOffset.UTC); - } -} diff --git a/juick-core/src/main/java/com/juick/util/DateFormattersHolder.java b/juick-core/src/main/java/com/juick/util/DateFormattersHolder.java deleted file mode 100644 index 09fd17d7..00000000 --- a/juick-core/src/main/java/com/juick/util/DateFormattersHolder.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.util; - -/** - * Created by aalexeev on 12/7/16. - */ -public class DateFormattersHolder { - - private DateFormattersHolder() { - throw new IllegalStateException(); - } - - private static volatile DateFormatter messageFormatter; - - public static DateFormatter getMessageFormatterInstance() { - DateFormatter localInstance = messageFormatter; - - if (localInstance == null) { - synchronized (DateFormatter.class) { - localInstance = messageFormatter; - - if (localInstance == null) - messageFormatter = localInstance = new DateFormatter("yyyy-MM-dd HH:mm:ss"); - } - } - return localInstance; - } - - private static volatile DateFormatter rssFormatter; - - public static DateFormatter getRssFormatterInstance() { - DateFormatter localInstance = rssFormatter; - - if (localInstance == null) { - synchronized (DateFormatter.class) { - localInstance = rssFormatter; - - if (localInstance == null) - rssFormatter = localInstance = new DateFormatter("EEE, d MMM yyyy HH:mm:ss"); - } - } - return localInstance; - } -} diff --git a/juick-core/src/main/java/com/juick/util/MessageUtils.java b/juick-core/src/main/java/com/juick/util/MessageUtils.java deleted file mode 100644 index 87a10351..00000000 --- a/juick-core/src/main/java/com/juick/util/MessageUtils.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.util; - -import com.juick.Message; -import com.juick.Tag; -import org.apache.commons.codec.CharEncoding; -import org.apache.commons.lang3.StringUtils; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -/** - * Created by aalexeev on 11/13/16. - */ -public class MessageUtils { - private MessageUtils() { - throw new IllegalStateException(); - } - - public static String formatQuote(final String quote) { - String result = quote; - - if (quote != null) { - if (quote.length() > 50) { - result = ">" + quote.substring(0, 47).replace('\n', ' ') + "...\n"; - } else if (!quote.isEmpty()) { - result = ">" + quote.replace('\n', ' ') + "\n"; - } - } - - return result; - } - - private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?<!>))*)([\\]\\}]|>)"); - - public static String formatMessageCode(String msg) { - msg = msg.replaceAll("&", "&"); - msg = msg.replaceAll("<", "<"); - msg = msg.replaceAll(">", ">"); - - // http://juick.com/last?page=2 - // <a href="http://juick.com/last?page=2" rel="nofollow">http://juick.com/last?page=2</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\s\\n\\\"]*)", "$1<a href=\"$2\" rel=\"nofollow\">$2</a>"); - - // (http://juick.com/last?page=2) - // (<a href="http://juick.com/last?page=2" rel="nofollow">http://juick.com/last?page=2</a>) - Matcher m = regexLinks2.matcher(msg); - StringBuffer sb = new StringBuffer(); - while (m.find()) { - String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", StringUtils.EMPTY); - m.appendReplacement(sb, "$1$2<a href=\"" + url + "\" rel=\"nofollow\">" + url + "</a>$5"); - } - m.appendTail(sb); - msg = sb.toString(); - - return "<pre>" + msg + "</pre>"; - } - - public static String formatMessage(String msg) { - msg = msg.replaceAll("&", "&"); - msg = msg.replaceAll("<", "<"); - msg = msg.replaceAll(">", ">"); - - // -- - // — - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1—$2"); - - // http://juick.com/last?page=2 - // <a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\s\\n\\\"]*)", "$1<a href=\"$2\" rel=\"nofollow\">$3</a>"); - - // [link text][http://juick.com/last?page=2] - // <a href="http://juick.com/last?page=2" rel="nofollow">link text</a> - msg = msg.replaceAll("\\[([^\\]]+)\\]\\[((?:ht|f)tps?://[^\\]]+)\\]", "<a href=\"$2\" rel=\"nofollow\">$1</a>"); - msg = msg.replaceAll("\\[([^\\]]+)\\]\\(((?:ht|f)tps?://[^\\)]+)\\)", "<a href=\"$2\" rel=\"nofollow\">$1</a>"); - - // #12345 - // <a href="http://juick.com/12345">#12345</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)((?=\\s)|(?=\\Z)|(?=\\))|(?=\\.)|(?=\\,))", "$1<a href=\"http://juick.com/$2\">#$2</a>$3"); - - // #12345/65 - // <a href="http://juick.com/12345#65">#12345/65</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2#$3\">#$2/$3</a>$4"); - - // *bold* - // <b>bold</b> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))\\*([^\\*\\n<>]+)\\*((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<b>$2</b>$3"); - - // /italic/ - // <i>italic</i> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))/([^\\/\\n<>]+)/((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<i>$2</i>$3"); - - // _underline_ - // <span class="u">underline</span> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))_([^\\_\\n<>]+)_((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<span class=\"u\">$2</span>$3"); - - // /12 - // <a href="#12">/12</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"#$2\">/$2</a>$3"); - - // @username@jabber.org - // <a href="http://juick.com/username@jabber.org/">@username@jabber.org</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2/\">@$2</a>$3"); - - // @username - // <a href="http://juick.com/username/">@username</a> - msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2/\">@$2</a>$3"); - - // (http://juick.com/last?page=2) - // (<a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a>) - Matcher m = regexLinks2.matcher(msg); - StringBuffer sb = new StringBuffer(); - while (m.find()) { - String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", StringUtils.EMPTY); - m.appendReplacement(sb, "$1$2<a href=\"" + url + "\" rel=\"nofollow\">$4</a>$5"); - } - m.appendTail(sb); - msg = sb.toString(); - - // > citate - msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))> *(.*)?(\\n|(?=\\Z))", "<q>$1</q>"); - msg = msg.replaceAll("</q><q>", "\n"); - - msg = msg.replaceAll("\n", "<br/>\n"); - return msg; - } - - public static String formatHtml(Message jmsg) { - StringBuilder sb = new StringBuilder(); - boolean isReply = jmsg.getRid() > 0; - String title = isReply ? "<b>Reply by @" : "<b>@"; - String subtitle = isReply ? "<blockquote>" + jmsg.getReplyQuote() + "</blockquote>" : "<i>" + getTagsString(jmsg) + "</i>"; - boolean isCode = jmsg.getTags().stream().anyMatch(t -> t.getName().equals("code")); - - sb.append(title).append(jmsg.getUser().getName()).append(":</b></br/>") - .append(subtitle).append("<br/>") - .append(isCode ? formatMessageCode(StringUtils.defaultString(jmsg.getText())) - : formatMessage(StringUtils.defaultString(jmsg.getText()))).append("<br />"); - if (StringUtils.isNotEmpty(jmsg.getAttachmentType())) { - // FIXME: attachment does not serialized to xml - if (jmsg.getAttachment() == null) { - if (jmsg.getRid() > 0) { - sb.append(String.format("<img src=\"http://i.juick.com/photos-1024/%d-%d.%s\" />", jmsg.getMid(), - jmsg.getRid(), jmsg.getAttachmentType())); - } else { - sb.append(String.format("<img src=\"http://i.juick.com/photos-1024/%d.%s\" />", jmsg.getMid(), - jmsg.getAttachmentType())); - } - } else { - sb.append("<img src=\"").append(jmsg.getAttachment().getMedium().getUrl()).append("\" />"); - } - } - return sb.toString(); - } - - public static String getMessageHashTags(final Message jmsg) { - StringBuilder hashtags = new StringBuilder(); - for (Tag tag : jmsg.getTags()) { - hashtags.append("#").append(tag).append(" "); - } - return hashtags.toString(); - } - public static String getMarkdownTags(final Message jmsg) { - return jmsg.getTags().stream().map(t -> String.format("[%s](http://juick.com/tag/%s)", t.getName(), percentEncode(t.getName()))) - .collect(Collectors.joining(", ")); - } - - public static String getMarkdownUser(final Message jmsg) { - return String.format("[%s](https://juick.com/%s/)", jmsg.getUser().getName(), jmsg.getUser().getName()); - } - - // TODO: check if it is really needed - public static String percentEncode(final String s) { - String ret = StringUtils.EMPTY; - try { - ret = URLEncoder.encode(s, CharEncoding.UTF_8).replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); - } catch (UnsupportedEncodingException e) { - } - return ret; - } - public static String escapeMarkdown(final String s) { - return s.replace("_", "\\_").replace("*", "\\*") - .replace("`", "\\`"); - } - public static String attachmentUrl(final Message jmsg) { - if (StringUtils.isEmpty(jmsg.getAttachmentType())) { - return StringUtils.EMPTY; - } - // FIXME: attachment does not serialized to xml - if (jmsg.getAttachment() == null) { - if (jmsg.getRid() > 0) { - return String.format("http://i.juick.com/photos-1024/%d-%d.%s", jmsg.getMid(), - jmsg.getRid(), jmsg.getAttachmentType()); - } else { - return String.format("http://i.juick.com/photos-1024/%d.%s", jmsg.getMid(), - jmsg.getAttachmentType()); - } - } else { - return jmsg.getAttachment().getMedium().getUrl(); - } - } - public static boolean replyStartsWithQuote(Message msg) { - return msg.getRid() > 0 && StringUtils.defaultString(msg.getText()).startsWith(">"); - } - public static List<Tag> parseTags(String strTags) { - List<Tag> tags = new ArrayList<>(); - if (StringUtils.isNotEmpty(strTags)) { - Set<Tag> tagSet = new TreeSet<>(tags); - for (String str : strTags.split(" ")) { - Tag tag = new Tag(str); - if (!tagSet.contains(tag)) { - tags.add(tag); - tagSet.add(tag); - } - } - } - return tags; - } - public static String getTagsString(Message msg) { - StringBuilder builder = new StringBuilder(); - List<Tag> tags = msg.getTags(); - if (!tags.isEmpty()) { - for (Tag Tag : tags) - builder.append(" *").append(Tag.getName()); - - if (msg.FriendsOnly) - builder.append(" *friends"); - - if (msg.getPrivacy() == -2) - builder.append(" *private"); - else if (msg.getPrivacy() == -1) - builder.append(" *friends"); - else if (msg.getPrivacy() == 2) - builder.append(" *public"); - - if (msg.ReadOnly) - builder.append(" *readonly"); - } - return builder.toString(); - } -} diff --git a/juick-core/src/main/java/com/juick/util/PrettyTimeFormatter.java b/juick-core/src/main/java/com/juick/util/PrettyTimeFormatter.java deleted file mode 100644 index 383f4d9a..00000000 --- a/juick-core/src/main/java/com/juick/util/PrettyTimeFormatter.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.util; - -import org.ocpsoft.prettytime.PrettyTime; - -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.Locale; -import java.util.Map; - -/** - * Created by vitalyster on 04.05.2017. - */ -public class PrettyTimeFormatter { - private static final int MAX_CACHE_SIZE = 20; - - // Cache PrettyTime per locale. LRU cache to prevent memory leak. - private static final Map<Locale, PrettyTime> PRETTY_TIME_LOCALE_MAP = - new LinkedHashMap<Locale, PrettyTime>(MAX_CACHE_SIZE + 1, 1.1F, true) - { - @Override - protected boolean removeEldestEntry(Map.Entry<Locale, PrettyTime> eldest) - { - return size() > MAX_CACHE_SIZE; - } - }; - - public String format(final Locale locale, final Date value) - { - PrettyTime prettyTime; - - synchronized (PRETTY_TIME_LOCALE_MAP) { - prettyTime = PRETTY_TIME_LOCALE_MAP.computeIfAbsent(locale, PrettyTime::new); - } - return prettyTime.format(value); - } -} diff --git a/juick-core/src/main/java/com/juick/xml/adapters/SimpleDateAdapter.java b/juick-core/src/main/java/com/juick/xml/adapters/SimpleDateAdapter.java deleted file mode 100644 index 6dd40582..00000000 --- a/juick-core/src/main/java/com/juick/xml/adapters/SimpleDateAdapter.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.xml.adapters; - -import com.juick.util.DateFormattersHolder; - -import javax.xml.bind.annotation.adapters.XmlAdapter; -import java.time.Instant; - -/** - * Created by vitalyster on 15.11.2016. - */ - -public class SimpleDateAdapter extends XmlAdapter<String, Instant> { - - @Override - public String marshal(Instant v) throws Exception { - return DateFormattersHolder.getMessageFormatterInstance().format(v); - } - - @Override - public Instant unmarshal(String v) throws Exception { - return DateFormattersHolder.getMessageFormatterInstance().parse(v); - } -} |