Ejemplo n.º 1
0
  protected void validate(Document document) throws Exception {
    XPath xPathSelector = _saxReader.createXPath("//dynamic-element");

    List<Node> nodes = xPathSelector.selectNodes(document);

    Set<String> elementNames = new HashSet<>();

    for (Node node : nodes) {
      Element element = (Element) node;

      String name = StringUtil.toLowerCase(element.attributeValue("name"));

      if (Validator.isNull(name)) {
        throw new StructureDefinitionException(
            "Element must have a name attribute " + element.formattedString());
      }

      if (name.startsWith(DDMStructureConstants.XSD_NAME_RESERVED)) {
        throw new StructureDefinitionException("Element name " + name + " is reserved");
      }

      if (elementNames.contains(name)) {
        throw new StructureDuplicateElementException(
            "Element with name " + name + " already exists");
      }

      elementNames.add(name);
    }
  }
Ejemplo n.º 2
0
  private void _updateJavadocsXmlFile(
      String fileName, JavaClass javaClass, Document javaClassDocument) throws Exception {

    String javaClassFullyQualifiedName = javaClass.getFullyQualifiedName();

    /*if (!javaClassFullyQualifiedName.contains(".service.") ||
    	!javaClassFullyQualifiedName.endsWith("ServiceImpl")) {

    	return;
    }*/

    Tuple javadocsXmlTuple = _getJavadocsXmlTuple(fileName);

    if (javadocsXmlTuple == null) {
      return;
    }

    Document javadocsXmlDocument = (Document) javadocsXmlTuple.getObject(3);

    Element javadocsXmlRootElement = javadocsXmlDocument.getRootElement();

    List<Element> javadocElements = javadocsXmlRootElement.elements("javadoc");

    for (Element javadocElement : javadocElements) {
      String type = javadocElement.elementText("type");

      if (type.equals(javaClassFullyQualifiedName)) {
        Element javaClassRootElement = javaClassDocument.getRootElement();

        if (Validator.equals(
            javadocElement.formattedString(), javaClassRootElement.formattedString())) {

          return;
        }

        javadocElement.detach();

        break;
      }
    }

    javadocsXmlRootElement.add(javaClassDocument.getRootElement());
  }
Ejemplo n.º 3
0
  private String _mergeXsds(String xsd1, String xsd2) throws SystemException {
    try {
      Document document1 = SAXReaderUtil.read(xsd1);
      Document document2 = SAXReaderUtil.read(xsd2);

      Element rootElement1 = document1.getRootElement();
      Element rootElement2 = document2.getRootElement();

      for (Element element : rootElement1.elements()) {
        rootElement1.remove(element);

        rootElement2.add(element);
      }

      return rootElement2.formattedString();
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }