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

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

Introduction

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

Prototype

public String attributeValue(String name);

Source Link

Usage

From source file:com.liferay.wsrp.admin.lar.AdminPortletDataHandlerImpl.java

License:Open Source License

protected void importWSRPProducers(PortletDataContext portletDataContext, Element wsrpProducersElement)
        throws Exception {

    if (wsrpProducersElement == null) {
        return;//from w  w  w.  j ava2  s  .  c o  m
    }

    for (Element wsrpProducerElement : wsrpProducersElement.elements("wsrp-producer")) {

        String path = wsrpProducerElement.attributeValue("path");

        if (!portletDataContext.isPathNotProcessed(path)) {
            continue;
        }

        WSRPProducer wsrpProducer = (WSRPProducer) portletDataContext.getZipEntryAsObject(path);

        importWSRPProducer(portletDataContext, wsrpProducerElement, wsrpProducer);
    }
}

From source file:com.liferay.wsrp.util.WSRPConsumerManager.java

License:Open Source License

private boolean _isV2(List<Element> serviceElements) {
    for (Element serviceElement : serviceElements) {
        List<Element> bindingElements = serviceElement.elements(_getWsdlQName("port"));

        Element firstBindingElement = bindingElements.get(0);

        String binding = firstBindingElement.attributeValue("binding");

        if (binding.contains("v2")) {
            return true;
        }/* w w w  .  j  av a  2s.co m*/
    }

    return false;
}

From source file:com.liferay.wsrp.util.WSRPConsumerManager.java

License:Open Source License

private void _readBindingElement(Element bindingElement) throws Exception {
    String binding = bindingElement.attributeValue("binding");

    int pos = binding.indexOf(StringPool.COLON);

    binding = binding.substring(pos + 1);

    Element addressElement = bindingElement.element("address");

    String bindingLocation = addressElement.attributeValue("location");

    URL bindingLocationURL = new URL(bindingLocation);

    if (binding.equals(_WSRP_V1_MARKUP_BINDING) || binding.equals(_WSRP_V2_MARKUP_BINDING)) {

        _markupServiceURL = bindingLocationURL;
    } else if (binding.equals(_WSRP_V1_PORTLET_MANAGEMENT_BINDING)
            || binding.equals(_WSRP_V2_PORTLET_MANAGEMENT_BINDING)) {

        _portletManagementService = _service.getWSRP_v2_PortletManagement_Service(bindingLocationURL);
    } else if (binding.equals(_WSRP_V1_REGISTRATION_BINDING) || binding.equals(_WSRP_V2_REGISTRATION_BINDING)) {

        _registrationService = _service.getWSRP_v2_Registration_Service(bindingLocationURL);
    } else if (binding.equals(_WSRP_V1_SERVICE_DESCRIPTION_BINDING)
            || binding.equals(_WSRP_V2_SERVICE_DESCRIPTION_BINDING)) {

        _serviceDescriptionService = _service.getWSRP_v2_ServiceDescription_Service(bindingLocationURL);
    }//w w w . ja  v a 2 s . c  om
}

From source file:com.liferay.wsrp.util.WSRPConsumerManager.java

License:Open Source License

private void _readServiceElements(List<Element> serviceElements) throws Exception {

    for (Element serviceElement : serviceElements) {
        List<Element> bindingElements = serviceElement.elements(_getWsdlQName("port"));

        for (Element bindingElement : bindingElements) {
            _readBindingElement(bindingElement);
        }//w  ww.  j  a v  a2 s.co m

        Element firstBindingElement = bindingElements.get(0);

        String binding = firstBindingElement.attributeValue("binding");

        if (binding.contains("v2")) {
            break;
        }
    }
}

From source file:com.playtech.portal.platform.portlet.orgsettings.lar.OrgSettingsDataHandler.java

/**
 * Parses single string with data into xml document and saves settings from it.
 * Internal method, access 'protected' only for licensees
 *
 * @param companyId whose settings are changed
 * @param groupId   is id of organization
 * @param data      single string with data to import
 * @throws DocumentException//from www .  j  av a 2 s.  co m
 */
