001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.tags.util;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.util.StringUtil;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.portal.util.PortletKeys;
028: import com.liferay.portlet.blogs.model.BlogsEntry;
029: import com.liferay.portlet.bookmarks.model.BookmarksEntry;
030: import com.liferay.portlet.documentlibrary.model.DLFileEntry;
031: import com.liferay.portlet.imagegallery.model.IGImage;
032: import com.liferay.portlet.journal.model.JournalArticle;
033: import com.liferay.portlet.messageboards.model.MBMessage;
034: import com.liferay.portlet.tags.NoSuchEntryException;
035: import com.liferay.portlet.tags.model.TagsEntry;
036: import com.liferay.portlet.tags.model.TagsProperty;
037: import com.liferay.portlet.tags.service.TagsEntryLocalServiceUtil;
038: import com.liferay.portlet.tags.service.TagsPropertyLocalServiceUtil;
039: import com.liferay.portlet.wiki.model.WikiPage;
040:
041: import java.util.Iterator;
042: import java.util.List;
043:
044: /**
045: * <a href="TagsUtil.java.html"><b><i>View Source</i></b></a>
046: *
047: * @author Brian Wing Shun Chan
048: *
049: */
050: public class TagsUtil {
051:
052: public static final String[] ASSET_TYPE_CLASS_NAMES = {
053: BlogsEntry.class.getName(), BookmarksEntry.class.getName(),
054: DLFileEntry.class.getName(), IGImage.class.getName(),
055: JournalArticle.class.getName(), MBMessage.class.getName(),
056: WikiPage.class.getName() };
057:
058: public static final String[] ASSET_TYPE_PORTLET_IDS = {
059: PortletKeys.BLOGS, PortletKeys.BOOKMARKS,
060: PortletKeys.DOCUMENT_LIBRARY, PortletKeys.IMAGE_GALLERY,
061: PortletKeys.JOURNAL, PortletKeys.MESSAGE_BOARDS,
062: PortletKeys.WIKI };
063:
064: public static boolean isValidWord(String word) {
065: if (Validator.isNull(word)) {
066: return false;
067: } else {
068: char[] c = word.toCharArray();
069:
070: for (int i = 0; i < c.length; i++) {
071: if (!Validator.isChar(c[i]) && !Validator.isDigit(c[i])
072: && (c[i] != ' ') && (c[i] != '.')
073: && (c[i] != '-') && (c[i] != '_')
074: && (c[i] != '(') && (c[i] != ')')) {
075:
076: return false;
077: }
078: }
079: }
080:
081: return true;
082: }
083:
084: public static String substitutePropertyVariables(long companyId,
085: String entryName, String s) throws PortalException,
086: SystemException {
087:
088: String result = s;
089:
090: TagsEntry entry = null;
091:
092: if (entryName != null) {
093: try {
094: entry = TagsEntryLocalServiceUtil.getEntry(companyId,
095: entryName);
096: } catch (NoSuchEntryException nsee) {
097: }
098: }
099:
100: if (entry != null) {
101: List properties = TagsPropertyLocalServiceUtil
102: .getProperties(entry.getEntryId());
103:
104: Iterator it = properties.iterator();
105:
106: while (it.hasNext()) {
107: TagsProperty property = (TagsProperty) it.next();
108:
109: result = StringUtil
110: .replace(result, "[$" + property.getKey()
111: + "$]", property.getValue());
112: }
113: }
114:
115: return StringUtil.stripBetween(result, "[$", "$]");
116: }
117:
118: }
|