Package dk.brics.xpath.evaluator

Examples of dk.brics.xpath.evaluator.StatusMap


   
    return g;
  }

  public void transferCheck(CheckStm s, XMLGraph base) {
    StatusMap sm = evaluateXPathOrRoot(s.getXPath(), base);
    switch (s.getKind()) {
    case GETNUMBER:
      checkXPathEmpty(s, base, sm);
      checkGetNumberOrStringFails(s, base, sm, true);
      break;
View Full Code Here


    final XMLGraph g = base.clone();
    if (g.isUnknown()) {
      return g;
    }
    final ChoiceNode gap_node = stm_nodes.getGapifyChoiceNode(s,g);
    StatusMap smt;
    //try {
      //smt = evaluator.evaluate(base, s.getXPath(), dummy_root, dummy_root_content);
    smt = evaluateXPathOrRoot(s.getXPath(), base);
    //} catch (XPathException e) {
    //  throw new XMLXPathException(e);
    //}
    final StatusMap sm = smt;
    checkXPathEmpty(s, base, sm);
    g.processRoots(new ReachableNodesProcessor(g) { 
      @Override
      public Object process(ChoiceNode n) { // all concrete nodes have a choice node parent
        Collection<Integer> cs = new LinkedHashSet<Integer>();
        boolean modified = false;
        boolean add_gap = false;
        for (int i : n.getContents()) {
          boolean keep = true;
          boolean hit = false;
          Node c = g.getNode(i);
          if (c instanceof ConcreteNode) {
            switch (sm.get(i)) {
            case ALL:
            case DEFINITE:
              hit = true;
              keep = false;
              break;
View Full Code Here

    cn.setContent(c, g);
    switch (s.getKind()) {
    case GET:
    case GETELEMENT: // TODO: to improve analysis precision, only select the *first* element for getElement
    case GETELEMENTS: {
      StatusMap sm;
//      try {
//        sm = evaluator.evaluate(base, s.getXPath(), dummy_root, dummy_root_content);
//      } catch (XPathException e) {
//        throw new XMLXPathException(e);
//      }
      sm = evaluateXPathOrRoot(s.getXPath(), base);
      checkXPathEmpty(s, base, sm);
      for (int i : sm.getNodes()) {
        if (g.getNode(i) instanceof ConcreteNode) {
          StatusMap.Status status = sm.get(i);
          if (status!=StatusMap.Status.NONE && status!=StatusMap.Status.NEVER)
            c.add(i);
        }
      }
      c.addAll(cn.getContents());
View Full Code Here

      return g;

    case SETATTRIBUTE:
    case APPENDCONTENT: // this is both appendContent(XML) and appendContent(XPath,XML)
    case PREPENDCONTENT:{
      final StatusMap stm = evaluateXPathOrRoot(s.getXPath(), g);
      boolean empty = checkXPathEmpty(s, g, stm);
      if (empty)
        return g;
      g.merge(xmlsrc);
      g.getRoots().retainAll(base.getRoots());
      // TODO can we append as root here???
      g.processReachableNodes(new NodeProcessor<Object>() {
        @Override
        public Object process(ElementNode n) {
          ChoiceNode ch = (ChoiceNode)g.getNode(n.getContent());
          switch (stm.get(n.getIndex())) {
          case DEFINITE:
          case ALL:
            left.getContents().addAll(ch.getContents());
            ch = makePrivate(ch, g);
            if (g.getGapTypeMap().isEmpty()) {
                ch.getContents().clear();
            }
            ch.getContents().add(seq.getIndex());
            break;
          case SOME:
          case DONTKNOW:
            ch = makePrivate(ch, g);
            left.getContents().addAll(ch.getContents());
            ch.getContents().add(seq.getIndex());
            break;
          case NONE:
          case NEVER:
            break;
          }
          return null;
        }
      });
      g.sharpen();
      return g;
    }
    case INSERTAFTER:
    case INSERTBEFORE: {
      final StatusMap stm = evaluateXPathOrRoot(s.getXPath(), g);
      boolean empty = checkXPathEmpty(s, g, stm);
      if (empty)
        return g;
      g.merge(xmlsrc);
      g.getRoots().retainAll(base.getRoots());
      g.processReachableNodes(new NodeProcessor<Object>() {
        @Override
        public Object process(ChoiceNode ch) {
          LinkedHashSet<Integer> cs = new LinkedHashSet<Integer>(ch.getContents());
          for (int child : ch.getContents()) {
            Node node = g.getNode(child);
            if (node instanceof ConcreteNode) {
              switch (stm.get(child)) {
              case ALL:
              case DEFINITE:
                  if (g.getGapTypeMap().isEmpty()) {
                      cs.remove(child);
                  }
View Full Code Here

  public XMLGraph transferRemove(final RemoveStm s, final XMLGraph base) {
    final XMLGraph g = base.clone();
    if (g.isUnknown()) {
      return g;
    }
    StatusMap smt;
    smt = evaluateXPathOrRoot(s.getXPath(), base); //evaluator.evaluate(base, s.getXPath(), dummy_root, dummy_root_content);
    final StatusMap sm = smt;
    checkXPathEmpty(s, base, sm);
    g.processRoots(new ReachableNodesProcessor(g) { 
      @Override
      public Object process(ChoiceNode n) { // all concrete nodes have a choice node parent
        Collection<Integer> cs = new LinkedHashSet<Integer>();
        boolean modified = false;
        boolean add_emptyseq = false;
        for (int i : n.getContents()) {
          boolean keep = true;
          if (base.getNode(i) instanceof ConcreteNode) {
            switch (sm.get(i)) {
            case ALL:
            case DEFINITE:
              add_emptyseq = true;
              if (g.getGapTypeMap().isEmpty()) {
                  keep = false;
View Full Code Here

    if (g.isUnknown() || xmlsrc.isUnknown()) {
      g.setUnknown();
      return g;
    }

    final StatusMap stm = evaluateXPathOrRoot(s.getXPath(), g);

    boolean empty = checkXPathEmpty(s, g, stm);
    if (empty)
      return g;

    g.merge(xmlsrc);
    g.getRoots().retainAll(base.getRoots());

    final TextNode text = stm_nodes.getSetTextNode(s, g);
    text.replaceText(s.getStringSource(), g);

    // TODO avoid recursive replacement for nodes that will not actually be replaced
    // because its ancestor got replaced instead.
    switch (s.getKind()) {
    case SET:
      // set(XPath, Object)
      g.processReachableNodes(new NodeProcessor<Object>() {
        @Override
        public Object process(ChoiceNode n) {
          LinkedHashSet<Integer> cs = new LinkedHashSet<Integer>(n.getContents());
          for (int child : n.getContents()) {
            Node node = g.getNode(child);
            if (node instanceof ConcreteNode) {
              switch (stm.get(child)) {
              case ALL:
              case DEFINITE:
                  if (g.getGapTypeMap().isEmpty()) {
                      cs.remove(child);
                  }
                cs.addAll(xmlsrc.getRoots());
                cs.add(text.getIndex());
                break;
              case SOME:
              case DONTKNOW:
                cs.addAll(xmlsrc.getRoots());
                cs.add(text.getIndex());
                break;
              case NONE:
              case NEVER:
                break;
              }
            }
          }
          n.setContent(cs, g);
          return null;
        }
      });
      break;

    case SETCONTENT:
      g.processReachableNodes(new NodeProcessor<Object>() {
        @Override
        public Object process(ElementNode n) {
          ChoiceNode ch = (ChoiceNode)g.getNode(n.getContent());
          LinkedHashSet<Integer> c = new LinkedHashSet<Integer>(ch.getContents());
          switch (stm.get(n.getIndex())) {
          case ALL:
          case DEFINITE:
              if (g.getGapTypeMap().isEmpty()) {
                  c.clear();
              }
View Full Code Here

TOP

Related Classes of dk.brics.xpath.evaluator.StatusMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.