예제 #1
0
 public void attribute(Txn transaction, AttrImpl attrib, NodePath path) {
   path.addComponent(attrib.getQName());
   if (config == null || config.matchAttribute(path)) {
     engine.storeAttribute(
         attrib,
         null,
         NativeTextEngine.ATTRIBUTE_NOT_BY_QNAME,
         config,
         mode == REMOVE_ALL_NODES);
   }
   if (config != null && config.hasQNameIndex(attrib.getQName())) {
     engine.storeAttribute(
         attrib, null, NativeTextEngine.ATTRIBUTE_BY_QNAME, config, mode == REMOVE_ALL_NODES);
   }
   path.removeLastComponent();
   super.attribute(transaction, attrib, path);
 }
예제 #2
0
  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;
  }
예제 #3
0
 /*
  * (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;
 }