List of usage examples for com.liferay.portal.kernel.xml SAXReaderUtil read
public static Document read(URL url) throws DocumentException
From source file:com.liferay.wiki.importer.impl.mediawiki.MediaWikiImporter.java
License:Open Source License
@Override public void importPages(long userId, WikiNode node, InputStream[] inputStreams, Map<String, String[]> options) throws PortalException { if ((inputStreams.length < 1) || (inputStreams[0] == null)) { throw new PortalException("The pages file is mandatory"); }/*from w w w.java 2 s .c o m*/ InputStream pagesInputStream = inputStreams[0]; InputStream usersInputStream = null; if (inputStreams.length > 1) { usersInputStream = inputStreams[1]; } InputStream imagesInputStream = null; if (inputStreams.length > 2) { imagesInputStream = inputStreams[2]; } try { Document document = SAXReaderUtil.read(pagesInputStream); Map<String, String> usersMap = readUsersFile(usersInputStream); Element rootElement = document.getRootElement(); List<String> specialNamespaces = readSpecialNamespaces(rootElement); processSpecialPages(userId, node, rootElement, specialNamespaces); processRegularPages(userId, node, rootElement, specialNamespaces, usersMap, imagesInputStream, options); processImages(userId, node, imagesInputStream); moveFrontPage(userId, node, options); } catch (DocumentException de) { throw new ImportFilesException("Invalid XML file provided"); } catch (IOException ioe) { throw new ImportFilesException("Error reading the files provided"); } catch (PortalException pe) { throw pe; } catch (Exception e) { throw new PortalException(e); } }
From source file:com.liferay.wsrp.admin.lar.AdminPortletDataHandlerImpl.java
License:Open Source License
@Override protected PortletPreferences doImportData(PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences, String data) throws Exception { Document document = SAXReaderUtil.read(data); Element rootElement = document.getRootElement(); if (portletDataContext.getBooleanParameter(_NAMESPACE, "wsrp-producers")) { Element wsrpProducersElement = rootElement.element("wsrp-producers"); importWSRPProducers(portletDataContext, wsrpProducersElement); }/*from www.j a v a2s.co m*/ if (portletDataContext.getBooleanParameter(_NAMESPACE, "wsrp-consumers")) { Element wsrpConsumersElement = rootElement.element("wsrp-consumers"); importWSRPConsumers(portletDataContext, wsrpConsumersElement); } return null; }
From source file:com.liferay.wsrp.util.WSRPConsumerManager.java
License:Open Source License
public WSRPConsumerManager(String url, RegistrationContext registrationContext, String forwardCookies, String forwardHeaders, String userToken) throws Exception { try {//from w ww . j a v a2s . c o m _wsdl = HttpUtil.URLtoString(url); Document document = SAXReaderUtil.read(_wsdl); Element root = document.getRootElement(); _wsdlNamespace = _getWsdlNamespace(root); List<Element> serviceElements = root.elements(_getWsdlQName("service")); ServiceHandler serviceHandler = new ServiceHandler(forwardCookies, forwardHeaders, userToken, _isV2(serviceElements)); _service = (WSRP_v2_Service) ProxyUtil.newProxyInstance(WSRP_v2_Service.class.getClassLoader(), new Class[] { WSRP_v2_Service.class }, serviceHandler); _readServiceElements(serviceElements); updateServiceDescription(registrationContext); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn(e, e); } throw e; } }
From source file:com.platts.portlet.documentlibrary.DLSetSeoUrl.java
License:Open Source License
@Override public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws PortalException, SystemException, IOException { LOGGER.info("the process action for struts action DLSetSeoUrl is getting called"); String uri = ParamUtil.getString(actionRequest, "uri", null); String seoURL = ParamUtil.getString(actionRequest, "seoURL", null); Long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId"); LOGGER.info("uri is " + uri + " seourl is " + seoURL + " fileEntryId " + fileEntryId); FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(fileEntryId); // sample url http://10.206.111.1:8030/v1/resources/content?uri=/test/holiday.xml&seoUrl=/EditorBios/regina1233johnson.xml StringBuilder url = new StringBuilder("http://10.206.111.1:8030/v1/resources/content?uri="); url.append(uri).append(StringPool.SLASH).append(fileEntry.getTitle()).append("&seoUrl=").append(seoURL); LOGGER.info("the url is " + url.toString()); PlattsExportUtil exportUtil = new PlattsExportUtil(); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); File file = exportUtil.getFileFromDLFile(themeDisplay.getUserId(), fileEntry.getFileEntryId(), fileEntry.getLatestFileVersion().getVersion()); //LOGGER.info("the file is " + FileUtils.readFileToString(file)); FileEntity fileEntity = new FileEntity(file); fileEntity.setContentType("application/xml"); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("CPUser", "CPUser22"); credentialsProvider.setCredentials(AuthScope.ANY, credentials); CloseableHttpClient httpClient = HttpClientBuilder.create() .setDefaultCredentialsProvider(credentialsProvider).build(); HttpPost postRequest = new HttpPost(url.toString()); postRequest.setEntity(fileEntity);//ww w . j a va 2s. co m try { CloseableHttpResponse response = httpClient.execute(postRequest); HttpEntity entity = response.getEntity(); String responseString = EntityUtils.toString(entity); Document document = SAXReaderUtil.read(responseString); String responseText = document.getRootElement().selectSingleNode("/response").getText(); if (responseText.equalsIgnoreCase("ok")) { SessionMessages.add(actionRequest, "seoURLActionSuccess"); hideDefaultSuccessMessage(actionRequest); String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect")); try { actionResponse.sendRedirect(redirect); } catch (IOException e) { LOGGER.error("error redirecting ", e); } } else { SessionErrors.add(actionRequest, "seoURLActionFailure"); LOGGER.info("the error text is " + responseText); actionResponse.setRenderParameter("errorMessage", responseText); } response.close(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
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 . ja va2s . c o 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.rivetlogic.ecommerce.cart.ShoppingCartItemUtil.java
License:Open Source License
public static Document getItemContent(String productId, long groupId) { JournalArticle jArticle = null;//from www.ja v a2 s . c o m Document document = null; try { jArticle = JournalArticleLocalServiceUtil.getArticle(groupId, productId); } catch (Exception e) { logger.error(e.getMessage()); } if (null != jArticle) { try { document = SAXReaderUtil.read(jArticle.getContent()); } catch (DocumentException e) { logger.error(e.getMessage()); } } return document; }
From source file:com.rivetlogic.ecommerce.portlet.ShoppingCartPortlet.java
License:Open Source License
private Document getItemContent(String productId, long groupId) { JournalArticle jArticle = null;//from w ww . j a v a 2 s.c o m Document document = null; try { jArticle = JournalArticleLocalServiceUtil.getArticle(groupId, productId); } catch (Exception e) { logger.error(e.getMessage()); } if (null != jArticle) { try { document = SAXReaderUtil.read(jArticle.getContent()); } catch (DocumentException e) { logger.error(e.getMessage()); } } return document; }
From source file:com.slemarchand.peoplepublisher.util.PeoplePublisherImpl.java
License:Open Source License
@Override public List<User> getUsers(PortletRequest portletRequest, PortletPreferences portletPreferences, String[] userXmls, boolean deleteMissingUsers) throws Exception { long companyId = PortalUtil.getCompanyId(portletRequest); List<User> users = new ArrayList<User>(); List<String> missingUserScreenNames = new ArrayList<String>(); for (String userXml : userXmls) { Document document = SAXReaderUtil.read(userXml); Element rootElement = document.getRootElement(); String screenName = rootElement.elementText("screen-name"); User user = null;/*ww w. j av a 2 s .c o m*/ user = UserLocalServiceUtil.getUserByScreenName(companyId, screenName); if (user == null) { if (deleteMissingUsers) { missingUserScreenNames.add(screenName); } continue; } users.add(user); } if (deleteMissingUsers) { removeAndStoreSelection(missingUserScreenNames, portletPreferences); if (!missingUserScreenNames.isEmpty()) { SessionMessages.add(portletRequest, "deletedMissingUsers", missingUserScreenNames); } } return users; }
From source file:com.slemarchand.peoplepublisher.util.PeoplePublisherImpl.java
License:Open Source License
public void removeAndStoreSelection(List<String> screenNames, PortletPreferences portletPreferences) throws Exception { if (screenNames.size() == 0) { return;//from ww w . java2 s . co m } String[] userXmls = portletPreferences.getValues("userXml", new String[0]); List<String> userXmlsList = ListUtil.fromArray(userXmls); Iterator<String> itr = userXmlsList.iterator(); while (itr.hasNext()) { String userXml = itr.next(); Document document = SAXReaderUtil.read(userXml); Element rootElement = document.getRootElement(); String screenName = rootElement.elementText("screen-name"); if (screenNames.contains(screenName)) { itr.remove(); } } portletPreferences.setValues("userXml", userXmlsList.toArray(new String[userXmlsList.size()])); portletPreferences.store(); }
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 ww . ja va 2 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; }