private void addAttribute(Element e, String attributeName, String value) {
   if (value != null) {
     Attr attr = e.getOwnerDocument().createAttribute(attributeName);
     attr.setNodeValue(value);
     e.setAttributeNode(attr);
   }
 }
  //
  // Marshaller's private methods
  //
  private Element marshallConfiguration(ComponentConfigurationImpl config) throws Exception {
    // get ComponentConfigurationImpl Object data
    String configPid = config.getPid();
    Map<String, Object> configProperty = config.getConfigurationProperties();
    Tocd configOCD = config.getDefinition();

    // create configuration element
    Element configurationElement =
        mashallDoc.createElement(ESF_NAMESPACE + ":" + CONFIGURATIONS_CONFIGURATION);
    Attr propertiesAttribute = mashallDoc.createAttribute(CONFIGURATION_PID);
    propertiesAttribute.setNodeValue(configPid);
    configurationElement.setAttributeNode(propertiesAttribute);

    // Add OCD node and marshall definitions
    if (configOCD != null) {
      Element ocd = new XmlJavaMetadataMapper().marshal(mashallDoc, configOCD);
      configurationElement.appendChild(ocd);
    }

    // Add properties Node and marshall properties
    if (configProperty != null) {
      Element properties = mashallDoc.createElement(ESF_NAMESPACE + ":" + PROPERTIES);
      marshallProperties(configProperty, properties);
      configurationElement.appendChild(properties);
    }

    return configurationElement;
  }
Пример #3
0
  /**
   * @param containingHtmlElement the name of the HTML element containing el. If the HTML element is
   *     contained inside a template construct then this name may differ from el's immediate parent.
   */
  private void inspectElement(JobEnvelope source, Element el, ElKey containingHtmlElement) {
    ElKey elKey = ElKey.forElement(el);

    // Recurse early so that ihtml:dynamic elements have been parsed before we
    // process the attributes element list.
    for (Node child : Nodes.childrenOf(el)) {
      inspect(source, child, elKey);
    }

    // For each attribute allowed on this element type, ensure that
    // (1) If it is not specified, and its default value is not allowed, then
    //     it is added with a known safe value.
    // (2) Its value is rewritten as appropriate.
    // We don't have to worry about disallowed attributes since those will
    // not be present in scriptsPerNode.  The TemplateSanitizer should have
    // stripped those out.  The TemplateSanitizer should also have stripped out
    // disallowed elements.
    if (!htmlSchema.isElementAllowed(elKey)) {
      return;
    }

    HTML.Element elInfo = htmlSchema.lookupElement(elKey);
    List<HTML.Attribute> attrs = elInfo.getAttributes();
    if (attrs != null) {
      for (HTML.Attribute a : attrs) {
        AttribKey attrKey = a.getKey();
        if (!htmlSchema.isAttributeAllowed(attrKey)) {
          continue;
        }
        Attr attr = null;
        String aUri = attrKey.ns.uri;
        String aName = attrKey.localName;
        Attr unsafe = el.getAttributeNodeNS(aUri, aName);
        if (unsafe != null && a.getValueCriterion().accept(unsafe.getValue())) {
          attr = unsafe;
        } else if ((a.getDefaultValue() != null
                && !a.getValueCriterion().accept(a.getDefaultValue()))
            || !a.isOptional()) {
          attr = el.getOwnerDocument().createAttributeNS(aUri, aName);
          String safeValue;
          if (a.getType() == HTML.Attribute.Type.URI) {
            safeValue = "" + Nodes.getFilePositionFor(el).source().getUri();
          } else {
            safeValue = a.getSafeValue();
          }
          if (safeValue == null) {
            mq.addMessage(
                IhtmlMessageType.MISSING_ATTRIB, Nodes.getFilePositionFor(el), elKey, attrKey);
            continue;
          }
          attr.setNodeValue(safeValue);
          el.setAttributeNodeNS(attr);
        }
        if (attr != null) {
          inspectHtmlAttribute(source, attr, a);
        }
      }
    }
    scriptsPerNode.put(el, null);
  }
Пример #4
0
 public void setAttribute(String name, String value) throws DOMException {
   Attr attribute = getAttributeNode(name);
   if (attribute == null) {
     attribute = mOwnerDocument.createAttribute(name);
   }
   attribute.setNodeValue(value);
   mAttributes.setNamedItem(attribute);
 }
