Adds/updates one specific query from XML file into Repository

@param document document which would be read
@param name     query which should be loaded
545887
public static void add(Document document, String name) {
        Element element = findElement(document, name);

        AssertUtils.assertNotNull(element, "Failed to find element by name: " + name);

        add(element);
    }
1093269
private function createNullNode(\DOMDocument $document, string $name = null): \DOMNode
    {
        $node = $document->createElement('json:null');

        if (null !== $name) {
            $node->setAttribute('name', $name);
        }

        return $node;
    }
29213
public com.google.gwt.dom.client.Element createIFrameElement(Document doc, String name) {

        IFrameElement element = doc.createIFrameElement();
        element.setName(name);
        return element;
    }
520656
private void setC4Document(C4Document c4doc) {
        synchronized (lock) {
            replaceC4Document(c4doc);
            data = null;
            if (c4doc != null && !c4doc.deleted()) { data = c4doc.getSelectedBody2(); }
            updateDictionary();
        }
    }
811759
public void updateDocument(String id, Document document, String EmbeddedEntityFieldName)
    {
        if (log.isDebugEnabled())
        {
            log.debug("Updateing indexed document: {} for in file system using Lucene", document);
        }

        IndexWriter w = getIndexWriter();
        try
        {
            Term term = null;
            if (EmbeddedEntityFieldName == null)
            {
                term = new Term(IndexingConstants.ENTITY_ID_FIELD, id);
            }
            else
            {
                term = new Term(EmbeddedEntityFieldName, id);
            }
            w.updateDocument(term, document);

        }
        catch (LuceneIndexingException lie)
        {
            log.error("Error while updating LuceneIndexer, Caused by :.", lie);
            throw new LuceneIndexingException(lie);
        }
        catch (IOException ioe)
        {
            log.error("Error while reading Lucene indexes, Caused by :.", ioe);

        }
    }
1332712
@Override
   void addDocuments(Document[] docs) throws IOException
   {
      for (int i = 0; i < docs.length; i++)
      {
         Document old = pending.put(docs[i].get(FieldNames.UUID), docs[i]);
         if (old != null)
         {
            Util.disposeDocument(old);
         }
         if (pending.size() >= bufferSize)
         {
            commitPending();
         }
         numDocs++;
      }
      invalidateSharedReader();
   }
172340
void add_document(Document doc)
    {
        doc.feature().normalize();
        documents_.add(doc);
        composite_.add_vector(doc.feature());
    }
1214318
static void setName(NodeImpl node, String name) {
        int prefixSeparator = name.lastIndexOf(":");
        if (prefixSeparator != -1) {
            String prefix = name.substring(0, prefixSeparator);
            String localName = name.substring(prefixSeparator + 1);
            if (!DocumentImpl.isXMLIdentifier(prefix) || !DocumentImpl.isXMLIdentifier(localName)) {
                throw new DOMException(DOMException.INVALID_CHARACTER_ERR, name);
            }
        } else if (!DocumentImpl.isXMLIdentifier(name)) {
            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, name);
        }

        switch (node.getNodeType()) {
        case ATTRIBUTE_NODE:
            AttrImpl attr = (AttrImpl) node;
            attr.namespaceAware = false;
            attr.localName = name;
            break;

        case ELEMENT_NODE:
            ElementImpl element = (ElementImpl) node;
            element.namespaceAware = false;
            element.localName = name;
            break;

        default:
            throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
                    "Cannot rename nodes of type " + node.getNodeType());
        }
    }
960183
@Override
    public boolean updatePolicy(String name, String newDocument)
            throws PolicyIndexException {
        log.debug("Updating document: " + name);

        // FIXME:  DBXML container.updateDocument is failing to update document metadata (this tested on DBXML ver 2.5.13)
        // specifically anySubject, anyResource metadata elements are not changing
        // if Subjects and Resources elements are added/deleted from document.


        // FIXME: this will acquire and release write locks for each operation
        // should instead do this just once for an update
        deletePolicy(name);
        addPolicy(name, newDocument);

        // FIXME:  code below would also need updating for transactions, deadlocks, single thread updates...

        /* original code below works apart from metadata update not happening
        try {
            utils.validate(newDocument, name);
        } catch (MelcoePDPException e) {
            throw new PolicyIndexException(e);
        }

        XmlTransaction txn = null;

        try {
            try {
                txn = dbXmlManager.manager.createTransaction();
                XmlDocument doc = makeDocument(name, newDocument);
                dbXmlManager.container.updateDocument(txn, doc, dbXmlManager.updateContext);
                txn.commit();
                setLastUpdate(System.currentTimeMillis());
            } catch (XmlException xe) {
                txn.abort();
                throw new PolicyIndexException("Error updating document: "
                                                             + name,
                                                     xe);
            }
        } catch (XmlException xe) {
            throw new PolicyIndexException("Error aborting transaction: "
                    + xe.getMessage(), xe);
        }
        */

        return true;
    }
