HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
List<String> saveTagErrors = new ArrayList<String>();
Map<String,Object> callbackData = new HashMap<String,Object>();
Tag tag = new Tag();
hostId=hostId.trim();
StringTokenizer tagNameToken = new StringTokenizer(tagNames, ",");
if (tagNameToken.hasMoreTokens()) {
for (; tagNameToken.hasMoreTokens();) {
String tagName = tagNameToken.nextToken().trim();
try{
tag = TagFactory.getTag(tagName, userId, hostId);
String tagStorageForHost = "";
Host host = APILocator.getHostAPI().find(hostId, APILocator.getUserAPI().getSystemUser(),true);
if(host==null) {
HttpSession session = WebContextFactory.get().getSession();
hostId = (String) session.getAttribute(com.dotmarketing.util.WebKeys.CMS_SELECTED_HOST_ID);
host = APILocator.getHostAPI().find(hostId, APILocator.getUserAPI().getSystemUser(),true);
}
tagAPI.addTagInode(tagName,
APILocator.getUserProxyAPI().getUserProxy(userId, APILocator.getUserAPI().getSystemUser(), false).getInode(),
hostId);
if(host!=null && host.getIdentifier()!=null && host.getIdentifier().equals(Host.SYSTEM_HOST))
tagStorageForHost = Host.SYSTEM_HOST;
else {
try {
tagStorageForHost = host.getMap().get("tagStorage").toString();
} catch(NullPointerException e) {
tagStorageForHost = Host.SYSTEM_HOST;
}
}
if (UtilMethods.isSet(tagStorageForHost)){
if (!tag.getHostId().equals(tagStorageForHost) && tag.getHostId().equals(Host.SYSTEM_HOST)) {
saveTagErrors.add("Global Tag Already Exists");
SessionMessages.clear(req.getSession());
}
}