List of usage examples for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI
String W3C_XML_SCHEMA_NS_URI
To view the source code for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI.
Click Source Link
From source file:org.artifactory.version.ConfigXmlConversionTest.java
private CentralConfigDescriptor getConfigValid(String configXml) throws Exception { JAXBContext context = JAXBContext.newInstance(CentralConfigDescriptorImpl.class); Unmarshaller unmarshaller = context.createUnmarshaller(); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); URL xsdUrl = getClass().getResource("/artifactory.xsd"); Schema schema = sf.newSchema(xsdUrl); unmarshaller.setSchema(schema);/* w w w. ja v a2s . c om*/ return (CentralConfigDescriptor) unmarshaller.unmarshal(new StringReader(configXml)); }
From source file:org.betaconceptframework.astroboa.configuration.RepositoryRegistry.java
private Schema loadXmlSchema() throws Exception { SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setResourceResolver(new W3CRelatedSchemaEntityResolver()); //Search in classpath at root level URL configurationSchemaURL = this.getClass().getResource(ASTROBOA_CONFIGURATION_XSD_FILEPATH); if (configurationSchemaURL == null) { throw new Exception("Could not find " + ASTROBOA_CONFIGURATION_XSD_FILEPATH + " in classpath"); }/*from ww w . ja v a2 s. c o m*/ return schemaFactory.newSchema(configurationSchemaURL); }
From source file:org.betaconceptframework.astroboa.engine.definition.visitor.CmsDefinitionVisitor.java
public void schema(XSSchema schema) { // Do not process schema of XML Schema!!! if (!XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) { //Collect all attributeGroups if (MapUtils.isNotEmpty(schema.getAttGroupDecls())) attributeGroupDeclarations.putAll(schema.getAttGroupDecls()); //Collect all elements if (MapUtils.isNotEmpty(schema.getElementDecls())) elementDeclarations.putAll(schema.getElementDecls()); //Collect all complexTypes if (MapUtils.isNotEmpty(schema.getComplexTypes())) complexTypeDeclarations.putAll(schema.getComplexTypes()); }//from w w w. j ava 2 s.co m }
From source file:org.betaconceptframework.astroboa.engine.definition.visitor.CmsPropertyVisitor.java
private void loadRestrictionFacets(XSRestrictionSimpleType restriction) { if (StringUtils.equals(restriction.getName(), XSSchemaItem.Language.getLocalPart()) && StringUtils.equals(restriction.getTargetNamespace(), XSSchemaItem.Language.getNamespaceURI())) { /*/* ww w . ja v a2 s .com*/ * XSOM library uses file xsom-20110809.jar/com.sun.xml.xsom.impl.parser.datatypes.xsd, * which contains a list of built in datatypes defined by XML Schema, * when information about one or more of these types is required. * * Unfortunately, it contains wrong information * about the pattern of the 'language' simple type. In this file, 'language' * simple type is defined as * <xs:simpleType name="language" > <xs:restriction base="xs:token"> <xs:pattern value="([a-zA-Z]{2}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]{1,8})(-[a-zA-Z]{1,8})*" > <xs:annotation> <xs:documentation source="http://www.w3.org/TR/REC-xml#NT-LanguageID"> pattern specifies the content of section 2.12 of XML 1.0e2 and RFC 1766 </xs:documentation> </xs:annotation> </xs:pattern> </xs:restriction> </xs:simpleType> * where as in http://www.w3.org/2001/XMLSchema.xsd (The XML Schema for the ... XML Schema) * 'language' type is defined as <xs:simpleType name="language" id="language"> <xs:annotation> <xs:documentation source="http://www.w3.org/TR/xmlschema-2/#language"/> </xs:annotation> <xs:restriction base="xs:token"> <xs:pattern value="[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*" id="language.pattern"> <xs:annotation> <xs:documentation source="http://www.ietf.org/rfc/rfc3066.txt"> pattern specifies the content of section 2.12 of XML 1.0e2 and RFC 3066 (Revised version of RFC 1766). </xs:documentation> </xs:annotation> </xs:pattern> </xs:restriction> </xs:simpleType> Every time we ask XSOM about the pattern of the 'language' type, it is returning the one provided in the datatypes.xsd file and not the valid value provided by the XML Schema's xsd. Therefore we have defined the constant CmsConstants.XML_SCHEMA_LANGUAGE_TYPE_REG_EXP which contains the true value of the pattern and use this instead. Thus, in the context of this method, if the restriction whose facets we want to load is the 'language' type restriction, there is no point in processing its facets at all. We know apriori that there is only one facet with a known pattern. */ return; } Collection<? extends XSFacet> facets = restriction.getDeclaredFacets(); for (XSFacet facet : facets) { if (XSFacet.FACET_ENUMERATION.equals(facet.getName())) { Localization localization = new LocalizationImpl(); XSAnnotation annotation = facet.getAnnotation(); if (annotation != null && annotation.getAnnotation() != null && annotation.getAnnotation() instanceof CmsAnnotation) { CmsAnnotation cmsAnnotation = (CmsAnnotation) annotation.getAnnotation(); if (cmsAnnotation.getDisplayName() != null) { //We are only interested for the displayName of the value localization = cmsAnnotation.getDisplayName(); } } else { logger.warn("Found no localization for enumeration entry {} for element {}", facet.getValue().value, name); } definitionValueRange.put(facet.getValue().value, localization); } else if (XSFacet.FACET_MAXEXCLUSIVE.equals(facet.getName())) { maxValueIsExclusive = true; if (valueType == ValueType.Long) { maxValue = retrieveLongValue(facet.getValue().value); } else if (valueType == ValueType.Double) { maxValue = retrieveDoubleValue(facet.getValue().value); } else { logger.warn("Found maxExclusive restriction entry {} for non double and non long element {}", facet.getValue().value, name); } } else if (XSFacet.FACET_MAXINCLUSIVE.equals(facet.getName())) { maxValueIsExclusive = false; if (valueType == ValueType.Long) { maxValue = retrieveLongValue(facet.getValue().value); } else if (valueType == ValueType.Double) { maxValue = retrieveDoubleValue(facet.getValue().value); } else { logger.warn("Found maxExclusive restriction entry {} for non double and non long element {}", facet.getValue().value, name); } } else if (XSFacet.FACET_MINEXCLUSIVE.equals(facet.getName())) { minValueIsExclusive = true; if (valueType == ValueType.Long) { minValue = retrieveLongValue(facet.getValue().value); } else if (valueType == ValueType.Double) { minValue = retrieveDoubleValue(facet.getValue().value); } else { logger.warn("Found maxExclusive restriction entry {} for non double and non long element {}", facet.getValue().value, name); } } else if (XSFacet.FACET_MININCLUSIVE.equals(facet.getName())) { minValueIsExclusive = false; if (valueType == ValueType.Long) { minValue = retrieveLongValue(facet.getValue().value); } else if (valueType == ValueType.Double) { minValue = retrieveDoubleValue(facet.getValue().value); } else { logger.warn("Found maxExclusive restriction entry {} for non double and non long element {}", facet.getValue().value, name); } } else if (XSFacet.FACET_MINLENGTH.equals(facet.getName())) { if (valueType == ValueType.String) { minLength = retrieveIntegerValue(facet.getValue().value); } else { logger.warn("Found minLength restriction entry {} for non string element {}", facet.getValue().value, name); } } else if (XSFacet.FACET_MAXLENGTH.equals(facet.getName())) { if (valueType == ValueType.String) { maxLength = retrieveIntegerValue(facet.getValue().value); } else { logger.warn("Found maxLength restriction entry {} for non string element {}", facet.getValue().value, name); } } else if (XSFacet.FACET_LENGTH.equals(facet.getName())) { if (valueType == ValueType.String) { minLength = retrieveIntegerValue(facet.getValue().value); maxLength = minLength; } else { logger.warn("Found length restriction entry {} for non string element {}", facet.getValue().value, name); } } else if (XSFacet.FACET_PATTERN.equals(facet.getName())) { if (valueType == ValueType.String) { pattern = facet.getValue().value; if (StringUtils.isBlank(pattern)) { pattern = null; logger.warn("Found blank pattern for string element {}", name); } } else { logger.warn("Found pattern restriction entry {} for non string element {}", facet.getValue().value, name); } } } //Continue if restriction extends another restriction //CAUTION : In case parent restriction has facets other than Enumeration //then these facets will override equivalent facets of this type //This code must be reviewed XSType baseType = restriction.getBaseType(); if (baseType.isSimpleType() && !baseType.asSimpleType().isPrimitive() && baseType.asSimpleType().isRestriction() && !StringUtils.equals(baseType.getTargetNamespace(), XMLConstants.W3C_XML_SCHEMA_NS_URI)) { loadRestrictionFacets(baseType.asSimpleType().asRestriction()); } }
From source file:org.betaconceptframework.astroboa.engine.definition.visitor.CmsPropertyVisitor.java
private void determineValueTypeForSimpleType(String componentName, XSType simpleType) { ItemQName typeItemQName = null;/*from w w w .ja v a 2 s . c om*/ String typeName = simpleType.getName(); String typeNamespace = simpleType.getTargetNamespace(); //Check if simple type is primitive if (!simpleType.asSimpleType().isPrimitive()) { //Check if element is a restriction if (simpleType.asSimpleType().isRestriction() && !StringUtils.equals(typeNamespace, XMLConstants.W3C_XML_SCHEMA_NS_URI)) { XSRestrictionSimpleType restriction = simpleType.asSimpleType().asRestriction(); XSType baseType = retrieveBaseTypeFromRestriction(restriction); typeName = baseType.getName(); typeNamespace = baseType.getTargetNamespace(); } else if (simpleType.asSimpleType().isUnion()) { XSUnionSimpleType union = simpleType.asSimpleType().asUnion(); //All members must have the same type. //Union with members of different types is not supported ItemQName unionCommonType = getUnionMemberCommonType(union); if (unionCommonType == null) { throw new CmsException("Component " + componentName + " Target namespace " + simpleType.getTargetNamespace() + " is a union of " + union.getMemberSize() + " simple types which are not of the same base type. Unions whose members are not of the same base type are not supported"); } typeName = unionCommonType.getLocalPart(); typeNamespace = unionCommonType.getNamespaceURI(); } } if (typeName == null) { throw new CmsException("Unknown simple type for component " + componentName + " Target namespace " + simpleType.getTargetNamespace()); } typeItemQName = ItemUtils.createNewItem("", typeNamespace, typeName); //Check what kind of type this element is if (typeItemQName.equals(XSSchemaItem.String) || typeItemQName.equals(XSSchemaItem.NormalizedString) || typeItemQName.equals(XSSchemaItem.AnyURI)) { valueType = ValueType.String; if (StringUtils.equals(simpleType.getName(), CmsDefinitionItem.passwordType.getLocalPart())) { passwordType = true; } } else if (typeItemQName.equals(XSSchemaItem.Double) || typeItemQName.equals(XSSchemaItem.Float) || typeItemQName.equals(XSSchemaItem.Decimal)) { valueType = ValueType.Double; } else if (typeItemQName.equals(XSSchemaItem.Long) || typeItemQName.equals(XSSchemaItem.Integer) || typeItemQName.equals(XSSchemaItem.NonPositiveInteger) || typeItemQName.equals(XSSchemaItem.NonNegativeInteger) || typeItemQName.equals(XSSchemaItem.NegativeInteger) || typeItemQName.equals(XSSchemaItem.Int) || typeItemQName.equals(XSSchemaItem.PositiveInteger) || typeItemQName.equals(XSSchemaItem.UnsignedLong) || typeItemQName.equals(XSSchemaItem.Short) || typeItemQName.equals(XSSchemaItem.UnsignedInt) || typeItemQName.equals(XSSchemaItem.Byte) || typeItemQName.equals(XSSchemaItem.UnsignedByte)) { valueType = ValueType.Long; } else if (typeItemQName.equals(XSSchemaItem.GYear)) { valueType = ValueType.String; pattern = CmsConstants.GYEAR_REG_EXP; } else if (typeItemQName.equals(XSSchemaItem.GMonth)) { valueType = ValueType.String; pattern = CmsConstants.GMONTH_REG_EXP; } else if (typeItemQName.equals(XSSchemaItem.GYearMonth)) { valueType = ValueType.String; pattern = CmsConstants.GYEAR_MONTH_REG_EXP; } else if (typeItemQName.equals(XSSchemaItem.GDay)) { valueType = ValueType.String; pattern = CmsConstants.GDAY_REG_EXP; } else if (typeItemQName.equals(XSSchemaItem.GMonthDay)) { valueType = ValueType.String; pattern = CmsConstants.GMONTH_DAY_REG_EXP; } else if (typeItemQName.equals(XSSchemaItem.Boolean)) { valueType = ValueType.Boolean; } else if (typeItemQName.equals(XSSchemaItem.DateTime)) { valueType = ValueType.Date; calendarPattern = CmsConstants.DATE_TIME_PATTERN; } else if (typeItemQName.equals(XSSchemaItem.Date)) { valueType = ValueType.Date; calendarPattern = CmsConstants.DATE_PATTERN; } else if (typeItemQName.equals(XSSchemaItem.Language)) { valueType = ValueType.String; pattern = CmsConstants.XML_SCHEMA_LANGUAGE_TYPE_REG_EXP; } else throw new CmsException( "Unknown type for component(element or attribute) " + componentName + ". Type details: " + " Target namespace " + simpleType.getTargetNamespace() + " and name " + typeName); }
From source file:org.betaconceptframework.astroboa.engine.definition.visitor.CmsPropertyVisitor.java
private XSType retrieveBaseTypeFromRestriction(XSRestrictionSimpleType restriction) { XSType baseType = restriction.getBaseType(); if (baseType.isSimpleType() && !baseType.asSimpleType().isPrimitive() && baseType.asSimpleType().isRestriction() && !StringUtils.equals(baseType.getTargetNamespace(), XMLConstants.W3C_XML_SCHEMA_NS_URI)) { return retrieveBaseTypeFromRestriction(baseType.asSimpleType().asRestriction()); }/*w w w. j a v a 2s. c o m*/ return baseType; }
From source file:org.betaconceptframework.astroboa.engine.jcr.io.contenthandler.ImportContentHandler.java
private void importAttributes(Attributes atts) throws SAXException { if (atts != null && atts.getLength() > 0) { for (int i = 0; i < atts.getLength(); i++) { //Ignore attributes with specific namespaces String uri = atts.getURI(i); if (StringUtils.equals(uri, XMLConstants.XMLNS_ATTRIBUTE_NS_URI) || StringUtils.equals(uri, XMLConstants.XML_NS_URI) || StringUtils.equals(uri, XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI) || StringUtils.equals(uri, XMLConstants.W3C_XML_SCHEMA_NS_URI) || StringUtils.equals(uri, XMLConstants.W3C_XPATH_DATATYPE_NS_URI)) { continue; }//from w w w .ja v a 2s . c om addAttributeToImportedEntity(atts.getLocalName(i), atts.getValue(i)); } } }
From source file:org.bibsonomy.rest.renderer.impl.JAXBRenderer.java
protected JAXBRenderer(final UrlRenderer urlRenderer) { final RestProperties properties = RestProperties.getInstance(); this.urlRenderer = urlRenderer; try {//from www . j a v a 2 s . c o m this.datatypeFactory = DatatypeFactory.newInstance(); } catch (final DatatypeConfigurationException ex) { throw new RuntimeException("Could not instantiate data type factory.", ex); } this.validateXMLInput = "true".equals(properties.get(VALIDATE_XML_INPUT)); this.validateXMLOutput = "true".equals(properties.get(VALIDATE_XML_OUTPUT)); ModelFactory.getInstance().setModelValidator(properties.getModelValidator()); // we only need to load the XML schema if we validate input or output if (this.validateXMLInput || this.validateXMLOutput) { try { schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(this.getClass().getClassLoader().getResource("xschema.xsd")); } catch (final Exception e) { log.error("Failed to load XML schema", e); schema = null; } } else { schema = null; } }
From source file:org.bonitasoft.engine.io.IOUtil.java
public static byte[] marshallObjectToXML(final Object jaxbModel, final URL schemaURL) throws JAXBException, IOException, SAXException { if (jaxbModel == null) { return null; }/*from w ww .j a va2 s. co m*/ if (schemaURL == null) { throw new IllegalArgumentException("schemaURL is null"); } final SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = sf.newSchema(schemaURL); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { final JAXBContext contextObj = JAXBContext.newInstance(jaxbModel.getClass()); final Marshaller m = contextObj.createMarshaller(); m.setSchema(schema); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(jaxbModel, baos); return baos.toByteArray(); } }
From source file:org.bonitasoft.engine.io.IOUtil.java
public static <T> T unmarshallXMLtoObject(final byte[] xmlObject, final Class<T> objectClass, final URL schemaURL) throws JAXBException, IOException, SAXException { if (xmlObject == null) { return null; }//from w w w .j a v a2 s.c om if (schemaURL == null) { throw new IllegalArgumentException("schemaURL is null"); } final SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = sf.newSchema(schemaURL); final JAXBContext contextObj = JAXBContext.newInstance(objectClass); final Unmarshaller um = contextObj.createUnmarshaller(); um.setSchema(schema); try (ByteArrayInputStream bais = new ByteArrayInputStream(xmlObject)) { final StreamSource ss = new StreamSource(bais); final JAXBElement<T> jaxbElement = um.unmarshal(ss, objectClass); return jaxbElement.getValue(); } }