s243a

ClientMetadata.java (freenet.client)

Oct 22nd, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.35 KB | None | 0 0
  1. // s243a pearltree node: http://www.pearltrees.com/s243a/clientmetadata-freenet-client/id12827764
  2. /* This code is part of Freenet. It is distributed under the GNU General
  3.  * Public License, version 2 (or at your option any later version). See
  4.  * http://www.gnu.org/ for further details of the GPL. */
  5. package freenet.client;
  6.  
  7. import com.db4o.ObjectContainer;
  8.  
  9. /**
  10.  * Stores the metadata that the client might actually be interested in.
  11.  * Currently this is just the MIME type, but in future it might be more than
  12.  * that. Size is not stored here, but maybe things like dublin core or
  13.  * whatever.
  14.  */
  15. // WARNING: THIS CLASS IS STORED IN DB4O -- THINK TWICE BEFORE ADD/REMOVE/RENAME FIELDS
  16. public class ClientMetadata implements Cloneable {
  17.    
  18.     /** The document MIME type */
  19.     private String mimeType;
  20.  
  21.     public ClientMetadata(){
  22.         mimeType = null;
  23.     }
  24.  
  25.     public ClientMetadata(String mime) {
  26.         mimeType = (mime == null) ? null : mime.intern();
  27.     }
  28.    
  29.     /** Get the document MIME type. Will always be a valid MIME type, unless there
  30.      * has been an error; if it is unknown, will return application/octet-stream. */
  31.     public String getMIMEType() {
  32.         if((mimeType == null) || (mimeType.length() == 0))
  33.             return DefaultMIMETypes.DEFAULT_MIME_TYPE;
  34.         return mimeType;
  35.     }
  36.  
  37.     /**
  38.      * Merge the given ClientMetadata, without overwriting our
  39.      * existing information.
  40.      */
  41.     public void mergeNoOverwrite(ClientMetadata clientMetadata) {
  42.         if((mimeType == null) || mimeType.equals(""))
  43.             mimeType = clientMetadata.mimeType;
  44.     }
  45.  
  46.     /** Is there no MIME type? */
  47.     public boolean isTrivial() {
  48.         return ((mimeType == null) || mimeType.equals(""));
  49.     }
  50.    
  51.     @Override
  52.     public ClientMetadata clone() {
  53.         try {
  54.             return (ClientMetadata) super.clone();
  55.         } catch (CloneNotSupportedException e) {
  56.             throw new Error(e);
  57.         }
  58.     }
  59.    
  60.     @Override
  61.     public String toString() {
  62.         return getMIMEType();
  63.     }
  64.  
  65.     /** Clear the MIME type. */
  66.     public void clear() {
  67.         mimeType = null;
  68.     }
  69.  
  70.     /** Return the MIME type minus any type parameters (e.g. charset, see
  71.      * the RFCs defining the MIME type for details). */
  72.     public String getMIMETypeNoParams() {
  73.         String s = mimeType;
  74.         if(s == null) return null;
  75.         int i = s.indexOf(';');
  76.         if(i > -1) {
  77.             s = s.substring(i);
  78.         }
  79.         return s;
  80.     }
  81.  
  82.     public void removeFrom(ObjectContainer container) {
  83.         container.delete(this);
  84.     }
  85. }
Add Comment
Please, Sign In to add comment