List of usage examples for com.liferay.portal.kernel.util HtmlUtil stripComments
public static String stripComments(String text)
From source file:com.liferay.journal.transformer.ContentTransformerListener.java
License:Open Source License
protected void replace(Element root, long articleGroupId) throws Exception { for (Element element : root.elements()) { List<Element> dynamicContentElements = element.elements("dynamic-content"); for (Element dynamicContentElement : dynamicContentElements) { String text = dynamicContentElement.getText(); text = HtmlUtil.stripComments(text); text = HtmlUtil.stripHtml(text); text = text.trim();/*from w w w . j a va 2s . c o m*/ // [@articleId;elementName@] if (Validator.isNotNull(text) && (text.length() >= 7) && text.startsWith("[@") && text.endsWith("@]")) { text = text.substring(2, text.length() - 2); int pos = text.indexOf(";"); if (pos != -1) { String articleId = text.substring(0, pos); String elementName = text.substring(pos + 1); JournalArticle article = JournalArticleLocalServiceUtil.getArticle(articleGroupId, articleId); dynamicContentElement.clearContent(); dynamicContentElement.addCDATA(getDynamicContent(article.getDocument(), elementName)); } } else if ((text != null) && text.startsWith("/image/journal/article?img_id")) { // Make sure to point images to the full path dynamicContentElement.setText("@cdn_host@@root_path@" + text); } } replace(element, articleGroupId); } }
From source file:com.liferay.netvibeswidget.util.NetvibesWidgetUtil.java
License:Open Source License
public static String[][] getCategories() throws Exception { String jsonString = HttpUtil/*from w w w.j a va 2 s . c o m*/ .URLtoString(HtmlUtil.stripComments("http://api.eco.netvibes.com/categories?format=json")); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(jsonString); JSONArray jsonArray = jsonObject.getJSONArray("categories"); if (jsonArray == null) { return new String[0][2]; } String[][] categories = new String[jsonArray.length()][2]; for (int i = 0; i < jsonArray.length(); i++) { JSONObject curJSONObject = jsonArray.getJSONObject(i); categories[i][0] = String.valueOf(curJSONObject.getInt("id")); categories[i][1] = curJSONObject.getString("label"); } return categories; }
From source file:com.liferay.netvibeswidget.util.NetvibesWidgetUtil.java
License:Open Source License
public static Object[] getWidgets(String query, String sort, int category, String region, int page, int limit) throws Exception { StringBuilder sb = new StringBuilder(); sb.append("http://api.eco.netvibes.com/search?category="); sb.append(category);//from w w w . java2s . co m sb.append("&format=json&limit="); sb.append(limit); sb.append("&page="); sb.append(page); sb.append("&query="); sb.append(HttpUtil.encodeURL(query)); sb.append("®ion="); sb.append(HttpUtil.encodeURL(region)); sb.append("&sort="); sb.append(HttpUtil.encodeURL(sort)); sb.append("&thumbheight=48&thumbwidth=64&type=uwa"); String jsonString = HttpUtil.URLtoString(HtmlUtil.stripComments(sb.toString())); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(jsonString); JSONArray jsonArray = jsonObject.getJSONArray("items"); List<Object[]> results = new ArrayList<Object[]>(); int total = 0; if (jsonArray != null) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject curJSONObject = jsonArray.getJSONObject(i); String link = curJSONObject.getString("link"); String title = curJSONObject.getString("title"); String description = curJSONObject.getString("description"); String thumbnail = curJSONObject.getString("thumbnail"); if (Validator.isNull(link) || Validator.isNull(title)) { continue; } results.add(new Object[] { link, title, description, thumbnail }); } total = jsonObject.getInt("total"); } return new Object[] { results, total }; }
From source file:com.liferay.portlet.journal.util.ContentTransformerListener.java
License:Open Source License
protected void replace(Element root) throws Exception { Map<String, String> tokens = getTokens(); long groupId = GetterUtil.getLong(tokens.get("group_id")); for (Element el : root.elements()) { Element dynamicContent = el.element("dynamic-content"); if (dynamicContent != null) { String text = dynamicContent.getText(); text = HtmlUtil.stripComments(text); text = HtmlUtil.stripHtml(text); text = text.trim();/* www . j a v a 2 s . c o m*/ // [@articleId;elementName@] if (Validator.isNotNull(text) && text.length() >= 7 && text.startsWith("[@") && text.endsWith("@]")) { text = text.substring(2, text.length() - 2); int pos = text.indexOf(";"); if (pos != -1) { String articleId = text.substring(0, pos); String elementName = text.substring(pos + 1, text.length()); JournalArticle article = JournalArticleLocalServiceUtil.getArticle(groupId, articleId); dynamicContent.clearContent(); dynamicContent.addCDATA(getDynamicContent(article.getContent(), elementName)); } } // Make sure to point images to the full path else if ((text != null) && (text.startsWith("/image/journal/article?img_id"))) { dynamicContent.setText("@cdn_host@@root_path@" + text); } } replace(el); } }
From source file:com.liferay.util.ant.Java2WsddTask.java
License:Open Source License
private static String _format(String content) throws Exception { content = HtmlUtil.stripComments(content); Document document = SAXReaderUtil.read(content); Element rootElement = document.getRootElement(); Element serviceElement = rootElement.element("service"); Map<String, Element> arrayMappingElements = new TreeMap<String, Element>(); Map<String, Element> typeMappingElements = new TreeMap<String, Element>(); Map<String, Element> operationElements = new TreeMap<String, Element>(); Map<String, Element> parameterElements = new TreeMap<String, Element>(); for (Element element : serviceElement.elements()) { String elementName = element.getName(); if (elementName.equals("arrayMapping")) { element.detach();/* www. java2s .c om*/ arrayMappingElements.put(element.formattedString(), element); } else if (elementName.equals("operation")) { element.detach(); StringBundler sb = new StringBundler(); String name = element.attributeValue("name"); sb.append(name); sb.append("_METHOD_"); for (Element parameterElement : element.elements("parameter")) { String type = parameterElement.attributeValue("type"); sb.append(type); sb.append("_PARAMETER_"); } operationElements.put(sb.toString(), element); } else if (elementName.equals("parameter")) { element.detach(); String name = element.attributeValue("name"); if (name.equals("allowedMethods")) { Attribute valueAttribute = element.attribute("value"); String[] values = StringUtil.split(valueAttribute.getValue(), CharPool.SPACE); Arrays.sort(values); valueAttribute.setValue(StringUtil.merge(values, StringPool.SPACE)); } else if (name.equals("schemaUnqualified")) { Attribute valueAttribute = element.attribute("value"); String[] values = StringUtil.split(valueAttribute.getValue()); Arrays.sort(values); valueAttribute.setValue(StringUtil.merge(values)); } parameterElements.put(name, element); } else if (elementName.equals("typeMapping")) { element.detach(); typeMappingElements.put(element.formattedString(), element); } } _addElements(serviceElement, arrayMappingElements); _addElements(serviceElement, typeMappingElements); _addElements(serviceElement, operationElements); _addElements(serviceElement, parameterElements); content = StringUtil.replace(document.formattedString(), "\"/>", "\" />"); return content; }