Checks that adding tags to existing topic won't cause problems

@param topicNode The topic the tags below to.
@return True if the tags are valid otherwise false.
963300
private boolean validateExistingTopicTags(final ITopicNode topicNode, final BaseTopicWrapper<?> topic) {
        // Ignore validating revision topics
        if (topicNode.getRevision() != null) {
            return true;
        }

        boolean valid = true;
        final List<String> tagNames = topicNode.getTags(true);
        if (!tagNames.isEmpty()) {
            final Set<TagWrapper> tags = new HashSet<TagWrapper>();
            for (final String tagName : tagNames) {
                // Check if the app should be shutdown
                if (isShuttingDown.get()) {
                    shutdown.set(true);
                    return false;
                }
                // Get the tag from the database
                TagWrapper tag = null;
                try {
                    tag = tagProvider.getTagByName(tagName);
                } catch (NotFoundException e) {

                }

                // Check that it exists
                if (tag != null) {
                    tags.add(tag);
                }
            }

            // Add all the existing tags
            if (topic.getTags() != null) {
                tags.addAll(topic.getTags().getItems());
            }

            // Check that the mutex value entered is correct
            final Map<Integer, List<TagWrapper>> mapping = EntityUtilities.getCategoryMappingFromTagList(tags);
            for (final Entry<Integer, List<TagWrapper>> catEntry : mapping.entrySet()) {
                final CategoryWrapper cat = categoryProvider.getCategory(catEntry.getKey());
                final List<TagWrapper> catTags = catEntry.getValue();

                // Check if the app should be shutdown
                if (isShuttingDown.get()) {
                    shutdown.set(true);
                    return false;
                }

                // Check that only one tag has been set if the category is mutually exclusive
                if (cat.isMutuallyExclusive() && catTags.size() > 1) {
                    log.error(String.format(ProcessorConstants.ERROR_TOPIC_TOO_MANY_CATS_MSG, topicNode.getLineNumber(), cat.getName(),
                            topicNode.getText()));
                    valid = false;
                }
            }
        }
        return valid;
    }
169540
protected boolean validateFixedUrl(final SpecNode specNode, final Set<String> processedFixedUrls) {
        boolean valid = true;

        if (!ProcessorConstants.VALID_FIXED_URL_PATTERN.matcher(specNode.getFixedUrl()).matches()) {
            log.error(format(ProcessorConstants.ERROR_FIXED_URL_NOT_VALID, specNode.getLineNumber(), specNode.getText()));
            valid = false;
        } else if (processedFixedUrls.contains(specNode.getFixedUrl())) {
            log.error(format(ProcessorConstants.ERROR_FIXED_URL_NOT_UNIQUE, specNode.getLineNumber(), specNode.getFixedUrl(),
                    specNode.getText()));
            valid = false;
        }

        return valid;
    }
878139
public static boolean nodeMatches(final Node nd, final QName tag) {
    if (tag == null) {
      return false;
    }

    String ns = nd.getNamespaceURI();

    if (ns == null) {
      /* It appears a node can have a NULL namespace but a QName has a zero length
       */
      if ((tag.getNamespaceURI() != null) && (!"".equals(tag.getNamespaceURI()))) {
        return false;
      }
    } else if (!ns.equals(tag.getNamespaceURI())) {
      return false;
    }

    String ln = nd.getLocalName();

    if (ln == null) {
      if (tag.getLocalPart() != null) {
        return false;
      }
    } else if (!ln.equals(tag.getLocalPart())) {
      return false;
    }

    return true;
  }
1307360
public boolean add(AbstractRslNode node) {
        if (_specifications == null) _specifications = new LinkedList();
        return _specifications.add(node);
    }
1255541
private boolean checkElementName(final Node node) {
        return TOPIC_INDEXTERM.matches(node)
                || INDEXING_D_INDEX_SORT_AS.matches(node)
                || INDEXING_D_INDEX_SEE.matches(node)
                || INDEXING_D_INDEX_SEE_ALSO.matches(node);
    }
