Coverage Report - org.phandom.Page
 
Classes in this File Line Coverage Branch Coverage Complexity
Page
N/A
N/A
1
Page$Text
0%
0/7
0%
0/10
1
Page$Text$AjcClosure1
0%
0/1
N/A
1
Page$Web
0%
0/7
0%
0/10
1
Page$Web$AjcClosure1
0%
0/1
N/A
1
 
 1  0
 /**
 2  
  * Copyright (c) 2013-2014, phandom.org
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the phandom.org nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package org.phandom;
 31  
 
 32  
 import com.jcabi.aspects.Immutable;
 33  
 import com.jcabi.aspects.Loggable;
 34  
 import java.io.ByteArrayInputStream;
 35  
 import java.io.IOException;
 36  
 import java.net.URI;
 37  
 import lombok.EqualsAndHashCode;
 38  
 import lombok.ToString;
 39  
 import org.apache.commons.io.Charsets;
 40  
 
 41  
 /**
 42  
  * Page to render.
 43  
  *
 44  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 45  
  * @version $Id$
 46  
  * @since 0.3
 47  
  */
 48  
 @Immutable
 49  
 interface Page {
 50  
 
 51  
     /**
 52  
      * Get its URI.
 53  
      * @return URI
 54  
      * @throws IOException If fails
 55  
      */
 56  
     URI uri() throws IOException;
 57  
 
 58  
     /**
 59  
      * Text page.
 60  
      */
 61  
     @Immutable
 62  0
     @ToString
 63  0
     @EqualsAndHashCode(of = "html")
 64  
     @Loggable(Loggable.DEBUG)
 65  
     final class Text implements Page {
 66  
         /**
 67  
          * HTML content.
 68  
          */
 69  
         private final transient String html;
 70  
         /**
 71  
          * Public ctor.
 72  
          * @param content HTML content
 73  
          */
 74  0
         public Text(final String content) {
 75  0
             this.html = content;
 76  0
         }
 77  
         @Override
 78  
         public URI uri() throws IOException {
 79  0
             return new Temp(
 80  
                 new ByteArrayInputStream(
 81  
                     this.html.getBytes(Charsets.UTF_8)
 82  
                 ),
 83  
                 ".html"
 84  
             ).file().toURI();
 85  
         }
 86  
     }
 87  
 
 88  
     /**
 89  
      * Web page.
 90  
      */
 91  
     @Immutable
 92  0
     @ToString
 93  0
     @EqualsAndHashCode(of = "href")
 94  
     @Loggable(Loggable.DEBUG)
 95  
     final class Web implements Page {
 96  
         /**
 97  
          * HREF.
 98  
          */
 99  
         private final transient String href;
 100  
         /**
 101  
          * Public ctor.
 102  
          * @param uri URI
 103  
          */
 104  0
         public Web(final URI uri) {
 105  0
             this.href = uri.toString();
 106  0
         }
 107  
         @Override
 108  
         public URI uri() {
 109  0
             return URI.create(this.href);
 110  
         }
 111  
     }
 112  
 
 113  
 }