Package org.waveprotocol.wave.model.document.util

Examples of org.waveprotocol.wave.model.document.util.XmlStringBuilder


      if (!waveXml.isEmpty()) {
        instrumentor.record(Action.CLIPBOARD_PASTE_FROM_WAVE);

        // initialise the XML:
        Builder builder = at(pos);
        XmlStringBuilder createdFromXmlString =
            XmlStringBuilder.createFromXmlStringWithContraints(waveXml,
                PermittedCharacters.BLIP_TEXT);

        // Strip annotations based on behaviour:
        StringMap<String> modified = annotationLogic.stripKeys(
            destDoc, pos, cursorBias, ContentType.RICH_TEXT, builder);

        double startTime = Duration.currentTimeMillis();
        // apply xml change
        MutableDocumentImpl.appendXmlToBuilder(createdFromXmlString, builder);
        double timeTaken = Duration.currentTimeMillis() - startTime;
        LOG.trace().log("time taken: " + timeTaken);

        // handle the end of annotations
        annotationLogic.unstripKeys(builder, modified.keySet(), CollectionUtils.createStringSet());
        builder.finish();
        Nindo nindo = builder.build();

        try {
          validator.maybeThrowOperationExceptionFor(nindo);

          int locationAfter = destDoc.getLocation(insertAt) + createdFromXmlString.getLength();
          destOperationSequencer.begin();
          destOperationSequencer.consume(nindo);
          destOperationSequencer.end();
          aggressiveSelectionHelper.setCaret(locationAfter);
View Full Code Here


        selectionMatcher.getHtmlEnd());

    Point<ContentNode> normalizedStart = normalize(contentSelection.getFirst());
    Point<ContentNode> normalizedEnd = normalize(contentSelection.getSecond());

    final XmlStringBuilder xmlInRange;
    final List<RangedAnnotation<String>> normalizedAnnotations;
    if (useSemanticCopyPaste) {
      String debugString =
          "Start: " + contentSelection.getFirst() + " End: " + contentSelection.getSecond()
              + " docDebug: " + mutableDocument.toDebugString();
View Full Code Here

        if (selection == null) {
          errorLabel.setText("Don't know where to insert this");
          return;
        }

        XmlStringBuilder xml;
        try {
           xml = XmlStringBuilder.innerXml(DocProviders.POJO.parse(contentInput.getText()));
        } catch (RuntimeException e) {
          errorLabel.setText("Ill formed XML");
          return;
View Full Code Here

   * @param state the initial gadget state.
   * @return content XML string for the gadget.
   */
  public static XmlStringBuilder constructXml(String url, String prefs, String author,
      @Nullable String[] categories, @Nullable Map<String, String> state) {
    final XmlStringBuilder builder = XmlStringBuilder.createEmpty();
    if (categories != null) {
      for (int i = 0; i < categories.length; ++i) {
        builder.append(
            XmlStringBuilder.createText("").wrap(
                CATEGORY_TAGNAME, KEY_ATTRIBUTE, categories[i]));
      }
    }
    if (state != null) {
      for (Map.Entry<String, String> entry : state.entrySet()) {
        builder.append(
            GadgetXmlUtil.constructStateXml(entry.getKey(), entry.getValue()));
      }
    }
    builder.wrap(
        TAGNAME,
        URL_ATTRIBUTE, url,
        TITLE_ATTRIBUTE, "",
        PREFS_ATTRIBUTE, prefs != null ? prefs : "",
        STATE_ATTRIBUTE, "",
View Full Code Here

    N nearestCommonAncestor =
        DocHelper.nearestCommonAncestor(doc, start.getCanonicalNode(), end.getCanonicalNode());

    Range inclusion = new Range(doc.getLocation(start), doc.getLocation(end));

    XmlStringBuilder builder =
      XmlStringBuilder.createEmptyWithCharConstraints(PermittedCharacters.BLIP_TEXT);

    E asElement = doc.asElement(nearestCommonAncestor);
    if (asElement != null) {
      for (N child = doc.getFirstChild(asElement);
           child != null; child = doc.getNextSibling(child)) {
        builder.append(augmentBuilder(child, inclusion));
      }
      if (asElement != doc.getDocumentElement()
          && shouldInclude(inclusion, getNodeRange(asElement))) {
        builder.wrap(doc.getTagName(asElement),
            CollectionUtils.adaptStringMap(doc.getAttributes(asElement)));
      }
    } else {
      T asText = doc.asText(nearestCommonAncestor);
      int tStart = doc.getLocation(asText);
      String substring =
          doc.getData(asText).substring(inclusion.getStart() - tStart, inclusion.getEnd() - tStart);

      builder.appendText(substring);
    }
    return builder;
  }
View Full Code Here

    return builder;
  }

  private XmlStringBuilder augmentBuilder(N node, Range inclusion) {
    Range nodeRange = getNodeRange(node);
    XmlStringBuilder builder = XmlStringBuilder.createEmpty();

    if (!shouldInclude(inclusion, nodeRange)) {
      return builder;
    }

    E asElement = doc.asElement(node);
    if (doc.asElement(node) != null) {
      for (N child = doc.getFirstChild(node); child != null; child = doc.getNextSibling(child)) {
        builder.append(augmentBuilder(child, inclusion));
      }
      builder.wrap(doc.getTagName(asElement),
          CollectionUtils.adaptStringMap(doc.getAttributes(asElement)));
    } else {
      T asText = doc.asText(node);
      int tStart = doc.getLocation(asText);
      String data = doc.getData(asText);
      int start = Math.max(0, inclusion.getStart() - tStart);
      int end = Math.min(data.length(), inclusion.getEnd() - tStart);

      builder.appendText(data.substring(start, end));
    }

    return builder;
  }
View Full Code Here

    } else {
      Element element = modifyAction.getElement(valueIndex);
      if (element != null) {
        if (element.isGadget()) {
          Gadget gadget = (Gadget) element;
          XmlStringBuilder xml =
              GadgetXmlUtil.constructXml(gadget.getUrl(), "", gadget.getAuthor(), null,
                  gadget.getProperties());
          // TODO (Yuri Z.) Make it possible to specify a location to insert the
          // gadget and implement insertion at the specified location.
          LineContainers.appendLine(doc, xml);
View Full Code Here

            doc.emptyElement(child);
            Point<Doc.N> point = Point.<Doc.N> inElement(child, null);
            doc.insertText(point, val);
          }
        } else {
          XmlStringBuilder xml = GadgetXmlUtil.constructStateXml(property.getKey(), val);
          doc.insertXml(Point.<Doc.N> inElement(existingElement, null), xml);
        }
      }
    }
  }
View Full Code Here

  public static boolean isNameValuePairElement(ContentNode node) {
    return EditorDocHelper.isNamedElement(node, NAMEVALUEPAIR_TAG);
  }

  public static XmlStringBuilder createXml(String url) {
    XmlStringBuilder builder = XmlStringBuilder.createEmpty();
    builder.wrap(TEMPLATE_TAG, URL_ATTRIBUTE, url);
    return builder;
  }
View Full Code Here

    FocusedRange focusedRange = editor.getSelectionHelper().getSelectionRange();
    if (focusedRange != null) {
      from = focusedRange.getFocus();
    }
    if (url != null && !url.isEmpty()) {
      XmlStringBuilder xml = GadgetXmlUtil.constructXml(url, "", user.getAddress());
      CMutableDocument document = editor.getDocument();
      if (document == null) {
        return;
      }
      if (from != -1) {
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.document.util.XmlStringBuilder

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.