@Override
 protected void fillJDOMConfigElement(Element configElement) {
   super.fillJDOMConfigElement(configElement);
   if (this.getMinLength() > -1) {
     Element element = new Element("minlength");
     element.setText(String.valueOf(this.getMinLength()));
     configElement.addContent(element);
   }
   if (this.getMaxLength() > -1) {
     Element element = new Element("maxlength");
     element.setText(String.valueOf(this.getMaxLength()));
     configElement.addContent(element);
   }
   if (null != this.getRegexp() && this.getRegexp().trim().length() > 0) {
     Element regexpElem = new Element("regexp");
     CDATA cdata = new CDATA(this.getRegexp());
     regexpElem.addContent(cdata);
     configElement.addContent(regexpElem);
   }
   String toStringEqualValue = (this.getValue() != null) ? String.valueOf(this.getValue()) : null;
   this.insertJDOMConfigElement(
       "value", this.getValueAttribute(), toStringEqualValue, configElement);
   String toStringStartValue =
       (this.getRangeStart() != null) ? String.valueOf(this.getRangeStart()) : null;
   this.insertJDOMConfigElement(
       "rangestart", this.getRangeStartAttribute(), toStringStartValue, configElement);
   String toStringEndValue =
       (this.getRangeEnd() != null) ? String.valueOf(this.getRangeEnd()) : null;
   this.insertJDOMConfigElement(
       "rangeend", this.getRangeEndAttribute(), toStringEndValue, configElement);
 }
 public void createXml(String fileName) {
   Document document;
   Element root;
   root = new Element("employees");
   document = new Document(root);
   Element employee = new Element("employee");
   root.addContent(employee);
   Element name = new Element("name");
   name.setText("ddvip");
   employee.addContent(name);
   Element sex = new Element("sex");
   sex.setText("m");
   employee.addContent(sex);
   Element age = new Element("age");
   age.setText("23");
   employee.addContent(age);
   XMLOutputter XMLOut = new XMLOutputter();
   try {
     XMLOut.output(document, new FileOutputStream(fileName));
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
  @Override
  public Record addGlobalMetadataIdentifier(
      Record record, String reposIdentifier, String ctlg, String oaiID)
      throws IllegalStateException, JDOMException {
    // TODO Auto-generated method stub
    String ident = ctlg + "_" + reposIdentifier + "_";

    Element metametadata =
        JDomUtils.getXpathNode(
            "//lom:lom/lom:metaMetadata", Namespace.NO_NAMESPACE, record.getMetadata());

    if (metametadata != null) {

      if (xmlString.equals(""))
        xmlString = JDomUtils.parseXml2string(record.getMetadata().getDocument(), null);

      ident = ident.concat(createHash(xmlString));

      Element newIdentifier = new Element("identifier", Namespace.NO_NAMESPACE);
      metametadata.addContent(0, newIdentifier);

      Element catalog = new Element("catalog", Namespace.NO_NAMESPACE);
      catalog.setText(ctlg);
      newIdentifier.addContent(catalog);

      Element entry = new Element("entry", Namespace.NO_NAMESPACE);
      ident = ident.replace("/", ".");
      ident = ident.replace(":", ".");
      entry.setText(ident);
      newIdentifier.addContent(entry);
      gLOMID = ident;

    } else {
      if (xmlString.equals(""))
        xmlString = JDomUtils.parseXml2string(record.getMetadata().getDocument(), null);

      ident = ident.concat(createHash(xmlString));

      Element lom =
          JDomUtils.getXpathNode("//lom:lom", Namespace.NO_NAMESPACE, record.getMetadata());
      metametadata = new Element("metaMetadata", Namespace.NO_NAMESPACE);
      lom.addContent(2, metametadata);

      Element newIdentifier = new Element("identifier", Namespace.NO_NAMESPACE);
      metametadata.addContent(0, newIdentifier);

      Element catalog = new Element("catalog", Namespace.NO_NAMESPACE);
      catalog.setText(ctlg);
      newIdentifier.addContent(catalog);

      Element entry = new Element("entry", Namespace.NO_NAMESPACE);
      ident = ident.replace("/", ".");
      ident = ident.replace(":", ".");
      entry.setText(ident);
      newIdentifier.addContent(entry);
      gLOMID = ident;
    }
    return record;
  }
Example #4
0
  /**
   * Invoke a handler. If a fault occurs it will be handled via the <code>handleFault</code> method.
   *
   * @param context The message context.
   */
  public void invoke(MessageContext context) throws Exception {
    UMOEvent event = (UMOEvent) context.getProperty(MuleProperties.MULE_EVENT_PROPERTY);

    if (event == null && context.getClient() != null) {
      event = (UMOEvent) context.getClient().getProperty(MuleProperties.MULE_EVENT_PROPERTY);
    }

    if (event != null) {
      MuleSoapHeaders muleHeaders = new MuleSoapHeaders(event);
      Element header = context.getOutMessage().getHeader();

      if (header == null) {
        header =
            new Element(
                "Header",
                context.getOutMessage().getSoapVersion().getPrefix(),
                context.getOutMessage().getSoapVersion().getNamespace());
      }

      // we can also add some extra properties like
      // Enconding Property, Session Property

      Element muleHeader = null;
      Namespace ns =
          Namespace.getNamespace(MuleSoapHeaders.MULE_NAMESPACE, MuleSoapHeaders.MULE_10_ACTOR);
      if (muleHeaders.getCorrelationId() != null || muleHeaders.getReplyTo() != null) {
        muleHeader = new Element(MuleSoapHeaders.MULE_HEADER, ns);
      } else {
        return;
      }

      Element e = null;
      if (muleHeaders.getCorrelationId() != null) {

        e = new Element(MuleProperties.MULE_CORRELATION_ID_PROPERTY, ns);
        e.setText(muleHeaders.getCorrelationId());
        muleHeader.addContent(e);

        e = new Element(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY, ns);
        e.setText(muleHeaders.getCorrelationGroup());
        muleHeader.addContent(e);

        e = new Element(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY, ns);
        e.setText(muleHeaders.getCorrelationSequence());
        muleHeader.addContent(e);
      }
      if (muleHeaders.getReplyTo() != null) {

        e = new Element(MuleProperties.MULE_REPLY_TO_PROPERTY, ns);
        e.setText(muleHeaders.getReplyTo());
        muleHeader.addContent(e);
      }
      header.addContent(muleHeader);

      context.getOutMessage().setHeader(header);
    }
  }
Example #5
0
  /**
   * Builds the tree node representing the project, which is structured in a XML type file
   *
   * @param xmlProject an Element which contains the data of the project
   * @param path a String with the path of the file where the project is saved
   */
  public void buildStructure(Element xmlProject, String path) {
    if (xmlProject != null) {

      ItTreeNode root = (ItTreeNode) treeModel.getRoot();

      /*
       * The project node is created with an
       * id higher than the current highest id
       */
      int currentIdValue, maxIdValue = 0;
      for (int i = 0; i < root.getChildCount(); i++) {
        ItTreeNode current = (ItTreeNode) root.getChildAt(i);
        currentIdValue = Integer.parseInt(current.getReference().getAttributeValue("id"));
        if (currentIdValue > maxIdValue) maxIdValue = currentIdValue;
      }
      String idValue = String.valueOf(maxIdValue + 1);
      Element projectId = new Element("id");
      projectId.setText(idValue);
      xmlProject.getChild("generalInformation").addContent(projectId);

      Element projectHeader = new Element("projectHeader");
      Attribute headerId = new Attribute("id", idValue);
      Element filePath = new Element("filePath");

      if (path != null) {
        filePath.setText(path);
      }
      // If it is null then it is a new project (*itSIMPLE* is a internal control)
      else {
        filePath.setText("*itSIMPLE*" + idValue);
        xmlProject.getChild("name").setText(xmlProject.getChildText("name") + " " + idValue);
      }

      projectHeader.setAttribute(headerId);
      projectHeader.addContent(filePath);

      ItTreeNode treeProject =
          new ItTreeNode(xmlProject.getChildText("name"), xmlProject, projectHeader, null);
      // treeProject.setIcon(new ImageIcon("resources/images/project.png"));
      treeModel.insertNodeInto(treeProject, root, root.getChildCount());

      if (xmlProject.getName().equals("project")) {
        treeProject.setIcon(new ImageIcon("resources/images/project.png"));
        buildDiagramNode(xmlProject, treeProject);
      } else if (xmlProject.getName().equals("pddlproject")) {
        // System.out.println(path);
        treeProject.setIcon(new ImageIcon("resources/images/virtualprototype.png"));
        // System.out.println("PDDL project open");
        buildPDDLNode(xmlProject, treeProject, path);
      }
    }
  }
  /** 增加一个新的节点(用于发现之后,或者手动增加一个节点) */
  public void addNode(
      String index,
      String InBandwidthUtilHdx,
      String OutBandwidthUtilHdx,
      String image,
      String ip,
      String alias,
      String portuse,
      String x,
      String y) {
    Element eleNode = new Element("node");
    Element eleId = new Element("id");
    Element eleImg = new Element("img");
    Element eleX = new Element("x");
    Element eleY = new Element("y");
    Element eleIp = new Element("ip");
    Element eleAlias = new Element("alias");
    Element eleInfo = new Element("info");
    Element eleMenu = new Element("menu");

    eleId.setText(index);
    if (image == null) eleImg.setText(PanelNodeHelper.getMenuItem(index, ipaddress));
    else eleImg.setText(image);
    eleX.setText(x);
    eleY.setText(y);
    eleIp.setText(ip);
    eleAlias.setText(alias);
    StringBuffer msg = new StringBuffer(200);
    msg.append("<font color='green'>索引:");
    msg.append(index);
    msg.append("</font><br>");
    msg.append("描述:");
    msg.append(alias);
    msg.append("<br>");
    msg.append("应用:");
    msg.append(portuse);
    msg.append("<br>");
    msg.append("入口流速:");
    msg.append(InBandwidthUtilHdx);
    msg.append("<br>");

    msg.append("出口流速:");
    msg.append(OutBandwidthUtilHdx);
    msg.append("<br>");

    eleInfo.setText(msg.toString());
    eleMenu.setText(PanelNodeHelper.getMenuItem(index, ip));
    eleNode.addContent(eleId);
    eleNode.addContent(eleImg);
    eleNode.addContent(eleX);
    eleNode.addContent(eleY);
    eleNode.addContent(eleIp);
    eleNode.addContent(eleAlias);
    eleNode.addContent(eleInfo);
    eleNode.addContent(eleMenu);
    nodes.addContent(eleNode);
  }
 /**
  * This is the preferred way for creating a Representation via a customized Resource serialization
  *
  * @param rootName
  * @param serialization
  */
 public JdomRepresentation(String rootName, CoupleList<String, Object> serialization) {
   Element root = new Element(rootName);
   for (Couple<String, Object> couple : serialization) {
     Element elt = new Element(couple.getLeft());
     if (couple.getRight() == null) {
       elt.setText(this.getEmptyValue());
     } else {
       elt.setText(couple.getRight().toString());
     }
     root.addContent(elt);
   }
   this.document = new Document(root);
 }
Example #8
0
 /** @param element */
 public void toXML(Element element) {
   element.setAttribute(ATTR_NAME, name);
   Element descriptionElement = new Element(TAG_DESCRIPTION);
   descriptionElement.setText(description);
   element.addContent(descriptionElement);
   Element scriptFileElement = new Element(TAG_SCRIPT_FILE);
   scriptFileElement.setText(scriptFile.toString());
   element.addContent(scriptFileElement);
   for (ArgDescription argDescription : argDescriptions) {
     Element argDescriptionElement = new Element(TAG_ARG_DESCRIPTION);
     argDescription.toXML(argDescriptionElement);
     element.addContent(argDescriptionElement);
   }
 }
Example #9
0
 /** Set the text of an XML element, safely encode it if needed. */
 @NotNull
 public static Element setSafeXmlText(@NotNull Element element, @NotNull String text) {
   final Character first = firstCharacter(text);
   final Character last = lastCharacter(text);
   if (!StringHelper.isXmlCharacterData(text)
       || first != null && Character.isWhitespace(first)
       || last != null && Character.isWhitespace(last)) {
     element.setAttribute("encoding", "base64");
     final String encoded = new String(Base64.encodeBase64(text.getBytes()));
     element.setText(encoded);
   } else {
     element.setText(text);
   }
   return element;
 }
Example #10
0
 /*     */ private void fillIndexItemElement(Element parentEl) /*     */ {
   /* 224 */ List itemList = this.indexItemManager.list();
   /* 225 */ if (itemList == null) /* 226 */ return;
   /* 227 */ for (IndexItem item : itemList) {
     /* 228 */ Element itemEl = new Element("item");
     /* 229 */ Element titleEl = new Element("title");
     /* 230 */ titleEl.setText(item.getTitle());
     /* 231 */ itemEl.addContent(titleEl);
     /*     */
     /* 233 */ Element urlEl = new Element("url");
     /* 234 */ urlEl.setText(item.getUrl());
     /* 235 */ itemEl.addContent(urlEl);
     /* 236 */ parentEl.addContent(itemEl);
     /*     */ }
   /*     */ }
Example #11
0
  public void writeExternal(Element macro) throws WriteExternalException {
    macro.setAttribute(ATTRIBUTE_NAME, myName);
    final ActionDescriptor[] actions = getActions();
    for (int i = 0; i < actions.length; i++) {
      ActionDescriptor action = actions[i];
      Element actionNode = null;
      if (action instanceof TypedDescriptor) {
        actionNode = new Element(ELEMENT_TYPING);
        TypedDescriptor typedDescriptor = (TypedDescriptor) action;
        final String t = typedDescriptor.getText();
        actionNode.setText(t);
        actionNode.setAttribute(
            ATTRIBUTE_KEY_CODES,
            unparseKeyCodes(
                new Pair<List<Integer>, List<Integer>>(
                    typedDescriptor.getKeyCodes(), typedDescriptor.getKeyModifiers())));
      } else if (action instanceof IdActionDescriptor) {
        actionNode = new Element(ELEMENT_ACTION);
        actionNode.setAttribute(ATTRIBUTE_ID, ((IdActionDescriptor) action).getActionId());
      } else if (action instanceof ShortcutActionDesciption) {
        actionNode = new Element(ELEMENT_SHORTCUT);
        actionNode.setAttribute(ATTRIBUTE_TEXT, ((ShortcutActionDesciption) action).getText());
      }

      assert actionNode != null : action;

      macro.addContent(actionNode);
    }
  }
  public void writeExternal(Element macro) {
    macro.setAttribute(ATTRIBUTE_NAME, myName);
    final ActionDescriptor[] actions = getActions();
    for (ActionDescriptor action : actions) {
      Element actionNode = null;
      if (action instanceof TypedDescriptor) {
        actionNode = new Element(ELEMENT_TYPING);
        TypedDescriptor typedDescriptor = (TypedDescriptor) action;
        actionNode.setText(typedDescriptor.getText().replaceAll(" ", "&#x20;"));
        actionNode.setAttribute(
            ATTRIBUTE_KEY_CODES,
            unparseKeyCodes(
                Couple.of(typedDescriptor.getKeyCodes(), typedDescriptor.getKeyModifiers())));
      } else if (action instanceof IdActionDescriptor) {
        actionNode = new Element(ELEMENT_ACTION);
        actionNode.setAttribute(ATTRIBUTE_ID, ((IdActionDescriptor) action).getActionId());
      } else if (action instanceof ShortcutActionDesciption) {
        actionNode = new Element(ELEMENT_SHORTCUT);
        actionNode.setAttribute(ATTRIBUTE_TEXT, ((ShortcutActionDesciption) action).getText());
      }

      assert actionNode != null : action;

      macro.addContent(actionNode);
    }
  }
Example #13
0
 private void insertHead() {
   Element head = new Element("head");
   Element title = new Element("title");
   title.setText(FluxxMessage.m("opml_title"));
   head.addContent(title);
   root.addContent(head);
 }
  protected Element setElement(Element root, String name, Object value) {
    Element element = getElement(root, name);

    element.setText(value.toString());

    return element;
  }
Example #15
0
  /**
   * Creates a &quot;mini-template&quot; with a given tag and an optional child tag, then evaluates
   * it recursively.
   *
   * <p>This method is used to map certain tags as combinations of other tags (as in <a
   * href="http://aitools.org/aiml/TR/2001/WD-aiml/#section-short-cut-elements">short-cut elements
   * </a>).
   *
   * @param element the element to modify
   * @param newElementName the new name to give the element
   * @param childContent the name or content for the child to add
   * @param childType the type of the child
   * @return the result of processing this structure
   * @throws ProcessorException if there is an error in processing
   */
  public String shortcutTag(
      Element element,
      String newElementName,
      String childContent,
      Class<? extends Content> childType)
      throws ProcessorException {
    String response = "";

    // If the node is empty, we need not continue.
    if (element == null) {
      return "";
    }

    /*
     * Process children (if any). Clearly, the root tag cannot have an empty type, and the children must exist.
     */
    if ((!"".equals(childContent)) && ((childType == Element.class) || (childType == Text.class))) {
      Element newElement = new Element(newElementName, element.getNamespaceURI());
      /*
       * Create an XML node for the child tag. Note that we assume that the child is an empty tag with no
       * attributes. This is reasonable for AIML 1.0.1, but might not always be.
       */
      if (childType == Element.class) {
        newElement.addContent(new Element(childContent, element.getNamespaceURI()));
      } else if (childType == Text.class) {
        newElement.setText(childContent);
      }

      // Now evaluate the node, just as if it came from the original AIML.
      response = response + evaluate(newElement);
    }

    return response;
  }
Example #16
0
  private List<Element> handleParameterName(String[] parameterNames) throws CatalogException {
    Element values;
    List<Element> domainValuesList = null;

    for (int i = 0; i < parameterNames.length; i++) {

      if (i == 0) domainValuesList = new ArrayList<Element>();

      // Generate DomainValues element
      Element domainValues = new Element("DomainValues", Csw.NAMESPACE_CSW);

      // FIXME what should be the type ???
      domainValues.setAttribute("type", "csw:Record");

      String paramName = parameterNames[i];

      // Set parameterName in any case.
      Element pn = new Element("ParameterName", Csw.NAMESPACE_CSW);
      domainValues.addContent(pn.setText(paramName));

      String operationName = paramName.substring(0, paramName.indexOf('.'));
      String parameterName = paramName.substring(paramName.indexOf('.') + 1);

      CatalogService cs = checkOperation(operationName);
      values = cs.retrieveValues(parameterName);

      // values null mean that the catalog was unable to determine
      // anything about the specified parameter
      if (values != null) domainValues.addContent(values);

      // Add current DomainValues to the list
      domainValuesList.add(domainValues);
    }
    return domainValuesList;
  }
Example #17
0
 private Element getSecurityContraintsElement() {
   Element securityContraints = new Element(SECURITY_CONSTRAINTS);
   List allGroupRules = mSecurityConstraints.getAllGroupRules();
   for (int i = 0; i < allGroupRules.size(); i++) {
     GroupRules groupRules = (GroupRules) allGroupRules.get(i);
     List rules = groupRules.getRules();
     if (rules.size() == 0) {
       continue;
     }
     Element groupRulesElement = new Element(GROUP_RULES);
     groupRulesElement.setAttribute(GROUP, groupRules.getGroupName());
     for (int j = 0; j < rules.size(); j++) {
       RuleDescription ruleDescription = (RuleDescription) rules.get(j);
       Element ruleElement;
       if (ruleDescription.getType() == RuleDescription.INCLUDE) {
         ruleElement = new Element(INCLUDE_RULE);
       } else {
         ruleElement = new Element(EXCLUDE_RULE);
       }
       ruleElement.setAttribute(RESOURCE, ruleDescription.getResource());
       ruleElement.setAttribute(CLASS, ruleDescription.getRetsClass());
       String systemNames = StringUtils.join(ruleDescription.getSystemNames().iterator(), " ");
       Element systemNamesElement = new Element(SYSTEM_NAMES);
       systemNamesElement.setText(systemNames);
       ruleElement.addContent(systemNamesElement);
       groupRulesElement.addContent(ruleElement);
     }
     securityContraints.addContent(groupRulesElement);
   }
   return securityContraints;
 }
 /** {@inheritDoc } */
 @Override
 public JdomRepresentation add(String nodeName, String nodeValue) throws XmlException {
   Element element = new Element(nodeName, this.document.getRootElement().getNamespace());
   element.setText(nodeValue);
   this.document.getRootElement().addContent(element);
   return this;
 }
  /**
   * @param request
   * @param response
   * @param fileIds
   * @param totalInserted
   * @param totalUpdated
   * @param totalDeleted
   */
  private void getResponseResult(
      Element request,
      Element response,
      List<String> fileIds,
      int totalInserted,
      int totalUpdated,
      int totalDeleted) {
    // transactionSummary
    Element transactionSummary = getTransactionSummary(totalInserted, totalUpdated, totalDeleted);

    // requestID
    String strRequestId = request.getAttributeValue("requestId");
    if (strRequestId != null) transactionSummary.setAttribute("requestId", strRequestId);

    response.addContent(transactionSummary);

    if (totalInserted > 0) {
      Element insertResult = new Element("InsertResult", Csw.NAMESPACE_CSW);
      insertResult.setAttribute("handleRef", "handleRefValue");

      // Namespace NAMESPACE_DC = Namespace.getNamespace("dc", "http://purl.org/dc/elements/1.1/");
      for (String fileId : fileIds) {
        Element briefRecord = new Element("BriefRecord", Csw.NAMESPACE_CSW);
        Element identifier = new Element("identifier"); // ,Csw.NAMESPACE_DC );
        identifier.setText(fileId);
        briefRecord.addContent(identifier);
        insertResult.addContent(briefRecord);
      }

      response.addContent(insertResult);
    }
  }
 public String createTable() {
   Element root = new Element("table");
   root.setAttribute("border", "0");
   Document doc = new Document(root);
   Element thead = new Element("thead");
   Element th = new Element("th");
   th.addContent("A header");
   th.setAttribute("class", "aka_header_border");
   thead.addContent(th);
   Element th2 = new Element("th");
   th2.addContent("Another header");
   th2.setAttribute("class", "aka_header_border");
   thead.addContent(th2);
   root.addContent(thead);
   Element tr1 = new Element("tr");
   Element td1 = new Element("td");
   td1.setAttribute("valign", "top");
   td1.setAttribute("class", "cellBorders");
   td1.setText("cell contents");
   tr1.addContent(td1);
   root.addContent(tr1);
   XMLOutputter outp = new XMLOutputter();
   Format format = Format.getPrettyFormat();
   format.setOmitDeclaration(true);
   outp.setFormat(format);
   Writer writer = new StringWriter();
   try {
     outp.output(doc, writer);
   } catch (IOException e) {
     e
         .printStackTrace(); // To change body of catch statement use File | Settings | File
                             // Templates.
   }
   return writer.toString();
 }
  /**
   * Transforms a list of KeywordBean object into its iso19139 representation.
   *
   * <pre>
   *  <gmd:MD_Keywords>
   *  	<gmd:keyword>
   *  		<gco:CharacterString>Keyword 1</gco:CharacterString>
   *  	</gmd:keyword>
   * 		<gmd:keyword>
   *  		<gco:CharacterString>Keyword 2</gco:CharacterString>
   *  	</gmd:keyword>
   *  	<gmd:type>
   *  		<gmd:MD_KeywordTypeCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#MD_KeywordTypeCode" codeListValue="TYPE"/>
   *  	</gmd:type>
   *  	<gmd:thesaurusName>
   *  		<gmd:CI_Citation id="geonetwork.thesaurus.register.theme.bc44a748-f1a1-4775-9395-a4a6d8bb8df6">
   *  			<gmd:title>
   *  				<gco:CharacterString>THESAURUS NAME</gco:CharacterString>
   *  			</gmd:title>
   *  			<gmd:date gco:nilReason="unknown"/>
   * 			<gmd:otherCitationDetails>
   * 				<gmx:FileName src="http://localhost:8080/geonetwork/srv/eng/metadata.show?uuid=bc44a748-f1a1-4775-9395-a4a6d8bb8df6">register.theme.bc44a748-f1a1-4775-9395-a4a6d8bb8df6</gmx:FileName>
   * 			</gmd:otherCitationDetails>
   *  		</gmd:CI_Citation>
   *  	</gmd:thesaurusName>
   *  </gmd:MD_Keywords>
   *  </pre>
   *
   * @param kbList
   * @return a complex iso19139 representation of the keyword
   */
  public static Element getComplexIso19139Elt(List<KeywordBean> kbList) {
    Element root = new Element("MD_Keywords", NS_GMD);

    Element cs = new Element("CharacterString", NS_GCO);

    List<Element> keywords = new ArrayList<Element>();

    String thName = "";
    Element type = null;
    Element thesaurusName = null;

    for (KeywordBean kb : kbList) {
      Element keyword = new Element("keyword", NS_GMD);

      cs.setText(kb.getValue());
      keyword.addContent((Content) cs.clone());
      keywords.add((Element) keyword.detach());
      thName = kb.getThesaurus();
      if (type == null) type = KeywordBean.createKeywordTypeElt(kb);
      if (thesaurusName == null) thesaurusName = KeywordBean.createThesaurusNameElt(kb);
    }

    // Add elements to the root MD_Keywords element.
    root.addContent(keywords);
    root.addContent(type);
    root.addContent(thesaurusName);

    return root;
  }
  protected void sendError(String message, HttpServletResponse response) throws IOException {

    Element root = new Element("error");
    Document doc = new Document(root);
    root.setText(message);
    sendDocument(doc, response);
  }
Example #23
0
 public static void tagWithAttributeAndText(
     Element container, String tagName, String attrName, String attrValue, String text) {
   Element child = new Element(tagName);
   child.setAttribute(attrName, attrValue);
   child.setText(text);
   container.addContent(child);
 }
 /** Establece el sub-elemento Source */
 private void setSource() {
   Element eAux;
   eAux = new Element("Source");
   // eAux.setAttribute("Type","pcap o xml");
   eAux.setText(getPBExport().getExpSource());
   addContent(eAux);
 }
Example #25
0
 /**
  * createNewObjective() - Creates a new <objective> element structure in the xml CMI datamodel for
  * a particular sco.
  *
  * @param index - the index for the <objective> to be created
  */
 private void createNewObjective(final int index) {
   // first get hold of the <objectives> node
   final Element objs = getElement(getDocument().getRootElement(), "cmi.objectives");
   // and then add our <objective index=""> node
   final Element objective = new Element("objective");
   objective.setAttribute("index", index + "");
   objs.addContent(objective);
   // add <id>
   final Element id = new Element("id");
   objective.addContent(id);
   // add <score>
   final Element score = new Element("score");
   objective.addContent(score);
   // add <_children>
   final Element _children = new Element("_children");
   _children.setText("raw,max,min");
   score.addContent(_children);
   // add <raw>
   final Element raw = new Element("raw");
   score.addContent(raw);
   // add <max>
   final Element max = new Element("max");
   score.addContent(max);
   // add <min>
   final Element min = new Element("min");
   score.addContent(min);
   // add <status>
   final Element status = new Element("status");
   objective.addContent(status);
 }
 private void addPermittedPaths(final Element field, final PathPermissions p) {
   for (String path : p.getPositiveRules()) {
     Element value = new Element(VALUE);
     value.setText(path);
     field.addContent(value);
   }
 }
 /**
  * The "default" is the highest priority and will receive the private messages. Negative priority
  * is a preference that the sender should not be used for direct or immediate contact. It must be
  * an integer value between -127 to +127. A 0 value is the default.
  */
 public void setPriority(int priority) {
   this.priority = priority;
   getDOM().removeChild("priority", XMLNS_PRESENCE);
   Element temp = new Element("priority", XMLNS_PRESENCE);
   temp.setText("" + priority);
   getDOM().addContent(temp);
 }
Example #28
0
  /**
   * Adds a localised character string to an element.
   *
   * @param md metadata record
   * @param ref current ref of element. All _lang_AB_123 element will be processed.
   * @param val
   * @return
   */
  protected static boolean updatedLocalizedTextElement(
      Element md, String ref, String val, EditLib editLib) {
    if (ref.startsWith("lang")) {
      if (val.length() > 0) {
        String[] ids = ref.split("_");
        // --- search element in current metadata record
        Element parent = editLib.findElement(md, ids[2]);

        // --- add required attribute
        parent.setAttribute(
            "type",
            "gmd:PT_FreeText_PropertyType",
            Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"));

        // --- add new translation
        Namespace gmd = Namespace.getNamespace("gmd", "http://www.isotc211.org/2005/gmd");
        Element langElem = new Element("LocalisedCharacterString", gmd);
        langElem.setAttribute("locale", "#" + ids[1]);
        langElem.setText(val);

        Element freeText = getOrAdd(parent, "PT_FreeText", gmd);

        Element textGroup = new Element("textGroup", gmd);
        freeText.addContent(textGroup);
        textGroup.addContent(langElem);
        Element refElem = new Element(Edit.RootChild.ELEMENT, Edit.NAMESPACE);
        refElem.setAttribute(Edit.Element.Attr.REF, "");
        textGroup.addContent(refElem);
        langElem.addContent((Element) refElem.clone());
      }
      return true;
    }
    return false;
  }
Example #29
0
	/**
	 *  普通版填写包的公共部分
	 * @param root	开始节点
	 * @param map	参数map
	 * @param sCycName	循环节点名
	 * @return
	 */
	public Element writeptPublicNode(Element root,HashMap map,String sCycName)
	{
		Element node=null;
		try
		{
			String sName="";
			String sValue="";
			List list=root.getChildren();
			for(int i=0;i<list.size();i++)
			{
				node=(Element)list.get(i);
				sName=node.getName();
				sName=sName.trim();
				sValue=(String)map.get(sName);
				//System.err.println("sName:"+sName+":"+sValue);
				if(sCycName.equals(sName)&&(root.getName()).trim().equals("ReqParamSet"))
				{
					//System.err.println("find cyc node:"+sName );
					return node;
				}
				else if(sValue!=null && !"".equals(sValue) )
					node.setText(sValue);
				node=writeptPublicNode(node,map,sCycName);
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
			System.err.println("error:"+ex.getMessage());
		}
		return node;
	}
  /**
   * Update the map-elements in the datasource that are below <i>parent</i>.
   *
   * @param parent Parent element to add / update
   * @param configuration configuration that holds the properties
   * @param mapName the name of the map-property in the configuration that holds the elements
   * @param propertyElementName the name of the element to write below <i>parent</i>
   */
  private static void updateMap(
      Element parent, Configuration configuration, String mapName, String propertyElementName) {
    PropertyMap map = configuration.getMap(mapName);
    // Wrap in ArrayList to avoid ConcurrentModificationException when adding or removing children
    // while iterating.
    List<Element> mapElements = new ArrayList<Element>(parent.getChildren(propertyElementName));

    if ((map == null) || map.getMap().isEmpty()) {
      if (!mapElements.isEmpty()) {
        parent.removeChildren(propertyElementName);
      }

      return;
    }

    Map<String, Element> elements = new HashMap<String, Element>();
    for (Element el : mapElements) {
      elements.put(el.getAttributeValue("name"), el);
      if (map.get(el.getAttributeValue("name")) == null) {
        parent.removeContent(el);
      }
    }

    for (Property prop : map.getMap().values()) {
      Element element = elements.get(prop.getName());
      if (element == null) {
        element = new Element(propertyElementName);
        element.setAttribute("name", prop.getName());
        parent.addContent(element);
      }

      element.setText(((PropertySimple) prop).getStringValue());
    }
  }