All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.flamenk.article.Article Maven / Gradle / Ivy

Go to download

Flamenk is an srticle extractor, extracts the article present in a web page.

The newest version!
/*
 * Copyright 2013 Torindo Nesci.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flamenk.article;

import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import java.net.URL;

/**
 *
 * The article extracted from the html page.
 *
 * 

This implementation is Thread Safe. * * @author Torindo Nesci */ public class Article { private volatile String mTitle; private volatile String mImageUrl; private volatile String mBody; private final URL mUrl; private volatile long mProcessingTime; Article(URL url) { Preconditions.checkNotNull(url); this.mUrl = url; } void setProcessingTime(long time) { Preconditions.checkArgument(time >= 0); this.mProcessingTime = time; } /** * Returns the processing time in milliseconds taken to extract this article. * In this time is excluded: *
    *
  • the time to pull the html from the network.
  • *
  • the time to parse the html page.
  • *
* * @return The processing time. */ public long getProcessingTime() { return this.mProcessingTime; } /** * Returns the url. * * @return The url. */ public URL getUrl() { return this.mUrl; } /** * Returns the document body, it can have html tokens. * * @return The document body. */ public Optional getBody() { return optionalOf(this.mBody); } /** * Sets the article body, it can have html tokens. * * @param body The article body. */ void setBody(String body) { Preconditions.checkNotNull(body); this.mBody = body; } /** * Sets the article title, it cannot have html tags. * * @param title The article title */ void setTitle(String title) { Preconditions.checkNotNull(title); this.mTitle = title; } /** * Returns the article title, it cannot have html tags. * * @return The article title. */ public Optional getTitle() { return optionalOf(this.mTitle); } /** * Sets the article main image url. * * @param url The article main image url. */ void setMainImageUrl(String url) { Preconditions.checkNotNull(url); this.mImageUrl = url; } /** * Returns the article main image url. * * @return The article main image url. */ public Optional getMainImageUrl() { return optionalOf(this.mImageUrl); } private Optional optionalOf(T obj) { if (isNullOrEmpty(obj)) { return Optional.absent(); } return Optional.of(obj); } private boolean isNullOrEmpty(Object obj) { if (obj == null) { return true; } if (obj instanceof String) { return ((String) obj).isEmpty(); } return false; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy