Search in sources :

Example 1 with VCard

use of net.fortuna.ical4j.vcard.VCard in project stanbol by apache.

the class VcardIndexingSource method main.

public static void main(String[] args) throws Exception {
    VcardIndexingSource instance = new VcardIndexingSource();
    instance.prefix = "http://test.org/";
    VCardBuilder parser = new VCardBuilder(new InputStreamReader(new FileInputStream(new File(args[0])), "utf8"));
    Map<EntityType, Map<String, Set<String>>> entityMap = new EnumMap<EntityType, Map<String, Set<String>>>(EntityType.class);
    entityMap.put(EntityType.organization, new HashMap<String, Set<String>>());
    entityMap.put(EntityType.person, new HashMap<String, Set<String>>());
    for (VCard vcard : parser.buildAll()) {
        instance.processVcard(vcard, OntologyMappings.schemaOrgMappings, entityMap);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) VCardBuilder(net.fortuna.ical4j.vcard.VCardBuilder) File(java.io.File) EnumMap(java.util.EnumMap) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) VCard(net.fortuna.ical4j.vcard.VCard)

Example 2 with VCard

use of net.fortuna.ical4j.vcard.VCard 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 VCard

use of net.fortuna.ical4j.vcard.VCard in project bw-calendar-engine by Bedework.

the class AbstractDirImpl method find.

@Override
public List<BwPrincipalInfo> find(final String cua, final String cutype, final boolean expand, final Holder<Boolean> truncated) throws CalFacadeException {
    final CardDavInfo cdi = getCardDavInfo(false);
    if ((cdi == null) || (cdi.getHost() == null)) {
        return null;
    }
    BasicHttpClient cdc = null;
    try {
        cdc = new BasicHttpClient(cdi.getHost(), cdi.getPort(), null, 15 * 1000);
        final List<BwPrincipalInfo> pis = find(cdc, cdi, cua, cutype);
        if (!expand) {
            return pis;
        }
        for (final BwPrincipalInfo pi : pis) {
            if (!Kind.GROUP.getValue().equalsIgnoreCase(pi.getKind())) {
                continue;
            }
            final List<BwPrincipalInfo> memberPis = new ArrayList<>();
            VCard card = pi.getCard();
            List<Property> members = card.getProperties(Id.MEMBER);
            if (members == null) {
                continue;
            }
            for (final Property p : members) {
                BwPrincipalInfo memberPi = fetch(cdc, cdi, p.getValue());
                if (memberPi != null) {
                    memberPis.add(memberPi);
                }
            }
            pi.setMembers(memberPis);
        }
        return pis;
    } catch (final Throwable t) {
        if (getLogger().isDebugEnabled()) {
            error(t);
        }
        throw new CalFacadeException(t);
    } finally {
        if (cdc != null) {
            try {
                cdc.release();
            } catch (final Throwable ignored) {
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) BasicHttpClient(org.bedework.util.http.BasicHttpClient) CardDavInfo(org.bedework.calfacade.configs.CardDavInfo) BwPrincipalInfo(org.bedework.calfacade.BwPrincipalInfo) VCard(net.fortuna.ical4j.vcard.VCard) BooleanPrincipalProperty(org.bedework.calfacade.BwPrincipalInfo.BooleanPrincipalProperty) IntPrincipalProperty(org.bedework.calfacade.BwPrincipalInfo.IntPrincipalProperty) Property(net.fortuna.ical4j.vcard.Property) WebdavProperty(org.bedework.webdav.servlet.shared.WebdavProperty) BwProperty(org.bedework.calfacade.BwProperty) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

VCard (net.fortuna.ical4j.vcard.VCard)3 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 InputStreamReader (java.io.InputStreamReader)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Property (net.fortuna.ical4j.vcard.Property)1 VCardBuilder (net.fortuna.ical4j.vcard.VCardBuilder)1 BwPrincipalInfo (org.bedework.calfacade.BwPrincipalInfo)1 BooleanPrincipalProperty (org.bedework.calfacade.BwPrincipalInfo.BooleanPrincipalProperty)1 IntPrincipalProperty (org.bedework.calfacade.BwPrincipalInfo.IntPrincipalProperty)1 BwProperty (org.bedework.calfacade.BwProperty)1 Dump (org.bedework.calfacade.annotations.Dump)1