Search in sources :

Example 1 with NoWrap

use of org.bedework.calfacade.annotations.NoWrap in project bw-calendar-engine by Bedework.

the class BwEvent method inDateTimeRange.

/**
 * Returns true if the event start and end dates lie within the specified
 * limits. Either or both of start and end may be null.
 *
 * @param start - UTC date/time or null
 * @param end - UTC date/time or null
 * @return true if event satisfies the limits
 */
@NoProxy
@NoWrap
public boolean inDateTimeRange(final String start, final String end) {
    if ((getEntityType() == IcalDefs.entityTypeTodo) && getNoStart()) {
        // XXX Wrong? - true if start - end covers today?
        return true;
    }
    String evStart = getDtstart().getDate();
    String evEnd = getDtend().getDate();
    int evstSt;
    if (end == null) {
        // < infinity
        evstSt = -1;
    } else {
        evstSt = evStart.compareTo(end);
    }
    if (evstSt >= 0) {
        return false;
    }
    int evendSt;
    if (start == null) {
        // > infinity
        evendSt = 1;
    } else {
        evendSt = evEnd.compareTo(start);
    }
    if ((evendSt > 0) || (evStart.equals(evEnd) && (evendSt >= 0))) {
        // Passed the tests.
        return true;
    }
    return false;
}
Also used : ToString(org.bedework.util.misc.ToString) NoProxy(org.bedework.calfacade.annotations.ical.NoProxy) NoWrap(org.bedework.calfacade.annotations.NoWrap)

Example 2 with NoWrap

use of org.bedework.calfacade.annotations.NoWrap in project bw-calendar-engine by Bedework.

the class DumpEntity method dump.

/**
 * Dump the entire entity into the given file.
 *
 * @param f - the file
 * @throws CalFacadeException
 */
@NoWrap
public void dump(final File f) throws CalFacadeException {
    Dump dCl = getClass().getAnnotation(Dump.class);
    if (dCl.format() == DumpFormat.xml) {
        Writer wtr = null;
        try {
            XmlEmit xml = new XmlEmit();
            wtr = new FileWriter(f);
            xml.startEmit(wtr);
            dump(xml, DumpType.def, false);
            xml.flush();
            return;
        } catch (CalFacadeException cfe) {
            throw cfe;
        } catch (Throwable t) {
            throw new CalFacadeException(t);
        } finally {
            if (wtr != null) {
                try {
                    wtr.close();
                } catch (Throwable t) {
                    throw new CalFacadeException(t);
                }
            }
        }
    }
    if (dCl.format() == DumpFormat.vCard) {
        Writer wtr = null;
        try {
            VCard vc = new VCard();
            dump(vc, DumpType.def);
            String vcStr = vc.toString();
            wtr = new FileWriter(f);
            wtr.append(vcStr);
            return;
        } catch (CalFacadeException cfe) {
            throw cfe;
        } catch (Throwable t) {
            throw new CalFacadeException(t);
        } finally {
            if (wtr != null) {
                try {
                    wtr.close();
                } catch (Throwable t) {
                    throw new CalFacadeException(t);
                }
            }
        }
    }
    throw new CalFacadeException("Unsupported dump format " + dCl.format());
}
Also used : NoDump(org.bedework.calfacade.annotations.NoDump) Dump(org.bedework.calfacade.annotations.Dump) FileWriter(java.io.FileWriter) XmlEmit(org.bedework.util.xml.XmlEmit) VCard(net.fortuna.ical4j.vcard.VCard) FileWriter(java.io.FileWriter) Writer(java.io.Writer) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) NoWrap(org.bedework.calfacade.annotations.NoWrap)

Example 3 with NoWrap

use of org.bedework.calfacade.annotations.NoWrap in project bw-calendar-engine by Bedework.

the class DumpEntity method dump.

/* ====================================================================
   *                   Private Vcard methods
   * ==================================================================== */
/**
 * Dump this entity as a vcard.
 *
 * @param vc
 * @param dtype
 * @throws CalFacadeException
 */
