Java Code Examples for org.apache.jackrabbit.webdav.xml.DomUtil#getAttribute()

The following examples show how to use org.apache.jackrabbit.webdav.xml.DomUtil#getAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextMatchFilter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a TextMatchFilter object from a DOM Element
 * @param element The dom element.
 * @throws ParseException - if something is wrong this exception is thrown.
 */
public TextMatchFilter(Element element) throws ParseException {
    // Element data is string to match
    // TODO: do we need to do this replacing??
    value = DomUtil.getTextTrim(element).replaceAll("'", "''");
    
    // Check attribute for collation
    collation =
        DomUtil.getAttribute(element, ATTR_CALDAV_COLLATION,null);
                
    String negateCondition = 
        DomUtil.getAttribute(element, ATTR_CALDAV_NEGATE_CONDITION,null);
    
    if((negateCondition == null) || !VALUE_YES.equals(negateCondition)) {
        isNegateCondition = false;
    }
    else {
        isNegateCondition = true;
    }
}
 
Example 2
Source File: TimeRangeFilter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a TimeRangeFilter object from a DOM Element
 * @param element The DOM Element.
 * @throws ParseException - if something is wrong this exception is thrown.
 */
public TimeRangeFilter(Element element, VTimeZone timezone) throws ParseException {        
    // Get start (must be present)
    String start =
        DomUtil.getAttribute(element, ATTR_CALDAV_START, null);
    if (start == null) {
        throw new ParseException("CALDAV:comp-filter time-range requires a start time", -1);
    }
    
    DateTime trstart = new DateTime(start);
    if (! trstart.isUtc()) {
        throw new ParseException("CALDAV:param-filter timerange start must be UTC", -1);
    }

    // Get end (must be present)
    String end =
        DomUtil.getAttribute(element, ATTR_CALDAV_END, null);        
    DateTime trend = end != null ? new DateTime(end) : getDefaultEndDate(trstart);
    
    if (! trend.isUtc()) {
        throw new ParseException("CALDAV:param-filter timerange end must be UTC", -1);
    }

    setPeriod(new Period(trstart, trend));
    setTimezone(timezone);
}
 
Example 3
Source File: ComponentFilter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
private void validateName(Element element) throws ParseException {
    name = DomUtil.getAttribute(element, ATTR_CALDAV_NAME, null);

    if (name == null) {
        throw new ParseException(
                "CALDAV:comp-filter a calendar component name  (e.g., \"VEVENT\") is required",
                -1);
    }

    if (!(name.equals(Calendar.VCALENDAR) 
        || CalendarUtils.isSupportedComponent(name) 
        || name.equals(Component.VALARM) 
        || name.equals(Component.VTIMEZONE))) {
        throw new ParseException(name + " is not a supported iCalendar component", -1);
    }
}
 
Example 4
Source File: ParamFilter.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a ParamFilter object from a DOM Element
 * @param element The element.
 * @throws ParseException - if something is wrong this exception is thrown.
 */
public ParamFilter(Element element) throws ParseException {
    // Get name which must be present
    name = DomUtil.getAttribute(element, ATTR_CALDAV_NAME, null);

    if (name == null) {
        throw new ParseException(
                "CALDAV:param-filter a property parameter name (e.g., \"PARTSTAT\") is required",
                -1);
    }

    // Can only have a single ext-match element
    ElementIterator i = DomUtil.getChildren(element);
    
    if(i.hasNext()) {
        
        Element child = i.nextElement();

        if (i.hasNext()) {
            throw new ParseException(
                    "CALDAV:param-filter only a single text-match or is-not-defined element is allowed",
                    -1);
        }

        if (ELEMENT_CALDAV_TEXT_MATCH.equals(child.getLocalName())) {
            textMatchFilter = new TextMatchFilter(child);

        } else if (ELEMENT_CALDAV_IS_NOT_DEFINED.equals(child.getLocalName())) {

            isNotDefinedFilter = new IsNotDefinedFilter();
        } else {
            throw new ParseException("CALDAV:param-filter an invalid element name found", -1);
        }
    }
}
 