1237501
public boolean preValidateInfoTopic(final InfoTopic infoTopic, final ContentSpec contentSpec, final Map<String,
            InfoTopic> infoTopics) {
        // Check if the app should be shutdown
        if (isShuttingDown.get()) {
            shutdown.set(true);
            return false;
        }

        boolean valid = true;

        // Checks that the id isn't null and is a valid topic ID
        if (infoTopic.getId() == null || !infoTopic.getId().matches(CSConstants.ALL_TOPIC_ID_REGEX)) {
            log.error(String.format(ProcessorConstants.ERROR_INVALID_TOPIC_ID_MSG, infoTopic.getLineNumber(), infoTopic.getText()));
            valid = false;
        }

        // Check that we aren't using translations for anything but existing topics
        if (!infoTopic.isTopicAnExistingTopic()) {
            // Check that we aren't processing translations
            if (processingOptions.isTranslation()) {
                log.error(String.format(ProcessorConstants.ERROR_TOPIC_NO_NEW_TRANSLATION_TOPIC, infoTopic.getLineNumber(),
                        infoTopic.getText()));
                valid = false;
            }
        }

        // Check that we are allowed to create new topics
        if (!infoTopic.isTopicAnExistingTopic() && !processingOptions.isAllowNewTopics()) {
            log.error(String.format(ProcessorConstants.ERROR_TOPIC_NO_NEW_TOPIC_BUILD, infoTopic.getLineNumber(), infoTopic.getText()));
            valid = false;
        }

        // Existing Topics
        if (infoTopic.isTopicAnExistingTopic()) {
            // Check that tags aren't trying to be removed
            if (!infoTopic.getRemoveTags(false).isEmpty()) {
                log.error(String.format(ProcessorConstants.ERROR_TOPIC_EXISTING_TOPIC_CANNOT_REMOVE_TAGS, infoTopic.getLineNumber(),
                        infoTopic.getText()));
                valid = false;
            }

            // Check that tags aren't trying to be added to a revision
            if (processingOptions.isPrintChangeWarnings() && infoTopic.getRevision() != null && !infoTopic.getTags(false).isEmpty()) {
                log.warn(
                        String.format(ProcessorConstants.WARN_TAGS_IGNORE_MSG, infoTopic.getLineNumber(), "revision", infoTopic.getText()));
            }

            // Check that the assigned writer and description haven't been set
            if (infoTopic.getAssignedWriter(false) != null || infoTopic.getDescription(false) != null) {
                log.error(
                        String.format(ProcessorConstants.ERROR_TOPIC_EXISTING_BAD_OPTIONS, infoTopic.getLineNumber(), infoTopic.getText()));
                valid = false;
            }

            // Check that we aren't processing translations
            if (!infoTopic.getTags(true).isEmpty() && processingOptions.isTranslation()) {
                log.error(String.format(ProcessorConstants.ERROR_TOPIC_NO_TAGS_TRANSLATION_TOPIC, infoTopic.getLineNumber(),
                        infoTopic.getText()));
                valid = false;
            }
        }
        // Duplicated Topics
        else if (infoTopic.isTopicADuplicateTopic()) {
            String temp = "N" + infoTopic.getId().substring(1);

            // Check that the topic exists in the content specification
            if (!infoTopics.containsKey(temp)) {
                log.error(String.format(ProcessorConstants.ERROR_TOPIC_NONEXIST_MSG, infoTopic.getLineNumber(), infoTopic.getText()));
                valid = false;
            }
            // Cloned Topics
        } else if (infoTopic.isTopicAClonedTopic()) {
            // Check if a description or type exists. If one does then generate an error.
            if (infoTopic.getDescription(false) != null && !infoTopic.getDescription(false).equals("")) {
                log.error(String.format(ProcessorConstants.ERROR_TOPIC_CLONED_BAD_OPTIONS, infoTopic.getLineNumber(), infoTopic.getText()));
                valid = false;
            }
            // Duplicated Cloned Topics
        } else if (infoTopic.isTopicAClonedDuplicateTopic()) {
            // Find the duplicate topic in the content spec
            final String topicId = infoTopic.getId().substring(1);
            int count = 0;
            for (final Entry<String, InfoTopic> entry : infoTopics.entrySet()) {
                final String uniqueTopicId = entry.getKey();

                if (uniqueTopicId.endsWith(topicId) && !uniqueTopicId.endsWith(infoTopic.getId())) {
                    count++;
                }
            }

            // Check that the topic exists
            if (count == 0) {
                log.error(String.format(ProcessorConstants.ERROR_TOPIC_NONEXIST_MSG, infoTopic.getLineNumber(), infoTopic.getText()));
                valid = false;
            }
            // Check that the referenced topic is unique
            else if (count > 1) {
                log.error(
                        String.format(ProcessorConstants.ERROR_TOPIC_DUPLICATE_CLONES_MSG, infoTopic.getLineNumber(), infoTopic.getText()));
                valid = false;
            }
        }

        // Check for conflicting conditions
        checkForConflictingCondition(infoTopic, contentSpec);

        return valid;
    }