@NoWrap
private void dump(final VCard vc, final DumpType dtype) throws CalFacadeException {
    if (!hasDumpValue()) {
        return;
    }
    NoDump ndCl = getClass().getAnnotation(NoDump.class);
    Dump dCl = getClass().getAnnotation(Dump.class);
    /* If dumpKeyFields is true we are dumping a field which is referred to by
     * a key field - for example, a principal is addressed by the principal
     * href.
     */
    boolean dumpKeyFields = dtype == DumpType.reference;
    ArrayList<String> noDumpMethods = null;
    ArrayList<String> firstMethods = null;
    try {
        if (ndCl != null) {
            if (ndCl.value().length == 0) {
                return;
            }
            noDumpMethods = new ArrayList<String>();
            for (String m : ndCl.value()) {
                noDumpMethods.add(m);
            }
        }
        if (!dumpKeyFields && (dCl != null) && (dCl.firstFields().length != 0)) {
            firstMethods = new ArrayList<String>();
            for (String f : dCl.firstFields()) {
                firstMethods.add(methodName(f));
            }
        }
        QName qn = null;
    /*
      if (dtype != DumpType.compound) {
        qn = startElement(xml, getClass(), dCl);
      }

      Collection<ComparableMethod> ms = findGetters(dCl, dtype);

      if (firstMethods != null) {
        doFirstMethods:
        for (String methodName: firstMethods) {
          for (ComparableMethod cm: ms) {
            Method m = cm.m;

            if (methodName.equals(m.getName())) {
              Dump d = m.getAnnotation(Dump.class);

              dumpValue(xml, m, d, m.invoke(this, (Object[])null), fromCollection);

              continue doFirstMethods;
            }
          }

          error("Listed first field has no corresponding getter: " + methodName);
        }
      }

      for (ComparableMethod cm: ms) {
        Method m = cm.m;

        if ((noDumpMethods != null) &&
            noDumpMethods.contains(fieldName(m.getName()))) {
          continue;
        }

        if ((firstMethods != null) &&
            firstMethods.contains(m.getName())) {
          continue;
        }

        Dump d = m.getAnnotation(Dump.class);

        dumpValue(xml, m, d, m.invoke(this, (Object[])null), fromCollection);
      }

      if (qn != null) {
        closeElement(xml, qn);
      }
      */
    // } catch (CalFacadeException cfe) {
    // throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : NoDump(org.bedework.calfacade.annotations.NoDump) NoDump(org.bedework.calfacade.annotations.NoDump) Dump(org.bedework.calfacade.annotations.Dump) QName(javax.xml.namespace.QName) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) NoWrap(org.bedework.calfacade.annotations.NoWrap)

Example 4 with NoWrap

use of org.bedework.calfacade.annotations.NoWrap in project bw-calendar-engine by Bedework.

the class DumpEntity method dump.

/* ====================================================================
   *                   Private XML methods
   * ==================================================================== */
/**
 * Dump this entity as xml.
 *
 * @param xml
 * @param dtype
 * @param fromCollection  true if the value is a member of a collection
 * @throws CalFacadeException
 */
@NoWrap
private void dump(final XmlEmit xml, final DumpType dtype, final boolean fromCollection) throws CalFacadeException {
    if (!hasDumpValue()) {
        return;
    }
    NoDump ndCl = getClass().getAnnotation(NoDump.class);
    Dump dCl = getClass().getAnnotation(Dump.class);
    boolean dumpKeyFields = dtype == DumpType.reference;
    ArrayList<String> noDumpMethods = null;
    ArrayList<String> firstMethods = null;
    try {
        if (ndCl != null) {
            if (ndCl.value().length == 0) {
                return;
            }
            noDumpMethods = new ArrayList<String>();
            for (String m : ndCl.value()) {
                noDumpMethods.add(m);
            }
        }
        if (!dumpKeyFields && (dCl != null) && (dCl.firstFields().length != 0)) {
            firstMethods = new ArrayList<String>();
            for (String f : dCl.firstFields()) {
                firstMethods.add(methodName(f));
            }
        }
        QName qn = null;
        if (fromCollection || (dtype != DumpType.compound)) {
            qn = startElement(xml, getClass(), dCl);
        }
        Collection<ComparableMethod> ms = findGetters(dCl, dtype);
        if (firstMethods != null) {
            doFirstMethods: for (String methodName : firstMethods) {
                for (ComparableMethod cm : ms) {
                    Method m = cm.m;
                    if (methodName.equals(m.getName())) {
                        Dump d = m.getAnnotation(Dump.class);
                        dumpValue(xml, m, d, m.invoke(this, (Object[]) null), fromCollection);
                        continue doFirstMethods;
                    }
                }
                error("Listed first field has no corresponding getter: " + methodName);
            }
        }
        for (ComparableMethod cm : ms) {
            Method m = cm.m;
            if ((noDumpMethods != null) && noDumpMethods.contains(fieldName(m.getName()))) {
                continue;
            }
            if ((firstMethods != null) && firstMethods.contains(m.getName())) {
                continue;
            }
            Dump d = m.getAnnotation(Dump.class);
            dumpValue(xml, m, d, m.invoke(this, (Object[]) null), fromCollection);
        }
        if (qn != null) {
            closeElement(xml, qn);
        }
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : NoDump(org.bedework.calfacade.annotations.NoDump) NoDump(org.bedework.calfacade.annotations.NoDump) Dump(org.bedework.calfacade.annotations.Dump) QName(javax.xml.namespace.QName) Method(java.lang.reflect.Method) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) NoWrap(org.bedework.calfacade.annotations.NoWrap)

Aggregations

NoWrap (org.bedework.calfacade.annotations.NoWrap)4 Dump (org.bedework.calfacade.annotations.Dump)3 NoDump (org.bedework.calfacade.annotations.NoDump)3 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)3 QName (javax.xml.namespace.QName)2 FileWriter (java.io.FileWriter)1 Writer (java.io.Writer)1 Method (java.lang.reflect.Method)1 VCard (net.fortuna.ical4j.vcard.VCard)1 NoProxy (org.bedework.calfacade.annotations.ical.NoProxy)1 ToString (org.bedework.util.misc.ToString)1 XmlEmit (org.bedework.util.xml.XmlEmit)1