21753
@Override
    public String addPolicy(String name, String document)
            throws PolicyIndexException {

        String docName = null;
        DbXmlManager.writeLock.lock();
        try {

            XmlDocument doc = makeDocument(name, document);
            docName = doc.getName();
            log.debug("Adding document: " + docName);
            m_dbXmlManager.container.putDocument(doc,
                                               m_dbXmlManager.updateContext);
            setLastUpdate(System.currentTimeMillis());
        } catch (XmlException xe) {
            if (xe.getErrorCode() == XmlException.UNIQUE_ERROR) {
                throw new PolicyIndexException("Document already exists: "
                                               + docName);
            } else {
                throw new PolicyIndexException("Error adding policy: "
                                               + xe.getMessage(), xe);
            }
        } finally {
            DbXmlManager.writeLock.unlock();
        }

        return docName;
    }
915256
public void setDocuments(java.util.Collection<DocumentMetadata> documents) {
        if (documents == null) {
            this.documents = null;
            return;
        }

        this.documents = new java.util.ArrayList<DocumentMetadata>(documents);
    }
811042
public void updateNamespaces(Document document) {
	Namespace rootNamespace = Namespace.gatherNamespaces(document);
	document.setNamespace(rootNamespace);
	for (org.openprovenance.prov.model.Bundle bu: utils.getBundle(document)) {
	    Namespace ns=bu.getNamespace();
	    if (ns!=null) {
		ns.setParent(rootNamespace);
	    } else {
		ns=new Namespace();
		ns.setParent(rootNamespace);
		bu.setNamespace(ns);
	    }
	}
    }
502489
public String putDocument(Document document) {
		String key = UUID.randomUUID().toString();
		documentMap.put(key, document);
		return key;
	}
1192710
protected void addSimpleSearchSetting(CmsXmlContentDefinition contentDef, String name, String value)
    throws CmsXmlException {

        if ("false".equalsIgnoreCase(value)) {
            addSearchSetting(contentDef, name, Boolean.FALSE);
        } else if ("true".equalsIgnoreCase(value)) {
            addSearchSetting(contentDef, name, Boolean.TRUE);
        } else {
            StringTemplate template = m_searchTemplateGroup.getInstanceOf(value);
            if ((template != null) && (template.getFormalArgument("name") != null)) {
                template.setAttribute("name", CmsEncoder.escapeXml(name));
                String xml = template.toString();
                try {
                    Document doc = DocumentHelper.parseText(xml);
                    initSearchSettings(doc.getRootElement(), contentDef);
                } catch (DocumentException e) {
                    LOG.error(e.getLocalizedMessage(), e);
                }
            }
        }
    }
493126
public void addDocumentParticipantObject(String documentUniqueId, String repositoryUniqueId, String homeCommunityId)
	{
		List<TypeValuePairType> tvp = new LinkedList<>();
        //SEK - 10/19/2011 - added check for empty or null, RE: Issue Tracker artifact artf2295 (was Issue 135)
 		if (!EventUtils.isEmptyOrNull(repositoryUniqueId)) {
			tvp.add(getTypeValuePair("Repository Unique Id", repositoryUniqueId.getBytes()));
		}
		if (!EventUtils.isEmptyOrNull(homeCommunityId)) {
			tvp.add(getTypeValuePair("ihe:homeCommunityID", homeCommunityId.getBytes()));
		}
		
		addParticipantObjectIdentification(
				new RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectIDTypeCodes.ReportNumber(), 
				null, 
				null, 
				tvp, 
				documentUniqueId, 
				RFC3881ParticipantObjectTypeCodes.SYSTEM, 
				RFC3881ParticipantObjectTypeRoleCodes.REPORT,
				null, 
				null);
	}
745693
public final void entityReference(String name)
        throws org.xml.sax.SAXException
    {
        try
        {

        final java.io.Writer writer = m_writer;
        writer.write('&');
        writer.write(name);
        writer.write(';');
        
        } catch(IOException e)
        {
            throw new SAXException(e);
        }
    }
339602
public void addQueryToCollection(String queryName, String query, boolean isNativeQuery, Class clazz)
    {
        if (namedNativeQueries == null)
        {
            namedNativeQueries = new ConcurrentHashMap<String, QueryWrapper>();
        }
        if (!namedNativeQueries.containsKey(queryName))
        {
            namedNativeQueries.put(queryName, new QueryWrapper(queryName, query, isNativeQuery, clazz));
        }
        // No null check made as it will never hold null value
        else if (queryName != null && !getQuery(queryName).equals(query))
        {
            logger.error("Duplicate named/native query with name:" + queryName
                    + "found! Already there is a query with same name:" + namedNativeQueries.get(queryName));
            throw new ApplicationLoaderException("Duplicate named/native query with name:" + queryName
                    + "found! Already there is a query with same name:" + namedNativeQueries.get(queryName));
        }
    }