/** * Returns all context nodes associated with the nodes in this node set. * * @param contextId used to track context nodes when evaluating predicate expressions. If * contextId != {@link Expression#NO_CONTEXT_ID}, the current context will be added to each * result of the of the selection. */ public NodeSet getContextNodes(int contextId) { NodeProxy current, context; ContextItem contextNode; NewArrayNodeSet result = new NewArrayNodeSet(); DocumentImpl lastDoc = null; for (Iterator i = iterator(); i.hasNext(); ) { current = (NodeProxy) i.next(); contextNode = current.getContext(); while (contextNode != null) { if (contextNode.getContextId() == contextId) { context = contextNode.getNode(); context.addMatches(current); // if (!result.contains(context)) { if (Expression.NO_CONTEXT_ID != contextId) context.addContextNode(contextId, context); if (lastDoc != null && lastDoc.getDocId() != context.getDocument().getDocId()) { lastDoc = context.getDocument(); result.add(context, getSizeHint(lastDoc)); } else result.add(context); // } } contextNode = contextNode.getNextDirect(); } } return result; }
/** * Renders the given range in the model as normal unselected text. This is implemented to paint * colors based upon the token-to-color translations. * * @param g the graphics context * @param x the starting X coordinate * @param y the starting Y coordinate * @param start the beginning position in the model * @param end the ending position in the model * @returns the location of the end of the range * @exception BadLocationException if the range is invalid */ @Override protected int drawUnselectedText(Graphics g, int x, int y, int start, int end) throws BadLocationException { DocumentImpl doc = (DocumentImpl) getDocument(); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); int mark = start; Segment text = new Segment(); for (Token token : doc.getTokensInRange(start, end)) { int endPosition = Math.min(token.getEndOffset(), end); token.accept(gd.setGraphics(g2)); doc.getText(mark, endPosition - mark, text); x = Utilities.drawTabbedText(text, x, y, g, this, mark); mark = endPosition; } // tokens may not reach to the end of the area we want rendered // so this will make up the remaining space if (end != mark) { doc.getText(mark, end - mark, text); x = Utilities.drawTabbedText(text, x, y, g, this, mark); } g2.setFont(g2.getFont().deriveFont(Font.PLAIN)); return x; }
public void setDocument(DocumentImpl doc, int newMode) { document = doc; mode = newMode; IndexSpec indexConf = document.getCollection().getIndexConfiguration(document.getBroker()); if (indexConf != null) config = indexConf.getFulltextIndexSpec(); engine.setDocument(document); }
private int getTagNameCase(Element element) { DocumentImpl document = (DocumentImpl) element.getOwnerDocument(); if (document == null) return DocumentTypeAdapter.STRICT_CASE; DocumentTypeAdapter adapter = (DocumentTypeAdapter) document.getAdapterFor(DocumentTypeAdapter.class); if (adapter == null) return DocumentTypeAdapter.STRICT_CASE; return adapter.getTagNameCase(); }
/** * Introduced in DOM Level 2. * * <p>Creates an XML Document object of the specified type with its document element. * * @param namespaceURI The namespace URI of the document element to create, or null. * @param qualifiedName The qualified name of the document element to create. * @param doctype The type of document to be created or null. * <p>When doctype is not null, its Node.ownerDocument attribute is set to the document being * created. * @return Document A new Document object. * @throws DOMException WRONG_DOCUMENT_ERR: Raised if doctype has already been used with a * different document. * @since WD-DOM-Level-2-19990923 */ public Document createDocument(String namespaceURI, String qualifiedName, DocumentType doctype) throws DOMException { if (doctype != null && doctype.getOwnerDocument() != null) { throw new DOMException( DOMException.WRONG_DOCUMENT_ERR, DOMMessageFormatter.formatMessage( DOMMessageFormatter.XML_DOMAIN, "WRONG_DOCUMENT_ERR", null)); } DocumentImpl doc = new PSVIDocumentImpl(doctype); Element e = doc.createElementNS(namespaceURI, qualifiedName); doc.appendChild(e); return doc; }
public void testGetChildNodes1() { MemTreeBuilder builder = new MemTreeBuilder(); builder.startDocument(); builder.startElement(new QName("top", null, null), null); builder.characters("text"); builder.endElement(); builder.endDocument(); DocumentImpl doc = builder.getDocument(); Node top = doc.getFirstChild(); assertEquals(Node.ELEMENT_NODE, top.getNodeType()); assertEquals("top", top.getNodeName()); assertEquals(1, top.getChildNodes().getLength()); }
/** Write a document out */ public void writeDocument(DocumentImpl doc) throws ShutdownException { int start = doc.getIndex(); int offset = BufferManager.getOffset(start); Page page = BufferManager.getPage(start); int size = page.documentSize(offset); while (size > 0) { // Fill our buffer with events short nRead = (short) Math.min(size, MAX_EVENTS - current_offset); page.copyEvents(offset, nRead, current_offset, types, strings); size -= nRead; offset += nRead; int pageSize = BufferManager.getPageSize(); if (size > 0 && offset >= pageSize) do { offset -= pageSize; page = page.getNext(); } while (offset >= pageSize); current_offset += nRead; assert current_offset == MAX_EVENTS || size == 0; // Write out as many full pages as possible writeOutPages(false); } }
public static StoredNode deserialize( byte[] data, int start, int len, DocumentImpl doc, boolean pooled) { int pos = start; byte idSizeType = (byte) (data[pos] & 0x3); boolean hasNamespace = (data[pos] & 0x10) == 0x10; int attrType = (data[pos] & 0x4) >> 0x2; pos += StoredNode.LENGTH_SIGNATURE_LENGTH; int dlnLen = ByteConversion.byteToShort(data, pos); pos += NodeId.LENGTH_NODE_ID_UNITS; NodeId dln = doc.getBroker().getBrokerPool().getNodeFactory().createFromData(dlnLen, data, pos); pos += dln.size(); short id = (short) Signatures.read(idSizeType, data, pos); pos += Signatures.getLength(idSizeType); String name = doc.getSymbols().getName(id); if (name == null) throw new RuntimeException("no symbol for id " + id); short nsId = 0; String prefix = null; if (hasNamespace) { nsId = ByteConversion.byteToShort(data, pos); pos += LENGTH_NS_ID; int prefixLen = ByteConversion.byteToShort(data, pos); pos += LENGTH_PREFIX_LENGTH; if (prefixLen > 0) prefix = UTF8.decode(data, pos, prefixLen).toString(); pos += prefixLen; } String namespace = nsId == 0 ? "" : doc.getSymbols().getNamespace(nsId); XMLString value = UTF8.decode(data, pos, len - (pos - start)); // OK : we have the necessary material to build the attribute AttrImpl attr; if (pooled) attr = (AttrImpl) NodePool.getInstance().borrowNode(Node.ATTRIBUTE_NODE); // attr = (AttrImpl)NodeObjectPool.getInstance().borrowNode(AttrImpl.class); else attr = new AttrImpl(); attr.setNodeName(doc.getSymbols().getQName(Node.ATTRIBUTE_NODE, namespace, name, prefix)); attr.value = value; attr.setNodeId(dln); if (dln == null) throw new RuntimeException("no node id " + id); attr.setType(attrType); return attr; }
@Override public Document createDocument( Map<String, PropertyData<?>> propMap, String user, Folder folder, ContentStream contentStream, List<String> policies, Acl addACEs, Acl removeACEs) { String name = (String) propMap.get(PropertyIds.NAME).getFirstValue(); DocumentImpl doc = new DocumentImpl(); doc.createSystemBasePropertiesWhenCreated(propMap, user); doc.setCustomProperties(propMap); doc.setRepositoryId(fRepositoryId); doc.setName(name); if (null != folder) { if (hasChild(folder, name)) { throw new CmisNameConstraintViolationException( "Cannot create document an object with name " + name + " already exists in folder " + getFolderPath(folder.getId())); } doc.addParentId(folder.getId()); } ContentStream content = setContent(doc, contentStream); doc.setContent(content); int aclId = getAclId(((FolderImpl) folder), addACEs, removeACEs); doc.setAclId(aclId); if (null != policies) { doc.setAppliedPolicies(policies); } String id = storeObject(doc); doc.setId(id); applyAcl(doc, addACEs, removeACEs); return doc; }
public static StoredNode deserialize( byte[] data, int start, int len, DocumentImpl doc, boolean pooled) { TextImpl text; if (pooled) text = (TextImpl) NodePool.getInstance().borrowNode(Node.TEXT_NODE); // text = (TextImpl)NodeObjectPool.getInstance().borrowNode(TextImpl.class); else text = new TextImpl(); int pos = start; pos += LENGTH_SIGNATURE_LENGTH; int dlnLen = ByteConversion.byteToShort(data, pos); pos += NodeId.LENGTH_NODE_ID_UNITS; NodeId dln = doc.getBroker().getBrokerPool().getNodeFactory().createFromData(dlnLen, data, pos); text.setNodeId(dln); int nodeIdLen = dln.size(); pos += nodeIdLen; text.cdata = UTF8.decode( data, pos, len - (LENGTH_SIGNATURE_LENGTH + nodeIdLen + NodeId.LENGTH_NODE_ID_UNITS)); return text; }
@Test public void testGetElementsByTagName() { MemTreeBuilder builder = new MemTreeBuilder(); builder.startDocument(); builder.startElement(new QName("xquery", null, null), null); builder.startElement(new QName("builtin-modules", null, null), null); AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute( null, "class", "class", "string", "org.exist.xquery.functions.util.UtilModule"); attrs.addAttribute(null, "uri", "uri", "string", "http://exist-db.org/xquery/util"); builder.startElement(new QName("module", null, null), attrs); builder.endElement(); attrs = new AttributesImpl(); attrs.addAttribute( null, "class", "class", "string", "org.exist.xquery.functions.request.RequestModule"); attrs.addAttribute(null, "uri", "uri", "string", "http://exist-db.org/xquery/request"); builder.startElement(new QName("module", null, null), attrs); attrs = new AttributesImpl(); attrs.addAttribute(null, "name", "name", "string", "stream"); attrs.addAttribute(null, "value", "value", "string", "true"); builder.startElement(new QName("parameter", null, null), attrs); builder.endElement(); builder.endElement(); attrs = new AttributesImpl(); attrs.addAttribute( null, "class", "class", "string", "org.exist.xquery.functions.util.ResponseModule"); attrs.addAttribute(null, "uri", "uri", "string", "http://exist-db.org/xquery/response"); builder.startElement(new QName("module", null, null), attrs); builder.endElement(); attrs = new AttributesImpl(); attrs.addAttribute( null, "class", "class", "string", "org.exist.xquery.functions.util.SessionModule"); attrs.addAttribute(null, "uri", "uri", "string", "http://exist-db.org/xquery/session"); builder.startElement(new QName("module", null, null), attrs); builder.endElement(); builder.endElement(); builder.endElement(); builder.endDocument(); DocumentImpl doc = builder.getDocument(); Node nXQuery = doc.getFirstChild(); assertTrue(nXQuery.getNodeType() == Node.ELEMENT_NODE); assertTrue(nXQuery.getLocalName().equals("xquery")); Node nBuiltinModules = nXQuery.getFirstChild(); assertTrue(nBuiltinModules.getNodeType() == Node.ELEMENT_NODE); assertTrue(nBuiltinModules.getLocalName().equals("builtin-modules")); NodeList nlModules = nBuiltinModules.getChildNodes(); for (int i = 0; i < nlModules.getLength(); i++) { Node nModule = nlModules.item(i); assertTrue(nModule.getNodeType() == Node.ELEMENT_NODE); assertTrue(nModule.getLocalName().equals("module")); Element eModule = (Element) nModule; NodeList nlParameter = eModule.getElementsByTagName("parameter"); if (eModule .getAttribute("class") .equals("org.exist.xquery.functions.request.RequestModule")) { assertEquals(1, nlParameter.getLength()); } else { assertEquals(0, nlParameter.getLength()); } } }
/* * (non-Javadoc) * * @see org.exist.xupdate.Modification#process(org.exist.dom.DocumentSet) */ public long process(Txn transaction) throws PermissionDeniedException, LockException, EXistException, XPathException { NodeList children = content; if (children.getLength() == 0) return 0; int modifications = children.getLength(); try { StoredNode ql[] = selectAndLock(transaction); IndexListener listener = new IndexListener(ql); NotificationService notifier = broker.getBrokerPool().getNotificationService(); Node temp; TextImpl text; AttrImpl attribute; ElementImpl parent; for (int i = 0; i < ql.length; i++) { StoredNode node = ql[i]; if (node == null) { LOG.warn("select " + selectStmt + " returned empty node"); continue; } DocumentImpl doc = (DocumentImpl) node.getOwnerDocument(); doc.getMetadata().setIndexListener(listener); if (!doc.getPermissions().validate(broker.getUser(), Permission.UPDATE)) throw new PermissionDeniedException("permission to update document denied"); switch (node.getNodeType()) { case Node.ELEMENT_NODE: if (modifications == 0) modifications = 1; ((ElementImpl) node).update(transaction, children); break; case Node.TEXT_NODE: parent = (ElementImpl) node.getParentNode(); temp = children.item(0); text = new TextImpl(temp.getNodeValue()); modifications = 1; text.setOwnerDocument(doc); parent.updateChild(transaction, node, text); break; case Node.ATTRIBUTE_NODE: parent = (ElementImpl) node.getParentNode(); if (parent == null) { LOG.warn("parent node not found for " + node.getNodeId()); break; } AttrImpl attr = (AttrImpl) node; temp = children.item(0); attribute = new AttrImpl(attr.getQName(), temp.getNodeValue()); attribute.setOwnerDocument(doc); parent.updateChild(transaction, node, attribute); break; default: throw new EXistException("unsupported node-type"); } doc.getMetadata().clearIndexListener(); doc.getMetadata().setLastModified(System.currentTimeMillis()); modifiedDocuments.add(doc); broker.storeXMLResource(transaction, doc); notifier.notifyUpdate(doc, UpdateListener.UPDATE); } checkFragmentation(transaction, modifiedDocuments); } finally { unlockDocuments(transaction); } return modifications; }