Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
1.0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
sokomishalov committed Oct 14, 2019
1 parent f525613 commit 297a2b6
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 32 deletions.
4 changes: 2 additions & 2 deletions commons-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>ru.sokomishalov.commons</groupId>
<artifactId>commons-parent</artifactId>
<version>1.0.21</version>
<version>1.0.22</version>
</parent>

<artifactId>commons-core</artifactId>
<version>1.0.21</version>
<version>1.0.22</version>

<properties>
<kotlin.version>1.3.50</kotlin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,44 @@

package ru.sokomishalov.commons.core.html

import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext
import org.jsoup.Jsoup
import org.jsoup.Jsoup.clean
import org.jsoup.Jsoup.parse
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import org.jsoup.safety.Whitelist
import ru.sokomishalov.commons.core.http.REACTIVE_NETTY_HTTP_CLIENT
import ru.sokomishalov.commons.core.reactor.awaitStrict
import java.nio.charset.StandardCharsets.UTF_8


/**
* @author sokomishalov
*/

suspend fun getWebPage(url: String): Document = withContext(IO) {
Jsoup.connect(url).get()
suspend fun getWebPage(url: String): Document {
val document = REACTIVE_NETTY_HTTP_CLIENT
.get()
.uri(url)
.responseContent()
.aggregate()
.asString(UTF_8)
.awaitStrict()

return parse(document)
}

fun Element.getSingleElementByClass(name: String): Element {
return getElementsByClass(name).first()
}

fun Element.getImageBackgroundUrl(): String {
return attr("style")
.run { substring(indexOf("http"), indexOf(")")) }
fun Element.getSingleElementByTag(name: String): Element {
return getElementsByTag(name).first()
}

suspend fun Element.fixText(): String {
val titleDoc = withContext(IO) {
parse(html())
}

val allAnchors = titleDoc.select("a")
val twitterAnchors = titleDoc.select("a[href^=/]")
val unwantedAnchors = ArrayList<Element>()

allAnchors.filterNotTo(unwantedAnchors) { twitterAnchors.contains(it) }
unwantedAnchors.forEach { it.remove() }

return titleDoc.text()
fun Element.getImageBackgroundUrl(): String {
val style = attr("style")
return style.substring(style.indexOf("http"), style.indexOf(")"))
}

fun Element.fixText(): String {
return clean(toString(), Whitelist.none())
}
10 changes: 5 additions & 5 deletions commons-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<parent>
<groupId>ru.sokomishalov.commons</groupId>
<artifactId>commons-parent</artifactId>
<version>1.0.21</version>
<version>1.0.22</version>
</parent>

<artifactId>commons-spring</artifactId>
<version>1.0.21</version>
<version>1.0.22</version>

<properties>
<kotlin.version>1.3.50</kotlin.version>
<spring.boot.version>2.1.8.RELEASE</spring.boot.version>
<spring.boot.version>2.1.9.RELEASE</spring.boot.version>
<spring.version>5.2.0.RELEASE</spring.version>
<caffeine.cache>2.8.0</caffeine.cache>
<springfox.version>2.9.2</springfox.version>
Expand All @@ -31,7 +31,7 @@
<dependency>
<groupId>ru.sokomishalov.commons</groupId>
<artifactId>commons-core</artifactId>
<version>1.0.21</version>
<version>1.0.22</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -102,7 +102,7 @@
<dependency>
<groupId>it.ozimov</groupId>
<artifactId>embedded-redis</artifactId>
<version>0.7.2</version>
<version>${redis-embedded.version}</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("UNCHECKED_CAST", "unused")

package ru.sokomishalov.commons.spring.cache

import com.github.benmanes.caffeine.cache.Caffeine
Expand All @@ -33,3 +35,18 @@ fun createDefaultCacheManager(cacheNames: List<String>, expireAfter: Duration =
})
}
}

fun <V> CacheManager.put(cacheName: String, key: String, value: V?) {
getCache(cacheName)?.put(key, value)
}

fun CacheManager.evict(cacheName: String, key: String) {
getCache(cacheName)?.evict(key)
}

fun <V> CacheManager.get(cacheName: String, key: String): V? {
return when (val value = getCache(cacheName)?.get(key)?.get()) {
null -> null
else -> value as V
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ fun Docket.customizeDocket(
.apiInfo(ApiInfoBuilder()
.title(title)
.description(description)
.license("Apache 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
.contact(contact)
.version(version)
.build()
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ru.sokomishalov.commons</groupId>
<artifactId>commons-parent</artifactId>
<version>1.0.21</version>
<version>1.0.22</version>
<packaging>pom</packaging>

<properties>
Expand Down

0 comments on commit 297a2b6

Please sign in to comment.