private void checkNcname(DefinitionsChildId id, String ncname) { if (!ncname.trim().equals(ncname)) { printAndAddError(id, "local name starts or ends with white spaces"); } if (ncname.toLowerCase().contains(ARTEFACT_BE)) { printAndAddError(id, "artifact is spelled with i in American English, not artefact as in British English"); } }
private void validate(RepositoryFileReference xmlSchemaFileReference, @Nullable Object any, DefinitionsChildId id) { if (!(any instanceof Element)) { printAndAddError(id, "any is not instance of Document, but " + any.getClass()); return; } Element element = (Element) any; SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try (InputStream inputStream = configuration.getRepository().newInputStream(xmlSchemaFileReference)) { Source schemaFile = new StreamSource(inputStream); Schema schema = factory.newSchema(schemaFile); Validator validator = schema.newValidator(); validator.validate(new DOMSource(element)); } catch (Exception e) { printAndAddError(id, "error during validating XML schema " + e.getMessage()); } }
} catch (IOException e) { LOGGER.debug("Error during checking ZIP", e); printAndAddError(id, "I/O error: " + e.getMessage()); return; } catch (RepositoryCorruptException e) { LOGGER.debug("Repository is corrupt", e); printAndAddError(id, "Corrupt: " + e.getMessage()); return; } catch (Exception e) { LOGGER.debug("Inner error at writing to temporary CSAR file", e); printAndAddError(id, e.toString()); return; final String error = "Could not write to temp CSAR file"; LOGGER.debug(error, e); printAndAddError(id, error); return; while ((entry = zis.getNextEntry()) != null) { if (entry.getName() == null) { printAndAddError(id, "Empty filename in zip file"); final String error = "Could not read from temp CSAR file"; LOGGER.debug(error, e); printAndAddError(id, error); return;
private void checkXmlSchemaValidation(DefinitionsChildId id) { RepositoryFileReference refOfDefinitions = BackendUtils.getRefOfDefinitions(id); if (!configuration.getRepository().exists(refOfDefinitions)) { printAndAddError(id, "Id exists, but corresponding XML file does not."); return; } try (InputStream inputStream = configuration.getRepository().newInputStream(refOfDefinitions)) { DocumentBuilder documentBuilder = ToscaDocumentBuilderFactory.INSTANCE.getSchemaAwareToscaDocumentBuilder(); StringBuilder errorStringBuilder = new StringBuilder(); documentBuilder.setErrorHandler(BackendUtils.getErrorHandler(errorStringBuilder)); documentBuilder.parse(inputStream); String errors = errorStringBuilder.toString(); if (!errors.isEmpty()) { printAndAddError(id, errors); } } catch (IOException e) { LOGGER.debug("I/O error", e); printAndAddError(id, "I/O error during XML validation " + e.getMessage()); } catch (SAXException e) { LOGGER.debug("SAX exception", e); printAndAddError(id, "SAX error during XML validation: " + e.getMessage()); } }
/** * Checks all references QNames whether they are valid */ private void checkReferencedQNames(DefinitionsChildId id) { final QNameValidator qNameValidator = new QNameValidator(error -> printAndAddError(id, error)); try { configuration.getRepository().getDefinitions(id).getElement().accept(qNameValidator); } catch (IllegalStateException e) { LOGGER.debug("Illegal State Exception during reading of id {}", id.toReadableString(), e); printAndAddError(id, "Reading error " + e.getMessage()); } }
printAndAddError(id, "Namespace starts or ends with white spaces"); } catch (URISyntaxException e) { LOGGER.debug("Invalid URI", e); printAndAddError(id, "Invalid URI: " + e.getMessage()); return; printAndAddError(id, "URI is relative"); String uriStrWithoutLastElement = uriStr.substring(0, (uriStr.length() - lastElement.length())); if (!(id.getXmlId().toString().startsWith(lastElement)) || (!uriStrWithoutLastElement.toLowerCase().equals(uriStrWithoutLastElement))) { printAndAddError(id, "opentosca URI is not lowercase"); printAndAddError(id, "URI ends with a slash"); printAndAddError(id, "artifact is spelled with i in American English, not artefact as in British English"); printAndAddError(id, "Namespace URI contains tosca definitions name from other type. E.g., Namespace is ...servicetemplates..., but the type is an artifact template");
} catch (IllegalStateException e) { LOGGER.debug("Illegal State Exception during reading of id {}", id.toReadableString(), e); printAndAddError(id, "Reading error " + e.getMessage()); return; } catch (ClassCastException e) { LOGGER.error("Something wrong in the consistency between Ids and the TOSCA data model. See http://eclipse.github.io/winery/dev/id-system.html for more information on the ID system."); printAndAddError(id, "Critical error at analysis: " + e.getMessage()); return; } catch (IllegalStateException e) { LOGGER.debug("Illegal State Exception during getting type for template {}", entityTemplate.getId(), e); printAndAddError(id, "Reading error " + e.getMessage()); return; final TEntityTemplate.Properties properties = entityTemplate.getProperties(); if (properties == null) { printAndAddError(id, "Properties required, but no properties defined"); return; Map<String, String> kvProperties = entityTemplate.getProperties().getKVProperties(); if (kvProperties.isEmpty()) { printAndAddError(id, "Properties required, but no properties set (any case)"); return; String key = propertyDefinitionKV.getKey(); if (kvProperties.get(key) == null) { printAndAddError(id, "Property " + key + " required, but not set."); } else {
} catch (IllegalStateException e) { LOGGER.debug("Illegal State Exception during reading of id {}", id.toReadableString(), e); printAndAddError(id, "Reading error " + e.getMessage()); return; } catch (IllegalStateException e) { LOGGER.debug("Illegal State Exception during reading of id {}", nodeTypeId.toReadableString(), e); printAndAddError(nodeTypeId, "Reading error " + e.getMessage()); return; String key = propdef.getKey(); if (key == null) { printAndAddError(id, "key is null"); continue; printAndAddError(id, "propertiesKV of node template " + nodeTemplate.getId() + " is null");
/** * Checks whether the given filename exists within the given defintions child id and if the size is above a threshold (currently 100 bytes) */ private void checkFileExistenceAndSize(DefinitionsChildId id, String filename) { RepositoryFileReference repositoryFileReference = new RepositoryFileReference(id, filename); if (!configuration.getRepository().exists(repositoryFileReference)) { printAndAddWarning(id, filename + " does not exist."); return; } long size; try { size = configuration.getRepository().getSize(repositoryFileReference); } catch (IOException e) { LOGGER.debug("Could not determine size for {}", id.toReadableString(), e); printAndAddError(id, "Could not determine size, because " + e.toString()); return; } if (size < 100) { printAndAddWarning(id, filename + " has size of less then 100 bytes."); } }