Пример #5
0
 private void replaceLinkAttributes(final Element pushcontent) {
   for (final String attName : new String[] {ATTRIBUTE_NAME_HREF, ATTRIBUTE_NAME_CONREF}) {
     final Attr att = pushcontent.getAttributeNode(attName);
     if (att != null) {
       att.setNodeValue(replaceURL(att.getNodeValue()));
     }
   }
 }
  private Element marshallProperty(XmlConfigPropertyAdapted propertyObj) {
    String name = propertyObj.getName();
    Boolean array = propertyObj.getArray();
    Boolean encrypted = propertyObj.isEncrypted();
    ConfigPropertyType cpt = propertyObj.getType();
    String[] values = propertyObj.getValues();

    if (values != null) {
      Element property =
          mashallDoc.createElement(ESF_NAMESPACE + ":" + CONFIGURATIONS_CONFIGURATION_PROPERTY);
      Attr attName = mashallDoc.createAttribute(CONFIGURATIONS_CONFIGURATION_PROPERTY_NAME);
      attName.setNodeValue(name);
      property.setAttributeNode(attName);

      Attr attArray = mashallDoc.createAttribute(CONFIGURATIONS_CONFIGURATION_PROPERTY_ARRAY);
      attArray.setNodeValue(array.toString());
      property.setAttributeNode(attArray);

      Attr attEncrypted =
          mashallDoc.createAttribute(CONFIGURATIONS_CONFIGURATION_PROPERTY_ENCRYPTED);
      attEncrypted.setNodeValue(encrypted.toString());
      property.setAttributeNode(attEncrypted);

      Attr attType = mashallDoc.createAttribute(CONFIGURATIONS_CONFIGURATION_PROPERTY_TYPE);

      attType.setNodeValue(getStringValue(cpt));
      property.setAttributeNode(attType);

      for (String value : values) {
        Element valueElem =
            mashallDoc.createElement(
                ESF_NAMESPACE + ":" + CONFIGURATIONS_CONFIGURATION_PROPERTY_VALUE);
        valueElem.setTextContent(value);
        property.appendChild(valueElem);
      }
      return property;
    }
    return null;
  }
  public Node getAppletAppNode() {
    Node node = doc.getDocumentElement();

    if (node == null) {
      Element root = doc.createElement(XmlTagNames.XML_APPLET_APP_TAG);
      Attr attr = doc.createAttribute(XmlTagNames.XML_VERSION_ATTR);
      attr.setNodeValue(XmlTagNames.XML_APPLET_APP_VERSION);
      doc.appendChild(root);
      return root;
    } else if (node.getNodeName().equals(XmlTagNames.XML_APPLET_APP_TAG)) {
      return node;
    }
    return null;
  }
  /**
   * Write shortcuts to xml file
   *
   * @param shortcutsNode
   * @return
   */
  private static void setBindings(List<KeyBindingAction> list, Document document) {
    Node shortcutsNode = document.createElement(SHORTCUT_ROOT);

    Iterator<KeyBindingAction> it = list.iterator();
    while (it.hasNext()) {
      KeyBindingAction keyBindingAction = (KeyBindingAction) it.next();

      Node node = document.createElement(SHORTCUT_TAG);
      shortcutsNode.appendChild(node);

      Attr attrKey = document.createAttribute(SHORTCUT_ATTRIBUTE_KEY);
      Attr attrMask = document.createAttribute(SHORTCUT_ATTRIBUTE_MASK);
      Attr attrAction = document.createAttribute(SHORTCUT_ATTRIBUTE_ACTION);

      attrKey.setNodeValue(Integer.toString(keyBindingAction.getKeyBinding().getKey()));
      attrMask.setNodeValue(Integer.toString(keyBindingAction.getKeyBinding().getMask()));
      attrAction.setNodeValue(keyBindingAction.getAction());

      node.getAttributes().setNamedItem(attrKey);
      node.getAttributes().setNamedItem(attrMask);
      node.getAttributes().setNamedItem(attrAction);
    }
    document.appendChild(shortcutsNode);
  }
