List of usage examples for com.liferay.portal.kernel.xml SAXReaderUtil createQName
public static QName createQName(String localName, Namespace namespace)
From source file:com.liferay.google.apps.connector.GHelperUtil.java
License:Open Source License
public static QName getAppsQName(String localName) { return SAXReaderUtil.createQName(localName, getAppsNamespace()); }
From source file:com.liferay.google.apps.connector.GHelperUtil.java
License:Open Source License
public static QName getAtomQName(String localName) { return SAXReaderUtil.createQName(localName, getAtomNamespace()); }
From source file:com.liferay.petra.xml.DocUtil.java
License:Open Source License
public static Element add(Element element, String name, Namespace namespace) { QName qName = SAXReaderUtil.createQName(name, namespace); return element.addElement(qName); }
From source file:com.liferay.petra.xml.DocUtil.java
License:Open Source License
public static Element add(Element element, String name, Namespace namespace, String text) { QName qName = SAXReaderUtil.createQName(name, namespace); return add(element, qName, text); }
From source file:com.liferay.portlet.blogs.lar.WordPressImporter.java
License:Open Source License
protected static void importComment(PortletDataContext context, User defaultUser, MBMessageDisplay messageDisplay, Map<Long, Long> messageIdMap, BlogsEntry entry, Element commentEl) throws PortalException, SystemException { MBThread thread = messageDisplay.getThread(); long commentId = GetterUtil .getLong(commentEl.elementTextTrim(SAXReaderUtil.createQName("comment_id", _NS_WP))); String commentContent = commentEl.elementTextTrim(SAXReaderUtil.createQName("comment_content", _NS_WP)); if (Validator.isNull(commentContent)) { return;/* w w w . j av a 2s .com*/ } String commentAuthor = commentEl.elementTextTrim(SAXReaderUtil.createQName("comment_author", _NS_WP)); commentAuthor = commentAuthor.substring(0, Math.min(75, commentAuthor.length())); long commentParentId = GetterUtil .getLong(commentEl.elementTextTrim(SAXReaderUtil.createQName("comment_parent", _NS_WP))); if (commentParentId == 0) { commentParentId = messageDisplay.getMessage().getMessageId(); } else { commentParentId = messageIdMap.get(commentParentId); } ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); MBMessage message = MBMessageLocalServiceUtil.addDiscussionMessage(defaultUser.getUserId(), commentAuthor, context.getGroupId(), BlogsEntry.class.getName(), entry.getEntryId(), thread.getThreadId(), commentParentId, null, commentContent, serviceContext); messageIdMap.put(commentId, message.getMessageId()); }
From source file:com.liferay.portlet.blogs.lar.WordPressImporter.java
License:Open Source License
protected static void importEntry(PortletDataContext context, User defaultUser, Map<String, Long> userMap, DateFormat dateFormat, Element entryEl) throws PortalException, SystemException { String creator = entryEl.elementText(SAXReaderUtil.createQName("creator", _NS_DC)); Long userId = userMap.get(creator); if (userId == null) { userId = context.getUserId(null); }//from w ww. jav a 2 s . c o m String title = entryEl.elementTextTrim("title"); if (Validator.isNull(title)) { title = entryEl.elementTextTrim(SAXReaderUtil.createQName("post_name", _NS_WP)); } String content = entryEl.elementText(SAXReaderUtil.createQName("encoded", _NS_CONTENT)); content = content.replaceAll("\\n", "\n<br />"); // LPS-1425 if (Validator.isNull(content)) { content = "<br />"; } String dateText = entryEl.elementTextTrim(SAXReaderUtil.createQName("post_date_gmt", _NS_WP)); Date postDate = new Date(); try { postDate = dateFormat.parse(dateText); } catch (ParseException pe) { _log.warn("Parse " + dateText, pe); } Calendar cal = Calendar.getInstance(); cal.setTime(postDate); int displayDateMonth = cal.get(Calendar.MONTH); int displayDateDay = cal.get(Calendar.DAY_OF_MONTH); int displayDateYear = cal.get(Calendar.YEAR); int displayDateHour = cal.get(Calendar.HOUR_OF_DAY); int displayDateMinute = cal.get(Calendar.MINUTE); String pingStatusText = entryEl.elementTextTrim(SAXReaderUtil.createQName("ping_status", _NS_WP)); boolean allowPingbacks = pingStatusText.equalsIgnoreCase("open"); boolean allowTrackbacks = allowPingbacks; String statusText = entryEl.elementTextTrim(SAXReaderUtil.createQName("status", _NS_WP)); int workflowAction = WorkflowConstants.ACTION_PUBLISH; if (statusText.equalsIgnoreCase("draft")) { workflowAction = WorkflowConstants.ACTION_SAVE_DRAFT; } String[] assetTagNames = null; String categoryText = entryEl.elementTextTrim("category"); if (Validator.isNotNull(categoryText)) { assetTagNames = new String[] { categoryText }; } ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setAssetTagNames(assetTagNames); serviceContext.setScopeGroupId(context.getGroupId()); serviceContext.setWorkflowAction(workflowAction); BlogsEntry entry = null; try { entry = BlogsEntryLocalServiceUtil.addEntry(userId, title, StringPool.BLANK, content, displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks, null, false, null, null, null, serviceContext); } catch (Exception e) { _log.error("Add entry " + title, e); return; } MBMessageDisplay messageDisplay = MBMessageLocalServiceUtil.getDiscussionMessageDisplay(userId, context.getGroupId(), BlogsEntry.class.getName(), entry.getEntryId(), WorkflowConstants.STATUS_APPROVED); Map<Long, Long> messageIdMap = new HashMap<Long, Long>(); List<Node> commentNodes = entryEl.selectNodes("wp:comment", "wp:comment_parent/text()"); for (Node commentNode : commentNodes) { Element commentEl = (Element) commentNode; importComment(context, defaultUser, messageDisplay, messageIdMap, entry, commentEl); } }
From source file:com.liferay.portlet.PortletQNameImpl.java
License:Open Source License
public QName getQName(Element qNameEl, Element nameEl, String defaultNamespace) { if ((qNameEl == null) && (nameEl == null)) { _log.error("both qname and name elements are null"); return null; }// w ww .j ava 2 s . c om if (qNameEl == null) { return SAXReaderUtil.createQName(nameEl.getTextTrim(), SAXReaderUtil.createNamespace(defaultNamespace)); } String localPart = qNameEl.getTextTrim(); int pos = localPart.indexOf(CharPool.COLON); if (pos == -1) { if (_log.isDebugEnabled()) { _log.debug("qname " + localPart + " does not have a prefix"); } return SAXReaderUtil.createQName(localPart); } String prefix = localPart.substring(0, pos); Namespace namespace = qNameEl.getNamespaceForPrefix(prefix); if (namespace == null) { if (_log.isWarnEnabled()) { _log.warn("qname " + localPart + " does not have a valid namespace"); } return null; } localPart = localPart.substring(prefix.length() + 1); return SAXReaderUtil.createQName(localPart, namespace); }
From source file:com.liferay.web.extender.internal.webbundle.WebBundleProcessor.java
License:Open Source License
protected void processPortletXML(String webContextpath) throws IOException { File portletXMLFile = new File(_deployedAppFolder, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD); if (!portletXMLFile.exists()) { return;//from w w w. j av a 2 s.c om } String content = FileUtil.read(portletXMLFile); Document document = null; try { document = SAXReaderUtil.read(content); } catch (DocumentException de) { throw new IOException(de); } Element rootElement = document.getRootElement(); List<Element> portletElements = rootElement.elements("portlet"); for (Element portletElement : portletElements) { String portletName = portletElement.elementText("portlet-name"); String invokerPortletName = "osgi".concat(webContextpath).concat(StringPool.SLASH).concat(portletName); XPath xPath = SAXReaderUtil.createXPath(_INVOKER_PORTLET_NAME_XPATH); Element invokerPortletNameEl = (Element) xPath.selectSingleNode(portletElement); if (invokerPortletNameEl == null) { Element portletClassElement = portletElement.element("portlet-class"); List<Node> children = portletElement.content(); int pos = children.indexOf(portletClassElement); QName qName = rootElement.getQName(); Element initParamElement = SAXReaderUtil .createElement(SAXReaderUtil.createQName("init-param", qName.getNamespace())); initParamElement.addElement("name").setText("com.liferay.portal.invokerPortletName"); initParamElement.addElement("value").setText(invokerPortletName); children.add(pos + 1, initParamElement); } else { Element valueElement = invokerPortletNameEl.element("value"); invokerPortletName = valueElement.getTextTrim(); if (!invokerPortletName.startsWith(StringPool.SLASH)) { invokerPortletName = StringPool.SLASH.concat(invokerPortletName); } invokerPortletName = "osgi".concat(webContextpath).concat(invokerPortletName); valueElement.setText(invokerPortletName); } } content = DDMXMLUtil.formatXML(document); FileUtil.write(portletXMLFile, content); }
From source file:com.liferay.wsrp.service.impl.WSRPConsumerPortletLocalServiceImpl.java
License:Open Source License
protected com.liferay.portal.kernel.xml.QName getQName(QName qName) { String localPart = qName.getLocalPart(); String prefix = qName.getPrefix(); String namespaceURI = qName.getNamespaceURI(); Namespace namespace = SAXReaderUtil.createNamespace(prefix, namespaceURI); return SAXReaderUtil.createQName(localPart, namespace); }
From source file:com.liferay.wsrp.util.WSRPConsumerManager.java
License:Open Source License
private com.liferay.portal.kernel.xml.QName _getWsdlQName(String localName) { return SAXReaderUtil.createQName(localName, _wsdlNamespace); }