ZCalendar.java

Index Score
com.zimbra.cs.mailbox.calendar
Zimbra Collaboration Suite

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
LINE_COMMENTNumber of line comments
DECL_COMMENTSComments in declarations
RETURNSNumber of return points from functions
INTERFACE_COMPLEXITYInterface complexity
JAVA0117JAVA0117 Missing javadoc: method 'method'
FUNCTIONSNumber of function declarations
JAVA0034JAVA0034 Missing braces in if statement
CYCLOMATICCyclomatic complexity
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
SIZESize of the file in bytes
OPERANDSNumber of operands
BLOCKSNumber of blocks
PARAMSNumber of formal parameter declarations
PROGRAM_LENGTHHalstead program length
OPERATORSNumber of operators
LOGICAL_LINESNumber of statements
ELOCEffective lines of code
LINESNumber of lines in the source file
LOCLines of code
EXITSProcedure exits
JAVA0266JAVA0266 Use of System.out
COMPARISONSNumber of comparison operators
COMMENTSComment lines
JAVA0177JAVA0177 Variable declaration missing initializer
JAVA0265JAVA0265 Use of Throwable.printStackTrace()
JAVA0144JAVA0144 Line exceeds maximum M characters
UNIQUE_OPERATORSNumber of unique operators
JAVA0036JAVA0036 Missing braces in while statement
JAVA0258JAVA0258 Implement Iterable for foreach compatibility
EXEC_COMMENTSComments in executable code
WHITESPACENumber of whitespace lines
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0032JAVA0032 Switch statement missing default
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0145JAVA0145 Tab character used in source file
/* * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1 * * The contents of this file are subject to the Mozilla Public License * Version 1.1 ("License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.zimbra.com/license * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is: Zimbra Collaboration Suite Server. * * The Initial Developer of the Original Code is Zimbra, Inc. * Portions created by Zimbra are Copyright (C) 2005, 2006 Zimbra, Inc. * All Rights Reserved. * * Contributor(s): * * ***** END LICENSE BLOCK ***** */ package com.zimbra.cs.mailbox.calendar; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import java.io.StringWriter; import java.io.Writer; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.regex.Pattern; import com.zimbra.common.service.ServiceException; import com.zimbra.common.util.ZimbraLog; import net.fortuna.ical4j.data.CalendarParser; import net.fortuna.ical4j.data.CalendarParserImpl; import net.fortuna.ical4j.data.ContentHandler; import net.fortuna.ical4j.data.ParserException; import net.fortuna.ical4j.data.UnfoldingReader; public class ZCalendar { public static final String sZimbraProdID = "Zimbra-Calendar-Provider"; public static final String sIcalVersion = "2.0"; public static enum ICalTok { ACTION, ALTREP, ATTACH, ATTENDEE, BINARY, BOOLEAN, CAL_ADDRESS, CALSCALE, CATEGORIES, CLASS, CN, COMMENT, COMPLETED, CONTACT, CREATED, CUTYPE, DATE, DATE_TIME, DELEGATED_FROM, DELEGATED_TO, DESCRIPTION, DIR, DTEND, DTSTAMP, DTSTART, DUE, DURATION, ENCODING, EXDATE, EXRULE, FBTYPE, FLOAT, FMTTYPE, FREEBUSY, GEO, INTEGER, LANGUAGE, LAST_MODIFIED, LOCATION, MEMBER, METHOD, ORGANIZER, PARTSTAT, PERCENT_COMPLETE, PERIOD, PRIORITY, PRODID, RDATE, RECUR, RECURRENCE_ID, RELATED, RELATED_TO, RELTYPE, REPEAT, RESOURCES, ROLE, RRULE, RSVP, SENT_BY, SEQUENCE, STATUS, SUMMARY, TEXT, TIME, TRANSP, TRIGGER, TZID, TZNAME, TZOFFSETFROM, TZOFFSETTO, TZURL, UID, URI, URL, UTC_OFFSET, VALARM, VALUE, VERSION, VEVENT, VFREEBUSY, VJOURNAL, VTIMEZONE, VTODO, // METHOD PUBLISH, REQUEST, REPLY, ADD, CANCEL, REFRESH, COUNTER, DECLINECOUNTER, // ROLE CHAIR, REQ_PARTICIPANT, OPT_PARTICIPANT, NON_PARTICIPANT, // CUTYPE INDIVIDUAL, GROUP, RESOURCE, ROOM, UNKNOWN, // STATUS TENTATIVE, CONFIRMED, /*CANCELLED,*/ NEEDS_ACTION, /*COMPLETED,*/ IN_PROCESS, CANCELLED, DRAFT, FINAL, // PARTSTAT ACCEPTED, /*COMPLETED,*/ DECLINED, DELEGATED, /*IN_PROCESS,*/ /*NEEDS_ACTION,*/ /*TENTATIVE,*/ // TRANSPARENCY TRANSPARENT, OPAQUE, // VTIMEZONE STANDARD, DAYLIGHT, // RECURRENCE-ID RANGE, THISANDFUTURE, THISANDPRIOR, X_MICROSOFT_CDO_ALLDAYEVENT, X_MICROSOFT_CDO_BUSYSTATUS, X_MICROSOFT_CDO_INTENDEDSTATUS, // ZCO Custom values X_ZIMBRA_STATUS, X_ZIMBRA_STATUS_WAITING, X_ZIMBRA_STATUS_DEFERRED, X_ZIMBRA_PARTSTAT_WAITING, X_ZIMBRA_PARTSTAT_DEFERRED; public static ICalTok lookup(String str) { try { str = str.replace('-', '_'); return ICalTok.valueOf(str); } catch (IllegalArgumentException e) { return null; } } public String toString() { return super.toString().replace('_', '-'); } } private static final String LINE_BREAK = "\r\n"; /** * @author tim * * Calendar has * Components * Properties */ public static class ZVCalendar { List<ZComponent> mComponents = new ArrayList<ZComponent>(); List<ZProperty> mProperties = new ArrayList<ZProperty>(); public ZVCalendar() { addProperty(new ZProperty(ICalTok.PRODID, sZimbraProdID)); addProperty(new ZProperty(ICalTok.VERSION, sIcalVersion)); } public void addProperty(ZProperty prop) { mProperties.add(prop); } public void addComponent(ZComponent comp) { mComponents.add(comp); } public ZComponent getComponent(ICalTok tok) { return findComponent(mComponents, tok); } public Iterator<ZComponent> getComponentIterator() { return mComponents.iterator(); } public ZProperty getProperty(ICalTok tok) { return findProp(mProperties, tok); } public String getPropVal(ICalTok tok, String defaultValue) { ZProperty prop = getProperty(tok); if (prop != null) return prop.mValue; return defaultValue; } public long getPropLongVal(ICalTok tok, long defaultValue) { ZProperty prop = getProperty(tok); if (prop != null) return Long.parseLong(prop.mValue); return defaultValue; } public String toString() { StringBuffer toRet = new StringBuffer("BEGIN:VCALENDAR"); toRet.append(LINE_BREAK); String INDENT = "\t"; for (ZProperty prop : mProperties) { toRet.append(prop.toString(INDENT)); } for (ZComponent comp : mComponents) { toRet.append(comp.toString(INDENT)); } toRet.append("END:VCALENDAR"); return toRet.toString(); } public void toICalendar(Writer w) throws IOException { w.write("BEGIN:VCALENDAR"); w.write(LINE_BREAK); for (ZProperty prop : mProperties) prop.toICalendar(w); for (ZComponent comp : mComponents) comp.toICalendar(w); w.write("END:VCALENDAR"); } // Add DESCRIPTION property to components that take that property, // if the property is not set. public void addDescription(String desc) { if (desc == null || desc.length() < 1) return; ZProperty descProp = new ZProperty(ICalTok.DESCRIPTION, desc); for (ZComponent comp : mComponents) { ICalTok name = comp.getTok(); if (ICalTok.VEVENT.equals(name) || ICalTok.VTODO.equals(name) || ICalTok.VJOURNAL.equals(name)) { ZProperty prop = comp.getProperty(ICalTok.DESCRIPTION); if (prop == null) { comp.addProperty(descProp); } else { String val = prop.getValue(); if (val == null || val.length() < 1) prop.setValue(desc); } } } } public ICalTok getMethod() { ICalTok ret = null; ZProperty method = getProperty(ICalTok.METHOD); if (method != null) { String methodStr = method.getValue(); if (methodStr != null) { try { ret = ICalTok.valueOf(methodStr); } catch (IllegalArgumentException e) {} } } return ret; } } /** * @author tim * * Component has * Name * Properties * Components */ public static class ZComponent { ZComponent(String name) { mName = name.toUpperCase(); mTok = ICalTok.lookup(mName); } ZComponent(ICalTok tok) { mTok = tok; mName = tok.toString(); } private String mName; ICalTok mTok; public String getName() { return mName; } public ICalTok getTok() { return mTok; } List<ZProperty> mProperties = new ArrayList<ZProperty>(); List<ZComponent> mComponents = new ArrayList<ZComponent>(); public void addProperty(ZProperty prop) { mProperties.add(prop); } public void addComponent(ZComponent comp) { mComponents.add(comp); } public ZComponent getComponent(ICalTok tok) { return findComponent(mComponents, tok); } public Iterator<ZComponent> getComponentIterator() { return mComponents.iterator(); } public Iterator<ZProperty> getPropertyIterator() { return mProperties.iterator(); } public ZProperty getProperty(ICalTok tok) { return findProp(mProperties, tok); } public String getPropVal(ICalTok tok, String defaultValue) { ZProperty prop = getProperty(tok); if (prop != null) return prop.mValue; return defaultValue; } long getPropLongVal(ICalTok tok, long defaultValue) { ZProperty prop = getProperty(tok); if (prop != null) return Long.parseLong(prop.mValue); return defaultValue; } public String toString() { return toString(""); } public String toString(String INDENT) { StringBuffer toRet = new StringBuffer(INDENT).append("COMPONENT:").append(mName).append('(').append(mTok).append(')').append('\n'); String NEW_INDENT = INDENT+'\t'; for (ZProperty prop : mProperties) { toRet.append(prop.toString(NEW_INDENT)); } for (ZComponent comp : mComponents) { toRet.append(comp.toString(NEW_INDENT)); } toRet.append(INDENT).append("END:").append(mName).append('\n'); return toRet.toString(); } public void toICalendar(Writer w) throws IOException { w.write("BEGIN:"); String name = escape(mName); w.write(name); w.write(LINE_BREAK); for (ZProperty prop : mProperties) prop.toICalendar(w); for (ZComponent comp : mComponents) comp.toICalendar(w); w.write("END:"); w.write(name); w.write(LINE_BREAK); } } // these are the characters that MUST be escaped: , ; " \n and \ -- note that \ // becomes \\\\ here because it is double-unescaped during the compile process! private static final Pattern MUST_ESCAPE = Pattern.compile("[,;\"\n\\\\]"); private static final Pattern SIMPLE_ESCAPE = Pattern.compile("([,;\"\\\\])"); private static final Pattern NEWLINE_ESCAPE = Pattern.compile("[\r\n]"); /** * ,;"\ and \n must all be escaped. */ public static String escape(String str) { if (str!= null && MUST_ESCAPE.matcher(str).find()) { // escape ([,;"])'s String toRet = SIMPLE_ESCAPE.matcher(str).replaceAll("\\\\$1"); // escape return NEWLINE_ESCAPE.matcher(toRet).replaceAll("\\\\n"); } return str; } private static final Pattern SIMPLE_ESCAPED = Pattern.compile("\\\\([,;\"\\\\])"); private static final Pattern NEWLINE_ESCAPED = Pattern.compile("\\\\n"); public static String unescape(String str) { if (str != null && str.indexOf('\\') >= 0) { String toRet = SIMPLE_ESCAPED.matcher(str).replaceAll("$1"); return NEWLINE_ESCAPED.matcher(toRet).replaceAll("\n"); } return str; } // From RFC2445, Section 4.1 Content Lines: // // param-value = paramtext / quoted-string // paramtext = *SAFE-CHAR // quoted-string = DQUOTE *QSAFE-CHAR DQUOTE // NON-US-ASCII = %x80-F8 // QSAFE-CHAR = WSP / %x21 / %x23-7E / NON-US-ASCII // ; Any character except CTLs and DQUOTE // SAFE-CHAR = WSP / %x21 / %x23-2B / %x2D-39 / %x3C-7E // / NON-US-ASCII // ; Any character except CTLs, DQUOTE, ";", ":", "," // CTL = %x00-08 / %x0A-1F / %x7F // // Thus a parameter value cannot contain CTLs or DQUOTE. // When a value has to be quoted, there is no need to escape // DQUOTE because it may not occur in the value. // private static final Pattern MUST_QUOTE = Pattern.compile("[;:,]"); public static String quote(String str) { if (str != null && MUST_QUOTE.matcher(str).find()) return "\"" + str + "\""; else return str; } public static String unquote(String str) { if (str != null && str.length()>2) { if ((str.charAt(0) == '\"') && (str.charAt(str.length()-1) == '\"')) return str.substring(1, str.length()-1); } return str; } /** * @author tim * * Property has * Name * Parameters * Value */ public static class ZProperty { public ZProperty(String name) { setName(name); mTok = ICalTok.lookup(mName); } public ZProperty(ICalTok tok) { mTok = tok; mName = tok.toString(); } public ZProperty(ICalTok tok, String value) { mTok = tok; mName = tok.toString(); setValue(value); } public ZProperty(ICalTok tok, boolean value) { mTok = tok; mName = tok.toString(); mValue = value ? "TRUE" : "FALSE"; } public ZProperty(ICalTok tok, long value) { mTok = tok; mName = tok.toString(); mValue = Long.toString(value); } public ZProperty(ICalTok tok, int value) { mTok = tok; mName = tok.toString(); mValue = Integer.toString(value); } public void setName(String name) { mName = unescape(name.toUpperCase()); } public void setValue(String value) { mValue = unescape(value); } List<ZParameter> mParameters = new ArrayList<ZParameter>(); public void addParameter(ZParameter param) { mParameters.add(param); } public ZParameter getParameter(ICalTok tok) { return findParameter(mParameters, tok); } public Iterator<ZParameter> parameterIterator() { return mParameters.iterator(); } public int getNumParameters() { return mParameters.size(); } String getParameterVal(ICalTok tok, String defaultValue) { ZParameter param = findParameter(mParameters, tok); if (param != null) return param.getValue(); else return defaultValue; } public String paramVal(ICalTok tok, String defaultValue) { ZParameter param = getParameter(tok); if (param != null) { return unquote(param.getValue()); } return defaultValue; } public String toString() { return toString(""); } public String toString(String INDENT) { StringBuffer toRet = new StringBuffer(INDENT).append("PROPERTY:").append(mName).append('(').append(mTok).append(')').append('\n'); String NEW_INDENT = INDENT+'\t'; for (ZParameter param: mParameters) { toRet.append(param.toString(NEW_INDENT)); } toRet.append(NEW_INDENT).append("VALUE=\"").append(mValue).append("\"\n"); toRet.append(INDENT).append("END:").append(mName).append('\n'); return toRet.toString(); } private static final int CHARS_PER_FOLDED_LINE = 76; public void toICalendar(Writer w) throws IOException { StringWriter sw = new StringWriter(); sw.write(escape(mName)); for (ZParameter param: mParameters) param.toICalendar(sw); sw.write(':'); if (mValue != null) { boolean noEscape = false; if (mTok != null) { switch (mTok) { case RRULE: case EXRULE: case RDATE: case EXDATE: noEscape = true; break; } } if (noEscape) sw.write(mValue); else sw.write(escape(mValue)); } // Write with folding. String rawval = sw.toString(); int len = rawval.length(); for (int i = 0; i < len; i += CHARS_PER_FOLDED_LINE) { int upto = Math.min(i + CHARS_PER_FOLDED_LINE, len); String segment = rawval.substring(i, upto); if (i > 0) { w.write(LINE_BREAK); w.write(' '); } w.write(segment); } w.write(LINE_BREAK); } public ICalTok getToken() { return mTok; } // may be null public String getName() { return mName; } public String getValue() { return mValue; } long getLongValue() { return Long.parseLong(mValue); }; int getIntValue() { return Integer.parseInt(mValue); }; boolean getBoolValue() { return mValue.equalsIgnoreCase("TRUE"); } ICalTok mTok; String mName; String mValue; } /** * @author tim * * Name:Value pair */ public static class ZParameter { public ZParameter(String name, String value) { setName(name); setValue(value); mTok = ICalTok.lookup(mName); } public ZParameter(ICalTok tok, String value) { mTok = tok; mName = tok.toString(); setValue(value); } public ZParameter(ICalTok tok, boolean value) { mTok = tok; mName = tok.toString(); maValue = value ? "TRUE" : "FALSE"; } public void setName(String name) { mName = unescape(name.toUpperCase()); } public void setValue(String value) { maValue = unescape(unquote(value)); } public String toString() { return toString(""); } public String toString(String INDENT) { StringBuffer toRet = new StringBuffer(INDENT).append("PARAM:").append(mName).append('(').append(mTok).append(')').append(':').append(maValue).append('\n'); return toRet.toString(); } public void toICalendar(Writer w) throws IOException { w.write(';'); w.write(escape(mName)); w.write('='); if (maValue == null || maValue.length()==0) { w.write("\"\""); // bug 4941: cannot put a completely blank parameter value, will confuse parsers } else if (ICalTok.CN.equals(mTok)) { // Outlook special: // Outlook's MIME parser chokes when CN value containing // characters with high bit set isn't quoted, even though it is // not necessary to quote according to RFC2445. w.write(sanitizeParamValue(maValue)); } else if (maValue.startsWith("\"") && maValue.endsWith("\"")) { w.write('\"'); w.write(escape(maValue.substring(1, maValue.length()-1))); w.write('\"'); } else if (ICalTok.TZID.equals(mTok)) { // Microsoft Entourage 2004 (Outlook-like program for Mac) // insists on quoting TZID parameter value (but not TZID // property value). It's an Entourage bug, but we have to // keep it happy with a hacky quoting policy. w.write('\"'); w.write(maValue); w.write('\"'); } else { w.write(quote(maValue)); } } public ICalTok getToken() { return mTok; } // may be null public String getName() { return mName; } public String getValue() { return maValue; } long getLongValue() { return Long.parseLong(maValue); }; int getIntValue() { return Integer.parseInt(maValue); }; ICalTok mTok; String mName; String maValue; /** * Sanitize a string to make it a valid param-value. DQUOTE * is changed to a single quote and CTL chars are changed to question * marks ('?'). String is quoted if str is already quoted or if it * contains ',', ':' or ';'. * * To workaround a bug in Outlook's MIME parser (see bug 12008), string * is quoted if any non-US-ASCII chars are present, e.g. non-English * names. (These characters don't require quoting according to * RFC2445.) * * Empty string is returned if str is null or is an empty string. * * @param str * @return */ private static String sanitizeParamValue(String str) { if (str == null) return ""; int len = str.length(); if (len == 0) return ""; boolean needToQuote; int start, end; // index of first and last char to examine // end is last char + 1 if (len >= 2 && str.charAt(0) == '"' && str.charAt(len - 1) == '"') { needToQuote = true; start = 1; end = len - 1; } else { needToQuote = false; start = 0; end = len; } StringBuilder sb = new StringBuilder(len + 2); sb.append('"'); // always start with quote for (int i = start; i < end; i++) { // Some chars require quoting, others require changing to a // valid char. No char requires both. char ch = str.charAt(i); if ((ch >= 0x3C && ch <= 0x7E) // "<=>?@ABC ..." (English letters) || ch == 0x20 // space || (ch >= 0x2D && ch <= 0x39) // "-./0123456789" || (ch >= 0x23 && ch <= 0x2B) // "#$%&'()*+" || ch == 0x09 // horizontal tab || ch == 0x21) { // '!' // Char is okay. } else if (ch >= 0x80 // NON-US-ASCII and higher || ch == 0x2C // ',' || ch == 0x3A // ':' || ch == 0x3B) { // ';' // Chars 0x80 and above don't need to be quoted in RFC2445, // but Outlook thinks differently. (bug 12008) needToQuote = true; } else if (ch == 0x22) { // '"' // DQUOTE is not allowed. Change to single quote. ch = '\''; } else { // ch is a CTL: // 0x00 <= ch <= 0x08 or // 0x0A <= ch <= 0x1F or // ch == 0x7F // CTL is invalid in a param-value, so change to a '?'. ch = '?'; } sb.append(ch); } sb.append('"'); // matches initial quote if (needToQuote) return sb.toString(); else return sb.substring(1, sb.length() - 1); } } static ZProperty findProp(List <ZProperty> list, ICalTok tok) { for (ZProperty prop : list) { if (prop.mTok == tok) { return prop; } } return null; } static ZParameter findParameter(List <ZParameter> list, ICalTok tok) { for (ZParameter param: list) { if (param.mTok == tok) { return param; } } return null; } static ZComponent findComponent(List <ZComponent> list, ICalTok tok) { for (ZComponent comp: list) { if (comp.mTok == tok) { return comp; } } return null; } // private static class UnfoldingReader : extends FilterReader // { // Reader mIn; // // char[] mBuf = new char[3]; // // boolean buffering = false; // boolean atNl = false; // int bufPos = 0; // // // // UnfoldingReader(Reader in) { // mIn = in; // } // // int read() { // int read = read(); // // // buffering? // // yes: // // at nl? // // yes: // // is space? // // yes: // // eat 1 space, done buffering // // no: // // don't eat, done buffering // // no: // // is it a '\n'? // // yes: // // at nl=true. still buffering // // no: // // don't eat. done buffering // // no: // // is it a '\r'? // // buffering, not at nl // // is it a '\n'? // // buffering. at nl // // return it // // // if (buffering) { // if (atNl) { // if ((char)read == ' ') { // // } // } // } else { // // } // // // } // // int read(char[] cbuf, int off, int len) { // // for (int i = 0; i < len; i++) { // int read = read(); // if (read == -1) // return i; // // cbuf[i+off] = (char)read; // } // return len; // } // // // } // // // private static class Parser // { // ZVCalendar mCal = null; // ArrayList<ZComponent> mComponents = new ArrayList(); // ZProperty mCurProperty = null; // StringBuffer curLine = null; // // StreamTokenizer mTokenizer; // //n static enum Token { // BEGIN, VCALENDAR, END, COLON; // // Token lookup(String str) { // if (str.equals(":")) // return COLON; // // return Token.valueOf(str); // } // } // // static ZVCalendar parse(Reader in) throws ServiceException { // Parser p = new Parser(in); // return p.mCal; // } // // private Parser(Reader in) throws ServiceException { // mTokenizer = new StreamTokenizer(in); // mTokenizer.wordChars(32, 127); // mTokenizer.whitespaceChars(0, 20); // mTokenizer.eolIsSignificant(true); // mTokenizer.quoteChar('"'); // mTokenizer.ordinaryChar(';'); // mTokenizer.ordinaryChar(':'); // mTokenizer.ordinaryChar('='); // } // // private int nextToken() // { // int toRet = nextToken(); // // } // // private void parseError(String expected) throws ServiceException // { // throw ServiceException.PARSE_ERROR("Expected \""+expected+"\" at l, cause) // } // // private void expectToken(String token) throws ServiceException // { // if (tokeniser.nextToken() != StreamTokenizer.TT_WORD) { // throw ServiceException.PARSE_ERROR("Expected \""+token, cause) // // } // // // // private void expectToken(Integer ch) throws ServiceException // { // // } // // // } private static class ZContentHandler implements ContentHandler { List<ZVCalendar> mCals = new ArrayList<ZVCalendar>(1); ZVCalendar mCurCal = null; List<ZComponent> mComponents = new ArrayList<ZComponent>(); ZProperty mCurProperty = null; public void startCalendar() { mCurCal = new ZVCalendar(); mCals.add(mCurCal); } public void endCalendar() { mCurCal = null; } public void startComponent(String name) { ZComponent newComponent = new ZComponent(name); if (mComponents.size() > 0) { mComponents.get(mComponents.size()-1).mComponents.add(newComponent); } else { mCurCal.mComponents.add(newComponent); } mComponents.add(newComponent); } public void endComponent(String name) { mComponents.remove(mComponents.size()-1); } public void startProperty(String name) { mCurProperty = new ZProperty(name); if (mComponents.size() > 0) { mComponents.get(mComponents.size()-1).mProperties.add(mCurProperty); } else { mCurCal.mProperties.add(mCurProperty); } } public void propertyValue(String value) { mCurProperty.mValue = value; } public void endProperty(String name) { mCurProperty = null; } public void parameter(String name, String value) { ZParameter param = new ZParameter(name, value); if (mCurProperty != null) { mCurProperty.mParameters.add(param); } else { ZimbraLog.calendar.debug("ERROR: got parameter " + name + "," + value + " outside of Property"); } } } public static class ZCalendarBuilder { public static ZVCalendar build(Reader reader) throws ServiceException { List<ZVCalendar> list = buildMulti(reader); int len = list.size(); if (len == 1) { return list.get(0); } else if (len > 1) { ZimbraLog.calendar.warn( "Returning only the first ZCALENDAR after parsing " + len); return list.get(0); } else { throw ServiceException.PARSE_ERROR("No ZCALENDAR found", null); } } public static List<ZVCalendar> buildMulti(Reader reader) throws ServiceException { BufferedReader br = new BufferedReader(reader); reader = br; try { reader.mark(32000); } catch(IOException e) { e.printStackTrace(); } CalendarParser parser = new CalendarParserImpl(); ZContentHandler handler = new ZContentHandler(); try { parser.parse(new UnfoldingReader(reader), handler); } catch (IOException e) { throw ServiceException.FAILURE("Caught IOException parsing calendar: " + e, e); } catch (ParserException e) { StringBuilder s = new StringBuilder("Caught ParseException parsing calendar: " + e); try { reader.reset(); s.append('\n'); int charRead; while ((charRead = reader.read()) != -1) s.append((char) charRead); } catch (IOException ioe) { ioe.printStackTrace(); } throw ServiceException.PARSE_ERROR(s.toString(), e); } return handler.mCals; } } /** * @param args */ public static void main(String[] args) { try { /** * ,;"\ and \n must all be escaped. */ { String s; s = "This, is; my \"string\", and\\or \nI hope\r\nyou like it"; System.out.println("Original: "+s+"\n\n\nEscaped: "+escape(s)+"\n\n\nUnescaped:"+unescape(escape(s))); System.out.println("\n\n\n"); s = "\"Foo Bar Gub\""; System.out.println("Unquoted:"+s+"\nQuoted:"+unquote(s)); System.out.println("\n\n\n"); s = "Blah Bar Blah"; System.out.println("Unquoted:"+s+"\nQuoted:"+unquote(s)); System.out.println("\n\n\n"); { s = "\"US & Canadia -- Foo\\Bar\""; System.out.println("String = "+s); ZParameter param = new ZParameter(ICalTok.TZID, s); System.out.println("TZID = "+param.getValue()); StringWriter writer = new StringWriter(); param.toICalendar(writer); System.out.println("ICAL: "+writer.toString()); System.out.println("\n\n\n"); } } if (false) { File inFile = new File("c:\\test.ics"); FileReader in = new FileReader(inFile); CalendarParser parser = new CalendarParserImpl(); ZContentHandler handler = new ZContentHandler(); parser.parse(new UnfoldingReader(in), handler); ZVCalendar cal = handler.mCals.get(0); System.out.println(cal.toString()); Invite.createFromCalendar(null, null, cal, false); } } catch(Exception e) { System.out.println("Caught exception: "+e); e.printStackTrace(); } } }

The table below shows all metrics for ZCalendar.java.

MetricValueDescription
BLOCKS146.00Number of blocks
BLOCK_COMMENT24.00Number of block comment lines
COMMENTS263.00Comment lines
COMMENT_DENSITY 0.53Comment density
COMPARISONS78.00Number of comparison operators
CYCLOMATIC164.00Cyclomatic complexity
DECL_COMMENTS153.00Comments in declarations
DOC_COMMENT53.00Number of javadoc comment lines
ELOC499.00Effective lines of code
EXEC_COMMENTS12.00Comments in executable code
EXITS87.00Procedure exits
FUNCTIONS84.00Number of function declarations
HALSTEAD_DIFFICULTY81.55Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY217.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 1.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 2.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 1.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003417.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 1.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 1.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 1.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 1.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 0.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 2.00JAVA0116 Missing javadoc: field 'field'
JAVA011756.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 2.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 3.00JAVA0144 Line exceeds maximum M characters
JAVA0145 4.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 1.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 5.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 1.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 3.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 1.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 3.00JAVA0265 Use of Throwable.printStackTrace()
JAVA026612.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES997.00Number of lines in the source file
LINE_COMMENT186.00Number of line comments
LOC613.00Lines of code
LOGICAL_LINES322.00Number of statements
LOOPS 3.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS1708.00Number of operands
OPERATORS2809.00Number of operators
PARAMS74.00Number of formal parameter declarations
PROGRAM_LENGTH4517.00Halstead program length
PROGRAM_VOCAB631.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS143.00Number of return points from functions
SIZE34727.00Size of the file in bytes
UNIQUE_OPERANDS576.00Number of unique operands
UNIQUE_OPERATORS55.00Number of unique operators
WHITESPACE121.00Number of whitespace lines