799307
public boolean heartbeat(ClusterNodeInfo clusterNodeInfo)
    throws DisallowedNode {
    ClusterNode node = nameToNode.get(clusterNodeInfo.name);
    if (!canAllowNode(clusterNodeInfo.getAddress().getHost())) {
      if (node != null) {
        node.heartbeat(clusterNodeInfo);
      } else {
        throw new DisallowedNode(clusterNodeInfo.getAddress().getHost());
      }
      return false;
    }
    boolean newNode = false;
    Map<ResourceType, String> currentResources =
        clusterNodeInfo.getResourceInfos();
    if (currentResources == null) {
      currentResources = new EnumMap<ResourceType, String>(ResourceType.class);
    }

    if (node == null) {
      LOG.info("Adding node with heartbeat: " + clusterNodeInfo.toString());
      node = new ClusterNode(clusterNodeInfo,
          topologyCache.getNode(clusterNodeInfo.address.host),
          cpuToResourcePartitioning);
      addNode(node, currentResources);
      newNode = true;
    }

    node.heartbeat(clusterNodeInfo);

    boolean appsChanged = false;
    Map<ResourceType, String> prevResources =
        nameToApps.get(clusterNodeInfo.name);
    Set<ResourceType> deletedApps = null;
    for (Map.Entry<ResourceType, String> entry : prevResources.entrySet()) {
      String newAppInfo = currentResources.get(entry.getKey());
      String oldAppInfo = entry.getValue();
      if (newAppInfo == null || !newAppInfo.equals(oldAppInfo)) {
        if (deletedApps == null) {
          deletedApps = EnumSet.noneOf(ResourceType.class);
        }
        deletedApps.add(entry.getKey());
        appsChanged = true;
      }
    }
    Map<ResourceType, String> addedApps = null;
    for (Map.Entry<ResourceType, String> entry : currentResources.entrySet()) {
      String newAppInfo = entry.getValue();
      String oldAppInfo = prevResources.get(entry.getKey());
      if (oldAppInfo == null || !oldAppInfo.equals(newAppInfo)) {
        if (addedApps == null) {
          addedApps = new EnumMap<ResourceType, String>(ResourceType.class);
        }
        addedApps.put(entry.getKey(), entry.getValue());
        appsChanged = true;
      }
    }
    if (deletedApps != null) {
      for (ResourceType deleted : deletedApps) {
        clusterManager.nodeAppRemoved(clusterNodeInfo.name, deleted);
      }
    }
    if (addedApps != null) {
      for (Map.Entry<ResourceType, String> added: addedApps.entrySet()) {
        addAppToNode(node, added.getKey(), added.getValue());
      }
    }

    updateRunnability(node);
    return newNode || appsChanged;
  }
1166863
public static void checkTopicName( String topicName ) throws JMSException
    {
        if (topicName == null)
            throw new FFMQException("Topic name is not set","INVALID_DESTINATION_NAME");      
        if (topicName.length() > FFMQConstants.MAX_TOPIC_NAME_SIZE)
            throw new FFMQException("Topic name '"+topicName+"' is too long ("+topicName.length()+" > "+FFMQConstants.MAX_TOPIC_NAME_SIZE+")","INVALID_DESTINATION_NAME");
        checkDestinationName(topicName);
    }
