001 package ezvcard.io.text;
002
003 /**
004 * Copyright 2011 George El-Haddad. All rights reserved.
005 *
006 * Redistribution and use in source and binary forms, with or without modification, are
007 * permitted provided that the following conditions are met:
008 *
009 * 1. Redistributions of source code must retain the above copyright notice, this list of
010 * conditions and the following disclaimer.
011 *
012 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
013 * of conditions and the following disclaimer in the documentation and/or other materials
014 * provided with the distribution.
015 *
016 * THIS SOFTWARE IS PROVIDED BY GEORGE EL-HADDAD ''AS IS'' AND ANY EXPRESS OR IMPLIED
017 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
018 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GEORGE EL-HADDAD OR
019 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
020 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
021 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
022 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
023 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
024 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
025 *
026 * The views and conclusions contained in the software and documentation are those of the
027 * authors and should not be interpreted as representing official policies, either expressed
028 * or implied, of George El-Haddad.
029 */
030
031 /*
032 Copyright (c) 2013, Michael Angstadt
033 All rights reserved.
034
035 Redistribution and use in source and binary forms, with or without
036 modification, are permitted provided that the following conditions are met:
037
038 1. Redistributions of source code must retain the above copyright notice, this
039 list of conditions and the following disclaimer.
040 2. Redistributions in binary form must reproduce the above copyright notice,
041 this list of conditions and the following disclaimer in the documentation
042 and/or other materials provided with the distribution.
043
044 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
045 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
046 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
047 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
048 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
049 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
050 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
051 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
052 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
053 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
054
055 The views and conclusions contained in the software and documentation are those
056 of the authors and should not be interpreted as representing official policies,
057 either expressed or implied, of the FreeBSD Project.
058 */
059
060 /**
061 * Specifies how a vCard should be folded when written to a string.
062 * @author George El-Haddad
063 * @author Michael Angstadt
064 */
065 public class FoldingScheme {
066 /**
067 * Folds lines at 75 characters (not including CRLF) and uses 1 space as
068 * indentation.
069 * @see "RFC2426 p.8"
070 */
071 public static final FoldingScheme MIME_DIR = new FoldingScheme(75, " ");
072
073 /**
074 * Folds lines at 72 characters (not including CRLF) and uses 1 space as
075 * indentation.
076 */
077 public static final FoldingScheme MS_OUTLOOK = new FoldingScheme(72, " ");
078
079 /**
080 * Folds lines at 76 characters (not including CRLF) and uses 2 spaces as
081 * indentation.
082 */
083 public static final FoldingScheme MAC_ADDRESS_BOOK = new FoldingScheme(76, " ");
084
085 private final int lineLength;
086 private final String indent;
087
088 /**
089 * Creates a folding scheme.
090 * @param lineLength the maximum number of characters that can exist on a
091 * line before needing to be folded (not including the newline)
092 * @param indent the string to use for indentation
093 * @throws IllegalArgumentException if the line length is <= 0, or if the
094 * line length is less than the length of the indentation string
095 */
096 public FoldingScheme(int lineLength, String indent) {
097 if (lineLength <= 0) {
098 throw new IllegalArgumentException("The line length must be greater than 0.");
099 }
100 if (indent.length() > lineLength) {
101 throw new IllegalArgumentException("The line length must be greater than the length of the indentation string.");
102 }
103 this.lineLength = lineLength;
104 this.indent = indent;
105 }
106
107 /**
108 * Gets the maximum number of characters that can exist on a line before
109 * needing to be folded (not including the newline).
110 * @return the max line length
111 */
112 public int getLineLength() {
113 return lineLength;
114 }
115
116 /**
117 * Gets the string that is used to indent the folded line.
118 * @return the indent string
119 */
120 public String getIndent() {
121 return indent;
122 }
123 }