List of usage examples for com.liferay.portal.kernel.xml Element attribute
public Attribute attribute(String name);
From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java
License:Open Source License
@Override public Object getZipEntryAsObject(Element element, String path) { Object object = fromXML(getZipEntryAsString(path)); Attribute classNameAttribute = element.attribute("attached-class-name"); if ((object != null) && (classNameAttribute != null)) { String className = classNameAttribute.getText(); BeanPropertiesUtil.setProperty(object, "className", className); BeanPropertiesUtil.setProperty(object, "classNameId", PortalUtil.getClassNameId(className)); }/* w ww . j av a 2s.co m*/ return object; }
From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java
License:Open Source License
@Override public boolean isMissingReference(Element referenceElement) { Attribute missingAttribute = referenceElement.attribute("missing"); if ((missingAttribute != null) && !GetterUtil.getBoolean(referenceElement.attributeValue("missing"))) { return false; }//from w w w .j av a 2 s. c om if (_missingReferences.isEmpty()) { List<Element> missingReferenceElements = _missingReferencesElement.elements(); for (Element missingReferenceElement : missingReferenceElements) { if (Validator.isNotNull(missingReferenceElement.attributeValue("element-path"))) { continue; } String missingReferenceClassName = missingReferenceElement.attributeValue("class-name"); String missingReferenceClassPK = missingReferenceElement.attributeValue("class-pk"); String missingReferenceKey = getReferenceKey(missingReferenceClassName, missingReferenceClassPK); _missingReferences.add(missingReferenceKey); } } String className = referenceElement.attributeValue("class-name"); String classPK = referenceElement.attributeValue("class-pk"); String referenceKey = getReferenceKey(className, classPK); return _missingReferences.contains(referenceKey); }
From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java
License:Open Source License
protected ServiceContext createServiceContext(Element element, String path, ClassedModel classedModel, Class<?> clazz) {/*w w w . j ava 2 s .c om*/ ServiceContext serviceContext = new ServiceContext(); // Theme display serviceContext.setCompanyId(getCompanyId()); serviceContext.setScopeGroupId(getScopeGroupId()); // Dates if (classedModel instanceof AuditedModel) { AuditedModel auditedModel = (AuditedModel) classedModel; serviceContext.setUserId(getUserId(auditedModel)); serviceContext.setCreateDate(auditedModel.getCreateDate()); serviceContext.setModifiedDate(auditedModel.getModifiedDate()); } // Permissions if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) { serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); } // Asset if (isResourceMain(classedModel)) { Serializable classPKObj = ExportImportClassedModelUtil.getPrimaryKeyObj(classedModel); long[] assetCategoryIds = getAssetCategoryIds(clazz, classPKObj); serviceContext.setAssetCategoryIds(assetCategoryIds); String[] assetTagNames = getAssetTagNames(clazz, classPKObj); serviceContext.setAssetTagNames(assetTagNames); } if (element != null) { Attribute assetPriorityAttribute = element.attribute("asset-entry-priority"); if (assetPriorityAttribute != null) { double assetPriority = GetterUtil.getDouble(assetPriorityAttribute.getValue()); serviceContext.setAssetPriority(assetPriority); } } // Expando String expandoPath = null; if (element != null) { expandoPath = element.attributeValue("expando-path"); } else { expandoPath = ExportImportPathUtil.getExpandoPath(path); } if (Validator.isNotNull(expandoPath)) { try { Map<String, Serializable> expandoBridgeAttributes = (Map<String, Serializable>) getZipEntryAsObject( expandoPath); if (expandoBridgeAttributes != null) { serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes); } } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } } } // Workflow if (classedModel instanceof WorkflowedModel) { WorkflowedModel workflowedModel = (WorkflowedModel) classedModel; if (workflowedModel.getStatus() == WorkflowConstants.STATUS_APPROVED) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); } else if (workflowedModel.getStatus() == WorkflowConstants.STATUS_DRAFT) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); } } return serviceContext; }
From source file:com.liferay.exportimport.lar.ThemeImporter.java
License:Open Source License
public void importTheme(PortletDataContext portletDataContext, LayoutSet layoutSet) throws Exception { boolean importThemeSettings = MapUtil.getBoolean(portletDataContext.getParameterMap(), PortletDataHandlerKeys.THEME_REFERENCE); if (_log.isDebugEnabled()) { _log.debug("Import theme settings " + importThemeSettings); }/*from w ww . j a va 2 s .com*/ if (!importThemeSettings) { return; } Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); long importGroupId = groupIds.get(layoutSet.getGroupId()); Element importDataRootElement = portletDataContext.getImportDataRootElement(); Element headerElement = importDataRootElement.element("header"); String themeId = layoutSet.getThemeId(); String colorSchemeId = layoutSet.getColorSchemeId(); Attribute themeIdAttribute = headerElement.attribute("theme-id"); if (themeIdAttribute != null) { themeId = themeIdAttribute.getValue(); } Attribute colorSchemeIdAttribute = headerElement.attribute("color-scheme-id"); if (colorSchemeIdAttribute != null) { colorSchemeId = colorSchemeIdAttribute.getValue(); } String css = GetterUtil.getString(headerElement.elementText("css")); LayoutSetLocalServiceUtil.updateLookAndFeel(importGroupId, layoutSet.isPrivateLayout(), themeId, colorSchemeId, css); }
From source file:com.liferay.exportimport.resources.importer.internal.util.FileSystemImporter.java
License:Open Source License
protected boolean isJournalStructureXSD(String xsd) throws Exception { Document document = saxReader.read(xsd); Element rootElement = document.getRootElement(); Attribute availableLocalesAttribute = rootElement.attribute("available-locales"); if (availableLocalesAttribute == null) { return true; }/* w ww . ja v a 2 s. com*/ return false; }
From source file:com.liferay.exportimport.test.PortletDataContextReferencesTest.java
License:Open Source License
@Test public void testCleanUpMissingReferences() throws Exception { _portletDataContext.setPortletId(JournalContentPortletKeys.JOURNAL_CONTENT); Portlet portlet = PortletLocalServiceUtil.getPortletById(JournalContentPortletKeys.JOURNAL_CONTENT); AssetVocabulary assetVocabulary = AssetTestUtil.addVocabulary(_group.getGroupId()); AssetCategory assetCategory = AssetTestUtil.addCategory(_group.getGroupId(), assetVocabulary.getVocabularyId()); _portletDataContext.addReferenceElement(portlet, _portletDataContext.getExportDataRootElement(), assetCategory, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); Element missingReferencesElement = _portletDataContext.getMissingReferencesElement(); List<Element> missingReferenceElements = missingReferencesElement.elements(); Assert.assertFalse(missingReferenceElements.toString(), missingReferenceElements.isEmpty()); Assert.assertEquals(missingReferenceElements.toString(), 1, missingReferenceElements.size()); StagedModelDataHandlerUtil.exportStagedModel(_portletDataContext, assetCategory); missingReferenceElements = missingReferencesElement.elements(); Assert.assertFalse(missingReferenceElements.toString(), missingReferenceElements.isEmpty()); Assert.assertEquals(missingReferenceElements.toString(), 1, missingReferenceElements.size()); Element missingReferenceElement = missingReferenceElements.get(0); Assert.assertNull(missingReferenceElement.attribute("missing")); Assert.assertFalse(Validator.isBlank(missingReferenceElement.attributeValue("element-path"))); }
From source file:com.liferay.exportimport.test.PortletDataContextReferencesTest.java
License:Open Source License
@Test public void testMissingNotMissingReference() throws Exception { _portletDataContext.setPortletId(BookmarksPortletKeys.BOOKMARKS); Element bookmarksEntryElement = _portletDataContext.getExportDataElement(_bookmarksEntry); _portletDataContext.addReferenceElement(_bookmarksEntry, bookmarksEntryElement, _bookmarksFolder, PortletDataContext.REFERENCE_TYPE_PARENT, true); _portletDataContext.addReferenceElement(_bookmarksEntry, bookmarksEntryElement, _bookmarksFolder, PortletDataContext.REFERENCE_TYPE_PARENT, false); Element missingReferencesElement = _portletDataContext.getMissingReferencesElement(); List<Element> missingReferenceElements = missingReferencesElement.elements(); Assert.assertFalse(missingReferenceElements.toString(), missingReferenceElements.isEmpty()); Assert.assertEquals(missingReferenceElements.toString(), 1, missingReferenceElements.size()); Element missingReferenceElement = missingReferenceElements.get(0); Assert.assertNull(missingReferenceElement.attribute("missing")); Assert.assertFalse(Validator.isBlank(missingReferenceElement.attributeValue("element-path"))); }
From source file:com.liferay.exportimport.test.PortletDataContextReferencesTest.java
License:Open Source License
@Test public void testMultipleMissingNotMissingReference() throws Exception { _portletDataContext.setPortletId(BookmarksPortletKeys.BOOKMARKS); Element bookmarksEntryElement1 = _portletDataContext.getExportDataElement(_bookmarksEntry); _portletDataContext.addReferenceElement(_bookmarksEntry, bookmarksEntryElement1, _bookmarksFolder, PortletDataContext.REFERENCE_TYPE_PARENT, true); _portletDataContext.addReferenceElement(_bookmarksEntry, bookmarksEntryElement1, _bookmarksFolder, PortletDataContext.REFERENCE_TYPE_PARENT, false); BookmarksEntry bookmarksEntry = BookmarksTestUtil.addEntry(_bookmarksFolder.getFolderId(), true, _serviceContext);//from w ww .j av a2 s.c o m Element bookmarksEntryElement2 = _portletDataContext.getExportDataElement(bookmarksEntry); _portletDataContext.addReferenceElement(bookmarksEntry, bookmarksEntryElement2, _bookmarksFolder, PortletDataContext.REFERENCE_TYPE_PARENT, true); Element missingReferencesElement = _portletDataContext.getMissingReferencesElement(); List<Element> missingReferenceElements = missingReferencesElement.elements(); Assert.assertFalse(missingReferenceElements.toString(), missingReferenceElements.isEmpty()); Assert.assertEquals(missingReferenceElements.toString(), 1, missingReferenceElements.size()); Element missingReferenceElement = missingReferenceElements.get(0); Assert.assertNull(missingReferenceElement.attribute("missing")); Assert.assertFalse(Validator.isBlank(missingReferenceElement.attributeValue("element-path"))); }
From source file:com.liferay.faces.portal.component.inputsearch.internal.InputSearchRenderer.java
License:Open Source License
@Override protected StringBuilder getMarkup(UIComponent uiComponent, StringBuilder markup) throws Exception { //J-//from w w w. j a v a 2s . c o m // NOTE: The specified markup looks like the following (HTML comments added for clarity): // // <!-- Opening <div> rendered by html/taglib/ui/input_search/page.jsp --> // <div class="input-append"> // // <!-- Input text field rendered by html/taglib/ui/input_search/page.jsp --> // <input class="search-query span9" id="...:jid42" name="..." placeholder="" type="text" value="" /> // // <!-- Search button rendered by html/taglib/ui/input_search/page.jsp --> // <button class="btn" type="submit">Search</button> // // <!-- HtmlInputText (dynamically added JSF child component) --> // <input type="text" name="...:htmlInputText" /> // // <!-- HtmlCommandButton (dynamically added JSF child component) --> // <input type="submit" name="...:htmlCommandButton" value="" /> // // <!-- Closing </div> rendered by html/taglib/ui/input_search/page.jsp --> // </div> //J+ // Parse the generated markup as an XML document. InputSearch inputSearch = cast(uiComponent); Document document = SAXReaderUtil.read(markup.toString()); Element rootElement = document.getRootElement(); // Locate the first/main input element in the XML document. This is the one that will contain contain the value // that will be submitted in the postback and received by the decode(FacesContext, UIComponent) method). String xpathInput = "//input[contains(@id, '" + uiComponent.getClientId() + "')]"; Element mainInputElement = (Element) rootElement.selectSingleNode(xpathInput); if (mainInputElement != null) { // Copy the value attribute of the InputSearch component to the first input element in the XML document. mainInputElement.attribute("value").setValue((String) inputSearch.getValue()); // Locate the dynamically added HtmlInputText and HtmlCommandButton child components. String xpathInputs = "//input[@type='text']"; List<Node> inputElements = rootElement.selectNodes(xpathInputs); if ((inputElements != null) && (inputElements.size() == 2)) { // Copy each "on" attribute name/value pairs from the HtmlInputText to the first input element in // the XML document. This will enable all of the AjaxBehavior events like keyup/keydown to work. Element htmlInputTextElement = (Element) inputElements.get(1); Iterator<Attribute> attributeIterator = htmlInputTextElement.attributeIterator(); while (attributeIterator.hasNext()) { Attribute attribute = attributeIterator.next(); String attributeName = attribute.getName(); if (attributeName.startsWith("on")) { mainInputElement.addAttribute(attributeName, attribute.getValue()); } } // Remove the HtmlInputText <input> from the XML document so that only one text field is rendered. htmlInputTextElement.getParent().remove(htmlInputTextElement); } } // Locate the HtmlCommandButton in the XML document. List<UIComponent> children = uiComponent.getChildren(); HtmlCommandButton htmlCommandButton = (HtmlCommandButton) children.get(1); String htmlCommandButtonClientId = htmlCommandButton.getClientId(); // Note that if there is an AjaxBehavior, then the rendered HtmlCommandButton can be located in the XML document // via the name attribute. Otherwise it can be located in the XML document via the id attribute. String htmlCommandButtonXPath = "//input[contains(@name,'" + htmlCommandButtonClientId + "') and @type='submit']"; Element htmlCommandButtonElement = (Element) rootElement.selectSingleNode(htmlCommandButtonXPath); if (htmlCommandButtonElement == null) { htmlCommandButtonXPath = "//input[contains(@id,'" + htmlCommandButtonClientId + "') and @type='submit']"; htmlCommandButtonElement = (Element) rootElement.selectSingleNode(htmlCommandButtonXPath); } if (htmlCommandButtonElement != null) { // Locate the <button> element in the XML document that was rendered by page.jsp Element buttonElement = (Element) rootElement.selectSingleNode("//button[@type='submit']"); if (buttonElement != null) { // Copy attributes found on the HtmlCommandButton <input> element to the <button> element that was // rendered by page.jsp Attribute onClickAttr = htmlCommandButtonElement.attribute("onclick"); if (onClickAttr != null) { buttonElement.addAttribute("onclick", onClickAttr.getValue()); } Attribute nameAttr = htmlCommandButtonElement.attribute("name"); if (nameAttr != null) { buttonElement.addAttribute("name", nameAttr.getValue()); } Attribute idAttr = htmlCommandButtonElement.attribute("id"); if (idAttr != null) { buttonElement.addAttribute("id", idAttr.getValue()); } // Remove the HtmlCommandButton <input> from the XML document so that only one button is rendered. htmlCommandButtonElement.getParent().remove(htmlCommandButtonElement); } } // Returned the modified verson of the specified markup. return new StringBuilder(rootElement.asXML()); }
From source file:com.liferay.faces.test.hooks.TestSetupAction.java
License:Open Source License
protected void setupBridgeTCKSite(long companyId, long userId) throws Exception, DocumentException { Group site = getSiteForSetup(companyId, userId, "Bridge TCK"); long groupId = site.getGroupId(); addAllUsersToSite(companyId, groupId); URL configFileURL = getClass().getClassLoader().getResource("pluto-portal-driver-config.xml"); Document document = SAXReaderUtil.read(configFileURL); Element rootElement = document.getRootElement(); Element renderConfigElement = rootElement.element("render-config"); Iterator<Element> pageElementIterator = renderConfigElement.elementIterator("page"); while (pageElementIterator.hasNext()) { Element pageElement = pageElementIterator.next(); Attribute nameAttribute = pageElement.attribute("name"); String pageName = nameAttribute.getValue(); Element portletElement = pageElement.element("portlet"); nameAttribute = portletElement.attribute("name"); String portletName = nameAttribute.getValue(); String liferayPortletName = portletName.replaceAll("-", ""); String liferayPortletId = liferayPortletName + "_WAR_bridgetckmainportlet"; PortalPage portalPage = new PortalPage(pageName, liferayPortletId); setupPrivatePage(companyId, userId, groupId, portalPage); }//from ww w. ja v a 2 s .c o m setupPrivatePage(companyId, userId, groupId, new PortalPage("Lifecycle Set", "chapter3TestslifecycleTestportlet_WAR_bridgetcklifecyclesetportlet")); setupPrivatePage(companyId, userId, groupId, new PortalPage("Render Policy Always Delegate", "chapter3TestsrenderPolicyTestportlet_WAR_bridgetckrenderpolicy1portlet")); setupPrivatePage(companyId, userId, groupId, new PortalPage("Render Policy Default", "chapter3TestsrenderPolicyTestportlet_WAR_bridgetckrenderpolicy2portlet")); setupPrivatePage(companyId, userId, groupId, new PortalPage("Render Policy Never Delegate", "chapter3TestsrenderPolicyTestportlet_WAR_bridgetckrenderpolicy3portlet")); setupPrivatePage(companyId, userId, groupId, new PortalPage("Render Response Wrapper", "chapter6_2_1TestsusesConfiguredRenderResponseWrapperTestportlet_WAR_bridgetckresponsewrapperportlet")); setupPrivatePage(companyId, userId, groupId, new PortalPage("Resource Response Wrapper", "chapter6_2_1TestsusesConfiguredResourceResponseWrapperTestportlet_WAR_bridgetckresponsewrapperportlet")); }