365462
private TopicWrapper getTopicForNewTopicNode(final DataProviderFactory providerFactory, final ITopicNode topicNode) {
        LOG.debug("Creating a new topic");

        final TopicProvider topicProvider = providerFactory.getProvider(TopicProvider.class);
        final TagProvider tagProvider = providerFactory.getProvider(TagProvider.class);
        final PropertyTagProvider propertyTagProvider = providerFactory.getProvider(PropertyTagProvider.class);

        // Create the topic entity.
        final TopicWrapper topic = topicProvider.newTopic();

        // Set the basics
        if (topicNode instanceof SpecTopic) {
            topic.setTitle(((SpecTopic) topicNode).getTitle());
        } else {
            topic.setTitle("Info");
        }
        topic.setDescription(topicNode.getDescription(true));
        topic.setXml("");

        // Write the type
        final TagWrapper tag;
        if (topicNode instanceof SpecTopic) {
            tag = tagProvider.getTagByName(((SpecTopic) topicNode).getType());
        } else {
            tag = tagProvider.getTag(serverEntities.getInfoTagId());
        }
        if (tag == null) {
            log.error(String.format(ProcessorConstants.ERROR_TYPE_NONEXIST_MSG, topicNode.getLineNumber(), topicNode.getText()));
            return null;
        }

        // Add the type to the topic
        topic.setTags(tagProvider.newTagCollection());
        topic.getTags().addNewItem(tag);

        // Add the added by property tag
        topic.setProperties(propertyTagProvider.newPropertyTagInTopicCollection(topic));
        final String assignedWriter = topicNode.getAssignedWriter(true);
        if (assignedWriter != null) {
            final PropertyTagWrapper addedByPropertyTag = propertyTagProvider.getPropertyTag(serverEntities.getAddedByPropertyTagId());
            final PropertyTagInTopicWrapper addedByProperty = propertyTagProvider.newPropertyTagInTopic(addedByPropertyTag, topic);
            addedByProperty.setValue(assignedWriter);
            topic.getProperties().addNewItem(addedByProperty);
        }

        return topic;
    }
982113
private Boolean hasChildNodes(Node n) {
        boolean flag = n.hasChildNodes();
        if (flag && XMLUnit.getIgnoreComments()) {
            List nl = nodeList2List(n.getChildNodes());
            flag = !nl.isEmpty();
        }
        return flag ? Boolean.TRUE : Boolean.FALSE;
    }
356412
private final void checkTopicNotNull(String topic) 
    throws InvalidTopicSyntaxException
  {
    if (topic == null)
      throw new InvalidTopicSyntaxException(
        NLS.format(
          "INVALID_TOPIC_ERROR_CWSIH0005",
          new Object[] { topic }));
  }
1305515
public static List<String> checkTopicRootElement(final ServerSettingsWrapper serverSettings, final BaseTopicWrapper<?> topic,
            final Document doc) {
        final List<String> xmlErrors = new ArrayList<String>();
        final ServerEntitiesWrapper serverEntities = serverSettings.getEntities();

        if (isTopicANormalTopic(topic, serverSettings)) {
            if (!doc.getDocumentElement().getNodeName().equals(DocBookUtilities.TOPIC_ROOT_NODE_NAME)) {
                xmlErrors.add("Topics must be a <" + DocBookUtilities.TOPIC_ROOT_NODE_NAME + ">.");
            }
        } else {
            if (topic.hasTag(serverEntities.getRevisionHistoryTagId())) {
                if (!doc.getDocumentElement().getNodeName().equals("appendix")) {
                    xmlErrors.add("Revision History topics must be an <appendix>.");
                }

                // Check to make sure that a revhistory entry exists
                final NodeList revHistoryList = doc.getElementsByTagName("revhistory");
                if (revHistoryList.getLength() == 0) {
                    xmlErrors.add("No <revhistory> element found. A <revhistory> must exist for Revision Histories.");
                }
            } else if (topic.hasTag(serverEntities.getLegalNoticeTagId())) {
                if (!doc.getDocumentElement().getNodeName().equals("legalnotice")) {
                    xmlErrors.add("Legal Notice topics must be a <legalnotice>.");
                }
            } else if (topic.hasTag(serverEntities.getAuthorGroupTagId())) {
                if (!doc.getDocumentElement().getNodeName().equals("authorgroup")) {
                    xmlErrors.add("Author Group topics must be an <authorgroup>.");
                }
            } else if (topic.hasTag(serverEntities.getAbstractTagId())) {
                if (!doc.getDocumentElement().getNodeName().equals("abstract")) {
                    xmlErrors.add("Abstract topics must be an <abstract>.");
                }
            } else if (topic.hasTag(serverEntities.getInfoTagId())) {
                if (DocBookVersion.DOCBOOK_50.getId().equals(topic.getXmlFormat())) {
                    if (!doc.getDocumentElement().getNodeName().equals("info")) {
                        xmlErrors.add("Info topics must be an <info>.");
                    }
                } else {
                    if (!doc.getDocumentElement().getNodeName().equals("sectioninfo")) {
                        xmlErrors.add("Info topics must be a <sectioninfo>.");
                    }
                }
            }
        }

        return xmlErrors;
    }
