Updates (renames) the name of an element, attribute or processing instruction. @param pre PRE value of the node to be updated @param kind node kind of the updated node @param name name of the new element, attribute or processing instruction @param uri namespace URI
(final int pre, final int kind, final byte[] name, final byte[] uri)
| 509 | * @param uri namespace URI |
| 510 | */ |
| 511 | public final void update(final int pre, final int kind, final byte[] name, final byte[] uri) { |
| 512 | meta.update(); |
| 513 | |
| 514 | if(kind == PI) { |
| 515 | updateText(pre, trim(concat(name, cpToken(' '), atom(pre))), PI); |
| 516 | } else { |
| 517 | // check if namespace has changed |
| 518 | final byte[] prefix = prefix(name); |
| 519 | final int oldUriId = nspaces.uriIdForPrefix(prefix, pre, this); |
| 520 | final boolean nsFlag = oldUriId == 0 && uri.length != 0 && !eq(prefix, XML); |
| 521 | final int nsPre = kind == ATTR ? parent(pre, kind) : pre; |
| 522 | final int uriId = nsFlag ? nspaces.add(nsPre, prefix, uri, this) : |
| 523 | oldUriId != 0 && eq(nspaces.uri(oldUriId), uri) ? oldUriId : 0; |
| 524 | final int size = size(pre, kind); |
| 525 | |
| 526 | // write IDs of namespace URI and name, and namespace flag |
| 527 | if(kind == ATTR) { |
| 528 | // delete old values from attribute indexes |
| 529 | if(meta.updindex) { |
| 530 | if(meta.attrindex) attrIndex.delete(new ValueCache(pre, IndexType.ATTRIBUTE, this)); |
| 531 | if(meta.tokenindex) tokenIndex.delete(new ValueCache(pre, IndexType.TOKEN, this)); |
| 532 | } |
| 533 | table.write1(pre, 11, uriId); |
| 534 | table.write2(pre, 1, attrNames.put(name)); |
| 535 | if(nsFlag) table.write2(nsPre, 1, 1 << 15 | nameId(nsPre)); |
| 536 | // add new values to attribute indexes |
| 537 | if(meta.updindex) { |
| 538 | if(meta.attrindex) attrIndex.add(new ValueCache(pre, IndexType.ATTRIBUTE, this)); |
| 539 | if(meta.tokenindex) tokenIndex.add(new ValueCache(pre, IndexType.TOKEN, this)); |
| 540 | } |
| 541 | } else { |
| 542 | // update element name |
| 543 | final IntList pres = new IntList(); |
| 544 | // update text index |
| 545 | if(meta.updindex && meta.textindex) { |
| 546 | final int last = pre + size; |
| 547 | for(int curr = pre + attSize(pre, kind); curr < last; curr += size(curr, kind(curr))) { |
| 548 | if(kind(curr) == TEXT) pres.add(curr); |
| 549 | } |
| 550 | textIndex.delete(new ValueCache(pres, IndexType.TEXT, this)); |
| 551 | } |
| 552 | table.write1(pre, 3, uriId); |
| 553 | final int nameId = elemNames.put(name); |
| 554 | table.write2(nsPre, 1, (nsFlag || nsFlag(nsPre) ? 1 << 15 : 0) | nameId); |
| 555 | if(!pres.isEmpty()) textIndex.add(new ValueCache(pres, IndexType.TEXT, this)); |
| 556 | } |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * Updates (replaces) the value of a single text, comment, pi, attribute or document node. |