protected void invokeImportData(PortletDataContext context, final long companyId, final long groupId,
        final String data) throws DocumentException {

    Document doc = SAXReaderUtil.read(data);

    Element expandoRoot = doc.getRootElement();

    Map<String, String> properties = new HashMap();
    Map<String, String> articleIds = (Map<String, String>) context
            .getNewPrimaryKeysMap(JournalArticle.class + ".articleId");

    for (Iterator<Element> iterator = expandoRoot.elementIterator(ELEM_EXPANDO); iterator.hasNext();) {
        Element expandoEl = iterator.next();
        Element nameEl = expandoEl.element(ELEM_NAME);
        String propertyName = nameEl.getText();
        String type = nameEl.attributeValue(ATTR_TYPE);
        Element valueEl = expandoEl.element(ELEM_VALUE);
        try {
            String primVal = addPrimitiveWrapper(articleIds, type, valueEl);
            if (log.isDebugEnabled()) {
                log.debug("Import {} = {} ", propertyName, primVal);
            }
            properties.put(propertyName, primVal);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }

    getPropertiesService().setAllPartitionPropertiesMap(companyId, PartitionNames.GROUP, groupId, properties);
    doLookupServiceImport(doc, context, companyId, groupId, data);
}

From source file:com.playtech.portal.platform.portlet.orgsettings.lar.OrgSettingsDataHandler.java

protected void doLookupServiceImport(Document doc, PortletDataContext context, final long companyId,
        final long groupId, final String data) {
    getLookupServiceConfigurator().deleteLookupServiceConfiguration(companyId, groupId);
    getProviderConfigurationService().deleteProviderConfigurations(companyId, groupId);

    Element root = doc.getRootElement();

    Element lookupServiceNode = root.element(NAMESPACE_LOOKUP_SERVICE);
    if (lookupServiceNode != null) {
        LookupServiceConfiguration lookupServiceConfiguration = getLookupServiceConfigurationFactory()
                .createLookupServiceConfiguration();
        lookupServiceConfiguration.getId().setCompanyId(companyId);
        lookupServiceConfiguration.getId().setGroupId(groupId);
        lookupServiceConfiguration//from w ww.  j av  a  2 s .c  o  m
                .setCurrentProviderId(lookupServiceNode.attributeValue(LOOKUP_CUR_PROVIDER_ID));
        lookupServiceConfiguration
                .setEnabled(BooleanUtil.parse(lookupServiceNode.attributeValue(LOOKUP_ENABLED)));
        getLookupServiceConfigurator().saveOrUpdate(lookupServiceConfiguration);

        Iterator<Element> providersIterator = lookupServiceNode.elementIterator(NAMESPACE_LOOKUP_PROVIDER);
        Collection<ProviderConfiguration> providerConfigurations = new HashSet<ProviderConfiguration>();
        while (providersIterator.hasNext()) {
            Element providerNode = providersIterator.next();
            if (providerNode != null) {
                ProviderConfiguration providerConfiguration = getProviderConfigurationFactory()
                        .createProviderConfiguration();
                providerConfiguration.getId().setCompanyId(companyId);
                providerConfiguration.getId().setGroupId(groupId);
                providerConfiguration.getId().setProviderId(providerNode.attributeValue(PROVIDER_ID));
                providerConfiguration.setJson(providerNode.element(PROVIDER_JSON).getText());

                providerConfigurations.add(providerConfiguration);
            }
        }
        if (!providerConfigurations.isEmpty()) {
            getProviderConfigurationService().saveOrUpdateAll(providerConfigurations);
        }
    }

}

From source file:org.liferay.demo.conference.lar.SpeakerStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Speaker speaker) throws Exception {

    ServiceContext serviceContext = portletDataContext.createServiceContext(speaker);

    Speaker importedSpeaker = null;//  w w  w  .  j  a v  a 2  s .  c  om

    if (portletDataContext.isDataStrategyMirror()) {
        Speaker existingSpeaker = SpeakerLocalServiceUtil.fetchSpeakerByUuidAndGroupId(speaker.getUuid(),
                portletDataContext.getScopeGroupId());

        if (existingSpeaker == null) {
            serviceContext.setUuid(speaker.getUuid());

            importedSpeaker = SpeakerLocalServiceUtil.addSpeaker(speaker.getName(), speaker.getBio(), null,
                    serviceContext);
        } else {
            importedSpeaker = SpeakerLocalServiceUtil.updateSpeaker(existingSpeaker.getSpeakerId(),
                    speaker.getName(), speaker.getBio(), null, serviceContext);
        }
    } else {
        importedSpeaker = SpeakerLocalServiceUtil.addSpeaker(speaker.getName(), speaker.getBio(), null,
                serviceContext);
    }

    Element speakerElement = portletDataContext.getImportDataStagedModelElement(speaker);

    List<Element> attachmentElements = portletDataContext.getReferenceDataElements(speakerElement,
            FileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);

    for (Element attachmentElement : attachmentElements) {

        String fileEntryUUID = attachmentElement.attributeValue("uuid");
        Element fileEntryElement = portletDataContext.getImportDataElement("FileEntry", "uuid", fileEntryUUID);
        String binPath = fileEntryElement.attributeValue("bin-path");
        InputStream image = portletDataContext.getZipEntryAsInputStream(binPath);

        importedSpeaker = SpeakerLocalServiceUtil.updateSpeaker(importedSpeaker.getSpeakerId(),
                importedSpeaker.getName(), importedSpeaker.getBio(), image, serviceContext);
    }

    portletDataContext.importClassedModel(speaker, importedSpeaker);
}

