Example usage for com.liferay.portal.kernel.xml Element attribute

List of usage examples for com.liferay.portal.kernel.xml Element attribute

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.xml Element attribute.

Prototype

public Attribute attribute(String name);

Source Link

Usage

From source file:com.liferay.util.ant.Java2WsddTask.java

License:Open Source License

private static String _format(String content) throws Exception {
    content = HtmlUtil.stripComments(content);

    Document document = SAXReaderUtil.read(content);

    Element rootElement = document.getRootElement();

    Element serviceElement = rootElement.element("service");

    Map<String, Element> arrayMappingElements = new TreeMap<String, Element>();
    Map<String, Element> typeMappingElements = new TreeMap<String, Element>();
    Map<String, Element> operationElements = new TreeMap<String, Element>();
    Map<String, Element> parameterElements = new TreeMap<String, Element>();

    for (Element element : serviceElement.elements()) {
        String elementName = element.getName();

        if (elementName.equals("arrayMapping")) {
            element.detach();//from w  ww.j  a  v a  2 s.c o m

            arrayMappingElements.put(element.formattedString(), element);
        } else if (elementName.equals("operation")) {
            element.detach();

            StringBundler sb = new StringBundler();

            String name = element.attributeValue("name");

            sb.append(name);
            sb.append("_METHOD_");

            for (Element parameterElement : element.elements("parameter")) {
                String type = parameterElement.attributeValue("type");

                sb.append(type);
                sb.append("_PARAMETER_");
            }

            operationElements.put(sb.toString(), element);
        } else if (elementName.equals("parameter")) {
            element.detach();

            String name = element.attributeValue("name");

            if (name.equals("allowedMethods")) {
                Attribute valueAttribute = element.attribute("value");

                String[] values = StringUtil.split(valueAttribute.getValue(), CharPool.SPACE);

                Arrays.sort(values);

                valueAttribute.setValue(StringUtil.merge(values, StringPool.SPACE));
            } else if (name.equals("schemaUnqualified")) {
                Attribute valueAttribute = element.attribute("value");

                String[] values = StringUtil.split(valueAttribute.getValue());

                Arrays.sort(values);

                valueAttribute.setValue(StringUtil.merge(values));
            }

            parameterElements.put(name, element);
        } else if (elementName.equals("typeMapping")) {
            element.detach();

            typeMappingElements.put(element.formattedString(), element);
        }
    }

    _addElements(serviceElement, arrayMappingElements);
    _addElements(serviceElement, typeMappingElements);
    _addElements(serviceElement, operationElements);
    _addElements(serviceElement, parameterElements);

    content = StringUtil.replace(document.formattedString(), "\"/>", "\" />");

    return content;
}

From source file:com.liferay.weather.util.WeatherWebCacheItem.java

License:Open Source License

protected Weather doConvert() throws Exception {
    String xml = HttpUtil.URLtoString("http://api.openweathermap.org/data/2.5/weather?q="
            + HttpUtil.encodeURL(_zip) + "&units=imperial&mode=xml");

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

    Element cityElement = rootElement.element("city");

    Attribute cityIdAttribute = cityElement.attribute("id");

    String cityId = cityIdAttribute.getText();

    Element temperatureElement = rootElement.element("temperature");

    Attribute temperatureAttribute = temperatureElement.attribute("value");

    float temperature = GetterUtil.getFloat(temperatureAttribute.getData());

    Element weatherElement = rootElement.element("weather");

    Attribute iconAttribute = weatherElement.attribute("icon");

    String iconURL = "http://openweathermap.org/img/w/" + iconAttribute.getText() + ".png";

    return new Weather(_zip, cityId, iconURL, temperature);
}

From source file:com.liferay.wiki.importer.impl.mediawiki.MediaWikiImporter.java

License:Open Source License

protected List<String> readSpecialNamespaces(Element root) throws ImportFilesException {

    List<String> namespaces = new ArrayList<>();

    Element siteinfoElement = root.element("siteinfo");

    if (siteinfoElement == null) {
        throw new ImportFilesException("Invalid pages XML file");
    }// w  w  w .  j a  va2 s  .  co  m

    Element namespacesElement = siteinfoElement.element("namespaces");

    List<Element> namespaceElements = namespacesElement.elements("namespace");

    for (Element namespaceElement : namespaceElements) {
        Attribute attribute = namespaceElement.attribute("key");

        String value = attribute.getValue();

        if (!value.equals("0")) {
            namespaces.add(namespaceElement.getText());
        }
    }

    return namespaces;
}

From source file:it.smc.calendar.sync.caldav.methods.ReportMethodImpl.java

License:Open Source License

@Override
protected void addResponse(WebDAVStorage storage, WebDAVRequest webDAVRequest, Resource resource,
        Set<QName> props, Element multistatusElement, long depth) throws Exception {

    List<CalendarBooking> calendarBookings = null;

    List<Node> hrefNodes = CalDAVRequestThreadLocal.getRequestDocument()
            .selectNodes("//*[local-name()='href']");

    if ((hrefNodes.size() > 0) && CalDAVUtil.isCalendarBookingRequest(webDAVRequest)) {

        calendarBookings = new ArrayList<CalendarBooking>();

        CalendarBooking calendarBooking;

        for (Node hrefNode : hrefNodes) {
            calendarBooking = CalDAVUtil.getCalendarBookingFromURL(hrefNode.getText());

            if (calendarBooking != null) {
                calendarBookings.add(calendarBooking);
            }//from   www. jav a 2  s .c  om
        }
    } else {
        Calendar calendar = (Calendar) resource.getModel();

        Date startDate = null;
        Date endDate = null;

        Element timeRangeElement = CalDAVUtil.getReportDateFilter();

        if ((timeRangeElement != null) && (timeRangeElement.attribute("start") != null)) {

            String startDateStr = timeRangeElement.attribute("start").getValue();

            startDate = new net.fortuna.ical4j.model.Date(startDateStr);
        }

        if ((timeRangeElement != null) && (timeRangeElement.attribute("end") != null)) {

            String endDateStr = timeRangeElement.attribute("end").getValue();

            endDate = new net.fortuna.ical4j.model.Date(endDateStr);
        }

        calendarBookings = CalendarUtil.getCalendarBookings(webDAVRequest.getPermissionChecker(), calendar,
                startDate, endDate);
    }

    for (CalendarBooking calendarBooking : calendarBookings) {
        try {
            addCalendarBookingData(webDAVRequest, resource, calendarBooking, multistatusElement);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e);
            }
        }
    }
}