Пример #9
0
  @Override
  protected void saveEObjectSingle(EObject o, EStructuralFeature f) {
    StringBuffer buffer = new StringBuffer();

    EObject value = (EObject) helper.getValue(o, f);
    if (value != null) {
      String id = helper.getHREF(value);
      if (id != null) {
        id = convertURI(id);
        buffer.setLength(0);
        // if (!id.startsWith("#"))
        // {
        if (!o.eClass().getEPackage().getNsURI().equals(f.getEType().getEPackage().getNsURI())) {

          EClass eClass = value.eClass();
          EClass expectedType = (EClass) f.getEType();
          if (saveTypeInfo
              ? xmlTypeInfo.shouldSaveType(eClass, expectedType, f)
              : eClass != expectedType
                  && (expectedType.isAbstract()
                      || f.getEGenericType().getETypeParameter() != null)) {
            buffer.append(helper.getQName(eClass));
            buffer.append(' ');
          }
        }
        // }
        buffer.append(id);
        if (!toDOM) {
          String name = helper.getQName(f);
          doc.startAttribute(name);
          doc.addAttributeContent(buffer.toString());
          doc.endAttribute();
        } else {
          helper.populateNameInfo(nameInfo, f);
          Attr attr =
              document.createAttributeNS(nameInfo.getNamespaceURI(), nameInfo.getQualifiedName());
          attr.setNodeValue(buffer.toString());
          ((Element) currentNode).setAttributeNodeNS(attr);
          handler.recordValues(attr, o, f, value);
        }
      }
    }
  }
Пример #10
0
 /**
  * Sets an attribute of a node.
  *
  * @param doc The document the node comes from.
  * @param node The node where to set the attribute.
  * @param attribName The name of the attribute to set.
  * @param attribValue The value of the attribute to set.
  */
 public static void setAttribute(Document doc, Node node, String attribName, String attribValue) {
   Attr attr = doc.createAttribute(attribName);
   attr.setNodeValue(attribValue);
   node.getAttributes().setNamedItem(attr);
 }
 public void setAttribute(String paramString1, String paramString2) {
   Attr localAttr = getAttributeNode(paramString1);
   if (localAttr == null) localAttr = this.a.createAttribute(paramString1);
   localAttr.setNodeValue(paramString2);
   this.c.setNamedItem(localAttr);
 }
  /**
   * Process expressions on attributes.
   *
   * @param element The Element to process attributes on
   * @return Node to attach after this Element, or null
   */
  private Node processAttributes(Element element) {
    NamedNodeMap attributes = element.getAttributes();
    Node additionalNode = null;

    // Mutations to perform after iterating (if needed)
    List<Attr> attrsToRemove = null;
    String newId = null;

    for (int i = 0; i < attributes.getLength(); i++) {
      boolean removeThisAttribute = false;

      Attr attribute = (Attr) attributes.item(i);
      // Boolean attributes: evaluate as a boolean.  If true, set the value to the
      // name of the attribute, e.g. selected="selected".  If false, remove the attribute
      // altogether.  The check here has some limitations for efficiency:  it assumes the
      // attribute is lowercase, and doesn't bother to check whether the boolean attribute
      // actually exists on the referred element (but HTML has no attrs that are sometimes
      // boolean and sometimes not)
      if (element.getNamespaceURI() == null
          && HTML4_BOOLEAN_ATTRIBUTES.contains(attribute.getName())) {
        if (Boolean.TRUE.equals(evaluate(attribute.getValue(), Boolean.class, Boolean.FALSE))) {
          attribute.setNodeValue(attribute.getName());
        } else {
          removeThisAttribute = true;
        }
      } else if (ONCREATE_ATTRIBUTES.contains(attribute.getName())) {
        String id = element.getAttribute("id");
        if (id.length() == 0) {
          newId = id = getUniqueId();
        }

        additionalNode =
            buildOnCreateScript(
                evaluate(attribute.getValue(), String.class, null), id, element.getOwnerDocument());
        removeThisAttribute = true;
      } else {
        attribute.setNodeValue(evaluate(attribute.getValue(), String.class, null));
      }

      // Because NamedNodeMaps are live, removing them interferes with iteration.
      // Remove the attributes in a later pass
      if (removeThisAttribute) {
        if (attrsToRemove == null) {
          attrsToRemove = Lists.newArrayListWithCapacity(attributes.getLength());
        }

        attrsToRemove.add(attribute);
      }
    }

    // Now that iteration is complete, perform mutations
    if (attrsToRemove != null) {
      for (Attr attr : attrsToRemove) {
        element.removeAttributeNode(attr);
      }
    }

    if (newId != null) {
      element.setAttribute("id", newId);
    }

    return additionalNode;
  }