Example 5
Source File: StandardDavProperty.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Returns an instance of <code>StandardDavProperty</code> representing
 * the given element. The element itself is provided as the property value.
 * If either the element or its parent element has the attribute
 * <code>xml:lang</code>, that attribute's value is provided as the
 * property's language. The resulting property is not "protected" (i.e.
 * it will not appear in "allprop" <code>PROPFIND</code> responses).
 * </p>
 */
public static StandardDavProperty createFromXml(Element e) {
    DavPropertyName name = DavPropertyName.createFromXml(e);
    String lang = DomUtil.getAttribute(e, XML_LANG, NAMESPACE_XML);
    if (lang == null && e.getParentNode() != null &&
        e.getParentNode().getNodeType() == Node.ELEMENT_NODE) {
        lang = DomUtil.getAttribute((Element)e.getParentNode(), XML_LANG,
                                    NAMESPACE_XML);
    }
    return new StandardDavProperty(name, e, lang);
}
 
Example 6
Source File: PropertyFilter.java    From cosmo with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a PropertyFilter object from a DOM Element
 * @param element The element.
 * @param timezone The timezone.
 * @throws ParseException - if something is wrong this exception is thrown.
 */
public PropertyFilter(Element element, VTimeZone timezone) throws ParseException {
    // Name must be present
    name = DomUtil.getAttribute(element, ATTR_CALDAV_NAME, null);
    if (name == null) {
        throw new ParseException("CALDAV:prop-filter a calendar property name (e.g., \"ATTENDEE\") is required", -1);
    }

    ElementIterator i = DomUtil.getChildren(element);
    int childCount = 0;
    
    while (i.hasNext()) {
        Element child = i.nextElement();
        childCount++;
        
        // if is-not-defined is present, then nothing else can be present
        if(childCount>1 && isNotDefinedFilter!=null) {
            throw new ParseException("CALDAV:is-not-defined cannnot be present with other child"
                    + " elements",-1); 
        }
        if (ELEMENT_CALDAV_TIME_RANGE.
            equals(child.getLocalName())) {

            // Can only have one time-range or text-match
            if (timeRangeFilter!=null) {
                throw new ParseException("CALDAV:prop-filter only one time-range or text-match "
                        + "element permitted", -1);
            }
            timeRangeFilter = new TimeRangeFilter(child, timezone);
        } else if (ELEMENT_CALDAV_TEXT_MATCH.
                   equals(child.getLocalName())) {

            // Can only have one time-range or text-match
            if (textMatchFilter!=null) {
                throw new ParseException("CALDAV:prop-filter only one time-range or text-match element permitted", -1);
            }
  
            textMatchFilter = new TextMatchFilter(child);

        } else if (ELEMENT_CALDAV_PARAM_FILTER.
                   equals(child.getLocalName())) {

            // Add to list
            paramFilters.add(new ParamFilter(child));
        } else if(ELEMENT_CALDAV_IS_NOT_DEFINED.equals(child.getLocalName())) {
            if(childCount>1) {
                throw new ParseException("CALDAV:is-not-defined cannnot be present with other "
                        + "child elements",-1);
            }
            isNotDefinedFilter = new IsNotDefinedFilter();
        } else {
            throw new ParseException("CALDAV:prop-filter an invalid element name found", -1);
        }
    }
}
 
Example 7
Source File: CaldavOutputFilter.java    From cosmo with Apache License 2.0 4 votes vote down vote up
/**
 * Returns an <code>OutputFilter</code> representing the given
 * <code>&lt;C:calendar-data/&gt;> element.
 * @param cdata the given calendar data.
 * @return output filter.
 * @throws CosmoDavException - if something is wrong this exception is thrown.
 */