From source file:org.liferay.jukebox.lar.AlbumStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Album album) throws Exception {

    long userId = portletDataContext.getUserId(album.getUserUuid());

    ServiceContext serviceContext = portletDataContext.createServiceContext(album);

    String artistPath = ExportImportPathUtil.getModelPath(portletDataContext, Artist.class.getName(),
            album.getArtistId());//  w  w  w  .  j ava 2 s  .com

    Artist artist = (Artist) portletDataContext.getZipEntryAsObject(artistPath);

    if (artist != null) {
        StagedModelDataHandlerUtil.importReferenceStagedModel(portletDataContext, album, Artist.class,
                album.getArtistId());
    }

    Map<Long, Long> artistIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Artist.class);

    long artistId = MapUtil.getLong(artistIds, album.getArtistId(), album.getArtistId());

    Album importedAlbum = null;

    if (portletDataContext.isDataStrategyMirror()) {
        Album existingAlbum = AlbumLocalServiceUtil.fetchAlbumByUuidAndGroupId(album.getUuid(),
                portletDataContext.getScopeGroupId());

        if (existingAlbum == null) {
            serviceContext.setUuid(album.getUuid());

            importedAlbum = AlbumLocalServiceUtil.addAlbum(userId, artistId, album.getName(), album.getYear(),
                    null, serviceContext);
        } else {
            importedAlbum = AlbumLocalServiceUtil.updateAlbum(userId, existingAlbum.getAlbumId(), artistId,
                    album.getName(), album.getYear(), null, serviceContext);
        }
    } else {
        importedAlbum = AlbumLocalServiceUtil.addAlbum(userId, artistId, album.getName(), album.getYear(), null,
                serviceContext);
    }

    Element albumElement = portletDataContext.getImportDataStagedModelElement(album);

    List<Element> attachmentElements = portletDataContext.getReferenceDataElements(albumElement,
            FileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);

    for (Element attachmentElement : attachmentElements) {
        String path = attachmentElement.attributeValue("path");

        FileEntry fileEntry = (FileEntry) portletDataContext.getZipEntryAsObject(path);

        importedAlbum = AlbumLocalServiceUtil.updateAlbum(userId, importedAlbum.getAlbumId(),
                importedAlbum.getArtistId(), importedAlbum.getName(), importedAlbum.getYear(),
                fileEntry.getContentStream(), serviceContext);
    }

    portletDataContext.importClassedModel(album, importedAlbum);
}

From source file:org.liferay.jukebox.lar.ArtistStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Artist artist) throws Exception {

    long userId = portletDataContext.getUserId(artist.getUserUuid());

    ServiceContext serviceContext = portletDataContext.createServiceContext(artist);

    Artist importedArtist = null;//  w ww  . j  av a2s .c  om

    if (portletDataContext.isDataStrategyMirror()) {
        Artist existingArtist = ArtistLocalServiceUtil.fetchArtistByUuidAndGroupId(artist.getUuid(),
                portletDataContext.getScopeGroupId());

        if (existingArtist == null) {
            serviceContext.setUuid(artist.getUuid());

            importedArtist = ArtistLocalServiceUtil.addArtist(userId, artist.getName(), artist.getBio(), null,
                    serviceContext);
        } else {
            importedArtist = ArtistLocalServiceUtil.updateArtist(userId, existingArtist.getArtistId(),
                    artist.getName(), artist.getBio(), null, serviceContext);
        }
    } else {
        importedArtist = ArtistLocalServiceUtil.addArtist(userId, artist.getName(), artist.getBio(), null,
                serviceContext);
    }

    Element artistElement = portletDataContext.getImportDataStagedModelElement(artist);

    List<Element> attachmentElements = portletDataContext.getReferenceDataElements(artistElement,
            FileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);

    for (Element attachmentElement : attachmentElements) {
        String path = attachmentElement.attributeValue("path");

        FileEntry fileEntry = (FileEntry) portletDataContext.getZipEntryAsObject(path);

        importedArtist = ArtistLocalServiceUtil.updateArtist(userId, importedArtist.getArtistId(),
                importedArtist.getName(), importedArtist.getBio(), fileEntry.getContentStream(),
                serviceContext);
    }

    portletDataContext.importClassedModel(artist, importedArtist);
}

From source file:se.gothiaforum.util.DynamicArticleHandler.java

License:Open Source License

private List<DynamicElement> generateDynamicElement(List<Element> elements) {

    List<DynamicElement> dynamicElementList = new ArrayList<DynamicElement>();

    for (Element e : elements) {
        List<Element> childElements = e.elements(ActorsConstants.ARTICLE_XML_DYNAMIC_ELEMENT);
        String content = e.elementText(ActorsConstants.ARTICLE_XML_DYNAMIC_CONTENT);
        String name = e.attributeValue("name");

        DynamicElement dynamicElement;//from   ww w .ja v a2  s.  c o m

        if (childElements.size() > 0) {
            dynamicElement = new DynamicElement(name, content, generateDynamicElement(childElements));
        } else {
            dynamicElement = new DynamicElement(name, content, new ArrayList<DynamicElement>());
        }

        dynamicElementList.add(dynamicElement);
    }
    return dynamicElementList;
}