List of usage examples for com.liferay.portal.kernel.io.unsync UnsyncStringReader UnsyncStringReader
public UnsyncStringReader(String string)
From source file:com.liferay.calendar.util.CalendarICalDataHandler.java
License:Open Source License
@Override public void importCalendar(long calendarId, String data) throws Exception { CalendarBuilder calendarBuilder = new CalendarBuilder(); UnsyncStringReader unsyncStringReader = new UnsyncStringReader(data); net.fortuna.ical4j.model.Calendar iCalCalendar = calendarBuilder.build(unsyncStringReader); List<VEvent> vEvents = iCalCalendar.getComponents(Component.VEVENT); for (VEvent vEvent : vEvents) { importICalEvent(calendarId, vEvent); }//www.j a v a 2s.co m }
From source file:com.liferay.customsql.CustomSQL.java
License:Open Source License
protected String transform(String sql) { sql = PortalUtil.transformCustomSQL(sql); StringBundler sb = new StringBundler(); try {//from ww w . j a v a 2s.c om UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(new UnsyncStringReader(sql)); String line = null; while ((line = unsyncBufferedReader.readLine()) != null) { sb.append(line.trim()); sb.append(StringPool.SPACE); } unsyncBufferedReader.close(); } catch (IOException ioe) { return sql; } return sb.toString(); }
From source file:com.liferay.google.apps.connector.GHelperUtil.java
License:Open Source License
public static Document getDocument(GAuthenticator gAuthenticator, String url) throws GoogleAppsException { try {/*from w w w . j a v a 2s . c o m*/ if (_log.isInfoEnabled()) { _log.info("getDocument request " + url); } Http.Options options = _getOptions(gAuthenticator); options.setLocation(url); String xml = HttpUtil.URLtoString(options); if (_log.isInfoEnabled()) { _log.info("getDocument response " + xml); } return SAXReaderUtil.read(new UnsyncStringReader(xml)); } catch (DocumentException de) { throw new GoogleAppsException(de); } catch (IOException ioe) { throw new GoogleAppsException(ioe); } }
From source file:com.liferay.journal.transformer.JournalXSLURIResolver.java
License:Open Source License
@Override public Source resolve(String href, String base) { try {// w ww.java2s. c o m String content = null; Matcher matcher = _templateIdPattern.matcher(href); if (matcher.matches()) { long articleGroupId = GetterUtil.getLong(_tokens.get("article_group_id")); String templateId = matcher.group(1); content = JournalUtil.getTemplateScript(articleGroupId, templateId, _tokens, _languageId); } else { content = HttpUtil.URLtoString(href); } return new StreamSource(new UnsyncStringReader(content)); } catch (Exception e) { _log.error(href + " does not reference a valid template"); return null; } }
From source file:com.liferay.journal.util.impl.JournalUtil.java
License:Open Source License
public static String diffHtml(long groupId, String articleId, double sourceVersion, double targetVersion, String languageId, PortletRequestModel portletRequestModel, ThemeDisplay themeDisplay) throws Exception { JournalArticle sourceArticle = JournalArticleLocalServiceUtil.getArticle(groupId, articleId, sourceVersion); if (!JournalArticleLocalServiceUtil.isRenderable(sourceArticle, portletRequestModel, themeDisplay)) { throw new CompareVersionsException(sourceVersion); }//w ww. j ava2 s . c om JournalArticleDisplay sourceArticleDisplay = JournalArticleLocalServiceUtil.getArticleDisplay(sourceArticle, null, Constants.VIEW, languageId, 1, portletRequestModel, themeDisplay); JournalArticle targetArticle = JournalArticleLocalServiceUtil.getArticle(groupId, articleId, targetVersion); if (!JournalArticleLocalServiceUtil.isRenderable(targetArticle, portletRequestModel, themeDisplay)) { throw new CompareVersionsException(targetVersion); } JournalArticleDisplay targetArticleDisplay = JournalArticleLocalServiceUtil.getArticleDisplay(targetArticle, null, Constants.VIEW, languageId, 1, portletRequestModel, themeDisplay); return DiffHtmlUtil.diff(new UnsyncStringReader(sourceArticleDisplay.getContent()), new UnsyncStringReader(targetArticleDisplay.getContent())); }
From source file:com.liferay.knowledgebase.admin.util.AdminUtil.java
License:Open Source License
public static String getKBArticleDiff(long resourcePrimKey, int sourceVersion, int targetVersion, String param) throws Exception { if (sourceVersion < KBArticleConstants.DEFAULT_VERSION) { sourceVersion = KBArticleConstants.DEFAULT_VERSION; }/*w ww . ja v a 2 s . c o m*/ if (sourceVersion == targetVersion) { KBArticle kbArticle = KBArticleLocalServiceUtil.getKBArticle(resourcePrimKey, targetVersion); return BeanPropertiesUtil.getString(kbArticle, param); } KBArticle sourceKBArticle = KBArticleLocalServiceUtil.getKBArticle(resourcePrimKey, sourceVersion); KBArticle targetKBArticle = KBArticleLocalServiceUtil.getKBArticle(resourcePrimKey, targetVersion); String sourceHtml = BeanPropertiesUtil.getString(sourceKBArticle, param); String targetHtml = BeanPropertiesUtil.getString(targetKBArticle, param); String diff = DiffHtmlUtil.diff(new UnsyncStringReader(sourceHtml), new UnsyncStringReader(targetHtml)); Source source = new Source(diff); OutputDocument outputDocument = new OutputDocument(source); for (Element element : source.getAllElements()) { StringBundler sb = new StringBundler(4); Attributes attributes = element.getAttributes(); if (attributes == null) { continue; } Attribute changeTypeAttribute = attributes.get("changeType"); if (changeTypeAttribute != null) { String changeTypeValue = changeTypeAttribute.getValue(); if (changeTypeValue.contains("diff-added-image")) { sb.append("border: 10px solid #CFC; "); } else if (changeTypeValue.contains("diff-changed-image")) { sb.append("border: 10px solid #C6C6FD; "); } else if (changeTypeValue.contains("diff-removed-image")) { sb.append("border: 10px solid #FDC6C6; "); } } Attribute classAttribute = attributes.get("class"); if (classAttribute != null) { String classValue = classAttribute.getValue(); if (classValue.contains("diff-html-added")) { sb.append("background-color: #CFC; "); } else if (classValue.contains("diff-html-changed")) { sb.append("background-color: #C6C6FD; "); } else if (classValue.contains("diff-html-removed")) { sb.append("background-color: #FDC6C6; "); sb.append("text-decoration: line-through; "); } } if (Validator.isNull(sb.toString())) { continue; } Attribute styleAttribute = attributes.get("style"); if (styleAttribute != null) { sb.append(GetterUtil.getString(styleAttribute.getValue())); } Map<String, String> map = outputDocument.replace(attributes, false); map.put("style", sb.toString()); } return outputDocument.toString(); }
From source file:com.liferay.petra.log4j.Log4JUtil.java
License:Open Source License
public static void configureLog4J(URL url) { if (url == null) { return;// w w w .j a va2 s.c o m } String urlContent = _getURLContent(url); if (urlContent == null) { return; } // See LPS-6029, LPS-8865, and LPS-24280 DOMConfigurator domConfigurator = new DOMConfigurator(); domConfigurator.doConfigure(new UnsyncStringReader(urlContent), LogManager.getLoggerRepository()); try { SAXReader saxReader = new SAXReader(); saxReader.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) { if (systemId.endsWith("log4j.dtd")) { return new InputSource(DOMConfigurator.class.getResourceAsStream("log4j.dtd")); } return null; } }); Document document = saxReader.read(new UnsyncStringReader(urlContent), url.toExternalForm()); Element rootElement = document.getRootElement(); List<Element> categoryElements = rootElement.elements("category"); for (Element categoryElement : categoryElements) { String name = categoryElement.attributeValue("name"); Element priorityElement = categoryElement.element("priority"); String priority = priorityElement.attributeValue("value"); java.util.logging.Logger jdkLogger = java.util.logging.Logger.getLogger(name); jdkLogger.setLevel(_getJdkLevel(priority)); } } catch (Exception e) { _logger.error(e, e); } }
From source file:com.liferay.petra.xml.Dom4jUtil.java
License:Open Source License
public static String toString(String xml, String indent) throws DocumentException, IOException { XMLReader xmlReader = null;/*from ww w . jav a 2 s . c om*/ if (SecureXMLFactoryProviderUtil.getSecureXMLFactoryProvider() != null) { xmlReader = SecureXMLFactoryProviderUtil.newXMLReader(); } SAXReader saxReader = new SAXReader(xmlReader); Document document = saxReader.read(new UnsyncStringReader(xml)); return toString(document, indent); }
From source file:com.liferay.portlet.blogs.util.LinkbackProducerUtil.java
License:Open Source License
public static boolean sendTrackback(String trackback, Map<String, String> parts) throws Exception { if (_log.isInfoEnabled()) { _log.info("Pinging trackback " + trackback); }/*from ww w .j a v a 2 s . c om*/ Http.Options options = new Http.Options(); options.addHeader(HttpHeaders.USER_AGENT, ReleaseInfo.getServerInfo()); options.setLocation(trackback); options.setParts(parts); options.setPost(true); String xml = HttpUtil.URLtoString(options); if (_log.isDebugEnabled()) { _log.debug(xml); } String error = xml; XMLStreamReader xmlStreamReader = null; try { XMLInputFactory xmlInputFactory = StAXReaderUtil.getXMLInputFactory(); xmlStreamReader = xmlInputFactory.createXMLStreamReader(new UnsyncStringReader(xml)); xmlStreamReader.nextTag(); xmlStreamReader.nextTag(); String name = xmlStreamReader.getLocalName(); if (name.equals("error")) { int status = GetterUtil.getInteger(xmlStreamReader.getElementText(), 1); if (status == 0) { if (_log.isInfoEnabled()) { _log.info("Trackback accepted"); } return true; } xmlStreamReader.nextTag(); name = xmlStreamReader.getLocalName(); if (name.equals("message")) { error = xmlStreamReader.getElementText(); } } } finally { if (xmlStreamReader != null) { try { xmlStreamReader.close(); } catch (Exception e) { } } } _log.error("Error while pinging trackback at " + trackback + ": " + error); return false; }
From source file:com.liferay.portlet.journal.util.URIResolver.java
License:Open Source License
public Source resolve(String href, String base) { try {//from w ww . j a v a2 s.c o m String content = null; int templatePathIndex = href.indexOf(_GET_TEMPLATE_PATH); if (templatePathIndex >= 0) { int templateIdIndex = templatePathIndex + _GET_TEMPLATE_PATH.length(); long groupId = GetterUtil.getLong(_tokens.get("group_id")); String templateId = href.substring(templateIdIndex, href.length()); content = JournalUtil.getTemplateScript(groupId, templateId, _tokens, _languageId); } else { content = HttpUtil.URLtoString(href); } return new StreamSource(new UnsyncStringReader(content)); } catch (Exception e) { _log.error(href + " does not reference a valid template"); return null; } }