704399
public synchronized void addTextNode(String text) throws IOException {
		// check for non-empty string
		if(text == null || text.trim().length() == 0) {
			return;
		}
		// reject modification of already closed node
		if(isOpen==false) {
			throw new IOException("Attempted to add child text node to already closed tag '" + name + "'!");
		}
		if(lastChildNode==null) {
			// no child nodes yet, close opening tag
			writer.write(">");
		} else {
			// close previous sibling and move to new line
			// FIXME: is this a legal situation, and if: how do we format this issue nicely?
			lastChildNode.close();
			writer.write("\n");
			indentLine();
		}
		SXTextNode textNode = new SXTextNode(text, writer, tabLevel, tabString);
		lastChildNode = textNode;
	}
934578
public static boolean hasAnnotation(final ClassNode classNode, final Class<? extends Annotation> annotationClass) {
        return !classNode.getAnnotations(new ClassNode(annotationClass)).isEmpty();
    }
1374093
public void checkEventTopicSyntax(String topic)
	  throws InvalidTopicSyntaxException
	  {
	    checkTopicNotNull(topic);
	        
	    char[] chars = topic.toCharArray();

	    // becomes false when dot seen, stays false thereafter
	    boolean acceptDot = false;
	    // becomes false when hash seen, stays false thereafter    
	    boolean acceptOrdinary = true;
	    // becomes false on wildcard, true on separator
	    boolean prevSeparator = false;
	    // becomes true on separator    

	    for (int i = 0; i < chars.length; i++)
	    {
	      char cand = chars[i];
	      if (cand == MatchSpace.SUBTOPIC_MATCHONE_CHAR)
	      {
	        throw new InvalidTopicSyntaxException(
	          NLS.format(
	            "INVALID_TOPIC_ERROR_CWSIH0006",
	            new Object[] { topic }));
	      }
	      else if (cand == MatchSpace.SUBTOPIC_STOP_CHAR)
	      {
	        if (acceptDot)
	        {
	          prevSeparator = acceptDot = false;
	          acceptOrdinary = true;
	        }
	        else
	          throw new InvalidTopicSyntaxException(
	            NLS.format(
	              "INVALID_TOPIC_ERROR_CWSIH0006",
	              new Object[] { topic }));
	      }
	      else if (cand == MatchSpace.SUBTOPIC_SEPARATOR_CHAR)
	      {
	          // A separator is disallowed at the end of a publication
	          if(i == chars.length - 1)
	          {
	            throw new InvalidTopicSyntaxException(
	                NLS.format(
	                  "INVALID_TOPIC_ERROR_CWSIH0006",
	                  new Object[] { topic }));           
	          }
	          if(prevSeparator)
	          {
	            // We've found a '//' this is disallowed in a publication
	            // discriminator string
	            throw new InvalidTopicSyntaxException(
	              NLS.format(
	                "INVALID_TOPIC_ERROR_CWSIH0006",
	                new Object[] { topic }));
	          }
	          
	          // First separator          
	          acceptOrdinary = prevSeparator = true;
	          acceptDot = false;
	          
	      }
	      else if( cand == ':')
	      {
	        // :'s are disallowed in topic name parts
	        throw new InvalidTopicSyntaxException(
	          NLS.format(
	            "INVALID_TOPIC_ERROR_CWSIH0006",
	            new Object[] { topic }));
	      }      
	      else // Ordinary character
	      {
	        if (!acceptOrdinary)
	          throw new InvalidTopicSyntaxException(
	            NLS.format(
	              "INVALID_TOPIC_ERROR_CWSIH0006",
	              new Object[] { topic }));
	        
	        prevSeparator = false;
	        acceptDot = true;
	      }
	    }          
	  }
605117
public static boolean hasBindableAnnotation(AnnotatedNode node) {
        for (AnnotationNode annotation : node.getAnnotations()) {
            if (boundClassNode.equals(annotation.getClassNode())) {
                return true;
            }
        }
        return false;
    }
146353
public boolean isCompleteExceptIgnoredNodes() {
        synchronized (nodeStack) {
            if (nodeStack.isEmpty() && retainedNodes.isEmpty()) {
                return true;
            } else {
                // Check that remaining nodes can be ignored
                for (int i=0; i < nodeStack.size(); i++) {
                    if (!ignoredNodes.contains(nodeStack.get(i))) {
                        return false;
                    }
                }
                for (int i=0; i < retainedNodes.size(); i++) {
                    if (!ignoredNodes.contains(retainedNodes.get(i))) {
                        return false;
                    }
                }
                return true;
            }
        }
    }