List of usage examples for com.liferay.portal.kernel.xml Element getStringValue
@Override
public String getStringValue();
From source file:com.liferay.adaptive.media.journal.web.internal.exportimport.content.processor.AMJournalArticleContentHTMLReplacer.java
License:Open Source License
public String replace(String content, Replace replace) throws Exception { try {/* w ww . ja v a 2s.c o m*/ Document document = SAXReaderUtil.read(content); XPath xPath = SAXReaderUtil.createXPath("//dynamic-element[@type='text_area']"); List<Node> ddmJournalArticleNodes = xPath.selectNodes(document); for (Node ddmJournalArticleNode : ddmJournalArticleNodes) { Element ddmJournalArticleElement = (Element) ddmJournalArticleNode; List<Element> dynamicContentElements = ddmJournalArticleElement.elements("dynamic-content"); for (Element dynamicContentElement : dynamicContentElements) { String replacedHtml = replace.apply(dynamicContentElement.getStringValue()); dynamicContentElement.clearContent(); dynamicContentElement.addCDATA(replacedHtml); } } return document.asXML(); } catch (DocumentException de) { if (_log.isDebugEnabled()) { _log.debug("Invalid content:\n" + content); } return content; } }
From source file:com.liferay.asset.publisher.web.upgrade.v1_0_0.UpgradePortletPreferences.java
License:Open Source License
protected void upgradeUuids(String[] assetEntryXmls) throws Exception { for (int i = 0; i < assetEntryXmls.length; i++) { String assetEntry = assetEntryXmls[i]; Document document = _saxReader.read(assetEntry); Element rootElement = document.getRootElement(); Element assetTypeElementUuid = rootElement.element("asset-entry-uuid"); if (assetTypeElementUuid == null) { continue; }/* w w w. j a v a2 s . c o m*/ String journalArticleResourceUuid = getJournalArticleResourceUuid( assetTypeElementUuid.getStringValue()); if (journalArticleResourceUuid == null) { continue; } rootElement.remove(assetTypeElementUuid); assetTypeElementUuid.setText(journalArticleResourceUuid); rootElement.add(assetTypeElementUuid); document.setRootElement(rootElement); assetEntryXmls[i] = document.formattedString(StringPool.BLANK); } }
From source file:com.liferay.journal.internal.exportimport.content.processor.JournalArticleExportImportContentProcessor.java
License:Open Source License
protected String replaceExportJournalArticleReferences(PortletDataContext portletDataContext, StagedModel stagedModel, String content, boolean exportReferencedContent) throws Exception { Group group = _groupLocalService.fetchGroup(portletDataContext.getGroupId()); if (group.isStagingGroup()) { group = group.getLiveGroup();/*from w w w . j ava 2s .com*/ } if (group.isStaged() && !group.isStagedRemotely() && !group.isStagedPortlet(JournalPortletKeys.JOURNAL)) { return content; } Document document = SAXReaderUtil.read(content); XPath xPath = SAXReaderUtil.createXPath("//dynamic-element[@type='ddm-journal-article']"); List<Node> ddmJournalArticleNodes = xPath.selectNodes(document); for (Node ddmJournalArticleNode : ddmJournalArticleNodes) { Element ddmJournalArticleElement = (Element) ddmJournalArticleNode; List<Element> dynamicContentElements = ddmJournalArticleElement.elements("dynamic-content"); for (Element dynamicContentElement : dynamicContentElements) { String jsonData = dynamicContentElement.getStringValue(); JSONObject jsonObject = _jsonFactory.createJSONObject(jsonData); long classPK = GetterUtil.getLong(jsonObject.get("classPK")); JournalArticle journalArticle = _journalArticleLocalService.fetchLatestArticle(classPK); if (journalArticle == null) { if (_log.isInfoEnabled()) { StringBundler messageSB = new StringBundler(); messageSB.append("Staged model with class name "); messageSB.append(stagedModel.getModelClassName()); messageSB.append(" and primary key "); messageSB.append(stagedModel.getPrimaryKeyObj()); messageSB.append(" references missing journal "); messageSB.append("article with class primary key "); messageSB.append(classPK); _log.info(messageSB.toString()); } continue; } String journalArticleReference = "[$journal-article-reference=" + journalArticle.getPrimaryKey() + "$]"; if (_log.isDebugEnabled()) { _log.debug("Replacing " + jsonData + " with " + journalArticleReference); } dynamicContentElement.clearContent(); dynamicContentElement.addCDATA(journalArticleReference); if (exportReferencedContent) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, stagedModel, journalArticle, PortletDataContext.REFERENCE_TYPE_DEPENDENCY); } else { Element entityElement = portletDataContext.getExportDataElement(stagedModel); portletDataContext.addReferenceElement(stagedModel, entityElement, journalArticle, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); } } } return document.asXML(); }
From source file:com.liferay.journal.internal.exportimport.content.processor.JournalArticleExportImportContentProcessor.java
License:Open Source License
protected void validateJournalArticleReferences(String content) throws PortalException { List<Throwable> throwables = new ArrayList<>(); try {/*from ww w . j av a2s. c o m*/ Document document = SAXReaderUtil.read(content); XPath xPath = SAXReaderUtil.createXPath("//dynamic-element[@type='ddm-journal-article']"); List<Node> ddmJournalArticleNodes = xPath.selectNodes(document); for (Node ddmJournalArticleNode : ddmJournalArticleNodes) { Element ddmJournalArticleElement = (Element) ddmJournalArticleNode; List<Element> dynamicContentElements = ddmJournalArticleElement.elements("dynamic-content"); for (Element dynamicContentElement : dynamicContentElements) { String json = dynamicContentElement.getStringValue(); if (Validator.isNull(json)) { if (_log.isDebugEnabled()) { _log.debug("No journal article reference is specified"); } continue; } JSONObject jsonObject = _jsonFactory.createJSONObject(json); long classPK = GetterUtil.getLong(jsonObject.get("classPK")); JournalArticle journalArticle = _journalArticleLocalService.fetchLatestArticle(classPK); if (journalArticle == null) { Throwable throwable = new NoSuchArticleException( "No JournalArticle exists with the key " + "{resourcePrimKey=" + classPK + "}"); throwables.add(throwable); } } } } catch (DocumentException de) { if (_log.isDebugEnabled()) { _log.debug("Invalid content:\n" + content); } } if (!throwables.isEmpty()) { throw new PortalException( new BulkException("Unable to validate journal article references", throwables)); } }
From source file:com.liferay.journal.verify.JournalServiceVerifyProcess.java
License:Open Source License
protected void updateLinkToLayoutElements(long groupId, Element element) { Element dynamicContentElement = element.element("dynamic-content"); Node node = dynamicContentElement.node(0); String text = node.getText(); if (!text.isEmpty() && !text.endsWith(StringPool.AT + groupId)) { node.setText(dynamicContentElement.getStringValue() + StringPool.AT + groupId); }/*from w w w . j a va2 s . com*/ }
From source file:com.liferay.tools.sourceformatter.XMLSourceProcessor.java
License:Open Source License
protected void checkServiceXMLExceptions(String fileName, Element rootElement) { Element exceptionsElement = rootElement.element("exceptions"); if (exceptionsElement == null) { return;//from w w w . j a v a2 s . c o m } List<Element> exceptionElements = exceptionsElement.elements("exception"); String previousException = StringPool.BLANK; for (Element exceptionElement : exceptionElements) { String exception = exceptionElement.getStringValue(); if (Validator.isNotNull(previousException) && (previousException.compareToIgnoreCase(exception) > 0)) { processErrorMessage(fileName, "sort: " + fileName + " " + exception); } previousException = exception; } }
From source file:com.sympo.twitter.TwitterOAuth.java
License:Open Source License
public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); String twitterApiKey = PropsUtil.get("twitter.api.key"); String twitterApiSecret = PropsUtil.get("twitter.api.secret"); OAuthService service = new ServiceBuilder().provider(TwitterApi.class).apiKey(twitterApiKey) .apiSecret(twitterApiSecret).build(); String oauthVerifier = ParamUtil.getString(request, "oauth_verifier"); String oauthToken = ParamUtil.getString(request, "oauth_token"); if (Validator.isNull(oauthVerifier) || Validator.isNull(oauthToken)) { return null; }// w w w. j av a2 s .c o m Verifier v = new Verifier(oauthVerifier); Token requestToken = new Token(oauthToken, twitterApiSecret); Token accessToken = service.getAccessToken(requestToken, v); String verifyCredentialsURL = PropsUtil.get("twitter.api.verify.credentials.url"); OAuthRequest authrequest = new OAuthRequest(Verb.GET, verifyCredentialsURL); service.signRequest(accessToken, authrequest); String bodyResponse = authrequest.send().getBody(); Document document = SAXReaderUtil.read(bodyResponse); Element rootElement = document.getRootElement(); Element idElement = rootElement.element("id"); String twitterId = idElement.getStringValue(); ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.getTable(User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME); ExpandoColumn expandoColumn = ExpandoColumnLocalServiceUtil.getColumn(expandoTable.getTableId(), "twitterId"); List<ExpandoValue> expandoValues = ExpandoValueLocalServiceUtil.getColumnValues( expandoColumn.getCompanyId(), User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, "twitterId", twitterId, QueryUtil.ALL_POS, QueryUtil.ALL_POS); int usersCount = expandoValues.size(); if (usersCount == 1) { ExpandoValue expandoValue = expandoValues.get(0); long userId = expandoValue.getClassPK(); User user = UserLocalServiceUtil.getUser(userId); session.setAttribute(TwitterConstants.TWITTER_ID_LOGIN, user.getUserId()); String redirect = PortalUtil.getPortalURL(request) + themeDisplay.getURLSignIn(); response.sendRedirect(redirect); return null; } else if (usersCount > 1) { if (_log.isDebugEnabled()) { _log.debug("There is more than 1 user with the same Twitter Id"); } } Element nameElement = rootElement.element("name"); Element screenNameElement = rootElement.element("screen_name"); String userName = nameElement.getStringValue(); String screenName = screenNameElement.getStringValue(); session.setAttribute(TwitterConstants.TWITTER_LOGIN_PENDING, Boolean.TRUE); String createAccountURL = PortalUtil.getCreateAccountURL(request, themeDisplay); createAccountURL = HttpUtil.setParameter(createAccountURL, "firstName", userName); createAccountURL = HttpUtil.setParameter(createAccountURL, "screenName", screenName); createAccountURL = HttpUtil.setParameter(createAccountURL, "twitterId", twitterId); response.sendRedirect(createAccountURL); return null; }