public static OutputFilter createFromXml(Element cdata)
    throws CosmoDavException {
    OutputFilter result = null;
    Period expand = null;
    Period limit = null;
    Period limitfb = null;

    String contentType =
        DomUtil.getAttribute(cdata, ATTR_CALDAV_CONTENT_TYPE,
                             NAMESPACE_CALDAV);
    if (contentType != null && ! contentType.equals(ICALENDAR_MEDIA_TYPE)) {
        throw new UnsupportedCalendarDataException(contentType);
    }
    String version =
        DomUtil.getAttribute(cdata, ATTR_CALDAV_CONTENT_TYPE,
                             NAMESPACE_CALDAV);
    if (version != null && ! version.equals(ICALENDAR_VERSION)) {
            throw new UnsupportedCalendarDataException();
    }

    // Look at each child element of calendar-data
    for (ElementIterator iter = DomUtil.getChildren(cdata);
         iter.hasNext();) {

        Element child = iter.nextElement();
        if (ELEMENT_CALDAV_COMP.equals(child.getLocalName())) {

            // At the top-level of calendar-data there should only be one
            // <comp> element as VCALENDAR components are the only top-level
            // components allowed in iCalendar data
            if (result != null) {
                return null;
            }

            // Get required name attribute and verify it is VCALENDAR
            String name = 
                DomUtil.getAttribute(child, ATTR_CALDAV_NAME, null);
            if (name == null || !Calendar.VCALENDAR.equals(name)) {
                return null;
            }

            // Now parse filter item
            result = parseCalendarDataComp(child);

        } else if (ELEMENT_CALDAV_EXPAND.equals(child.getLocalName())) {
            expand = parsePeriod(child, true);
        } else if (ELEMENT_CALDAV_LIMIT_RECURRENCE_SET.
                   equals(child.getLocalName())) {
            limit = parsePeriod(child, true);
        } else if (ELEMENT_CALDAV_LIMIT_FREEBUSY_SET.
                   equals(child.getLocalName())) {
            limitfb = parsePeriod(child, true);
        } else {
            LOG.warn("Ignoring child {} of {}", child.getTagName(), cdata.getTagName());
        }
    }

    // Now add any limit/expand options, creating a filter if one is not
    // already present
    if (result == null
            && (expand != null || limit != null || limitfb != null)) {
        result = new OutputFilter("VCALENDAR");
        result.setAllSubComponents();
        result.setAllProperties();
    }
    if (expand != null) {
        result.setExpand(expand);
    }
    if (limit != null) {
        result.setLimit(limit);
    }
    if (limitfb != null) {
        result.setLimitfb(limitfb);
    }

    return result;
}
 
Example 8
Source File: CaldavOutputFilter.java    From cosmo with Apache License 2.0 4 votes vote down vote up
private static OutputFilter parseCalendarDataComp(Element comp) {
    // Get required name attribute
    String name =
        DomUtil.getAttribute(comp, ATTR_CALDAV_NAME, null);
    if (name == null) {
        return null;
    }

    // Now create filter item
    OutputFilter result = new OutputFilter(name);

    // Look at each child element
    ElementIterator i = DomUtil.getChildren(comp);
    while (i.hasNext()) {
        Element child = i.nextElement();
        if (ELEMENT_CALDAV_ALLCOMP.equals(child.getLocalName())) {
            // Validity check
            if (result.hasSubComponentFilters()) {
                result = null;
                return null;
            }
            result.setAllSubComponents();

        } else if (ELEMENT_CALDAV_ALLPROP.equals(child.getLocalName())) {
            // Validity check
            if (result.hasPropertyFilters()) {
                result = null;
                return null;
            }
            result.setAllProperties();

        } else if (ELEMENT_CALDAV_COMP.equals(child.getLocalName())) {
            // Validity check
            if (result.isAllSubComponents()) {
                result = null;
                return null;
            }
            OutputFilter subfilter = parseCalendarDataComp(child);
            if (subfilter == null) {
                result = null;
                return null;
            } else {
                result.addSubComponent(subfilter);
            }
        } else if (ELEMENT_CALDAV_PROP.equals(child.getLocalName())) {
            // Validity check
            if (result.isAllProperties()) {
                result = null;
                return null;
            }

            // Get required name attribute
            String propname =
                DomUtil.getAttribute(child, ATTR_CALDAV_NAME, null);
            if (propname == null) {
                result = null;
                return null;
            }

            // Get optional novalue attribute
            boolean novalue = false;
            String novaluetxt =
                DomUtil.getAttribute(child, ATTR_CALDAV_NOVALUE, null);
            if (novaluetxt != null) {
                if (VALUE_YES.equals(novaluetxt)) {
                    novalue = true;
                }
                else if (VALUE_NO.equals(novaluetxt)) {
                    novalue = false;
                }
                else {
                    result = null;
                    return null;
                }
            }

            // Now add property item
            result.addProperty(propname, novalue);
        }
    }

    return result;
}