Example usage for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI

List of usage examples for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI

Introduction

In this page you can find the example usage for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI.

Prototype

String W3C_XML_SCHEMA_NS_URI

To view the source code for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI.

Click Source Link

Document

W3C XML Schema Namespace URI.

Usage

From source file:com.consol.citrus.samples.bookstore.validation.XmlSchemaValidatingChannelInterceptor.java

/**
 * Constructor.//from   w  w w. j a  v  a 2s . c  om
 * 
 * @param schemaResource
 * @param schemaLanguage
 * @throws IOException
 */
public XmlSchemaValidatingChannelInterceptor(Resource schemaResource, String schemaLanguage)
        throws IOException {
    if (schemaLanguage.equals("xml-schema")) {
        this.xmlValidator = XmlValidatorFactory.createValidator(schemaResource,
                XMLConstants.W3C_XML_SCHEMA_NS_URI);
    } else {
        this.xmlValidator = XmlValidatorFactory.createValidator(schemaResource, XMLConstants.RELAXNG_NS_URI);
    }
}

From source file:com.amalto.core.storage.hibernate.FlatTypeMappingCreator.java

@Override
public TypeMapping visit(ReferenceFieldMetadata referenceField) {
    String name = context.getFieldColumn(referenceField);
    String typeName = referenceField.getReferencedType().getName().replace('-', '_');
    ComplexTypeMetadata referencedType = new SoftTypeRef(internalRepository,
            referenceField.getReferencedType().getNamespace(), typeName, true);
    FieldMetadata referencedField = new SoftIdFieldRef(internalRepository, typeName);

    TypeMetadata declaringType = referenceField.getDeclaringType();
    ComplexTypeMetadata database = typeMapping.getDatabase();
    ReferenceFieldMetadata newFlattenField = new ReferenceFieldMetadata(database, referenceField.isKey(),
            referenceField.isMany(), isDatabaseMandatory(referenceField, declaringType), name, referencedType,
            referencedField, Collections.<FieldMetadata>emptyList(), referenceField.getForeignKeyInfoFormat(),
            referenceField.isFKIntegrity(), referenceField.allowFKIntegrityOverride(),
            new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI, Types.STRING),
            referenceField.getWriteUsers(), referenceField.getHideUsers(),
            referenceField.getWorkflowAccessRights(), StringUtils.EMPTY, StringUtils.EMPTY);
    if (!referenceField.getContainingType().equals(declaringType)) {
        String declaringTypeName = declaringType.isInstantiable() ? declaringType.getName()
                : "X_" + declaringType.getName(); //$NON-NLS-1$
        SoftTypeRef internalDeclaringType = new SoftTypeRef(internalRepository, declaringType.getNamespace(),
                declaringTypeName, declaringType.isInstantiable());
        newFlattenField.setDeclaringType(internalDeclaringType);
    }//from ww  w  .  ja v  a  2 s  .  c  om
    database.addField(newFlattenField);
    typeMapping.map(referenceField, newFlattenField);
    return typeMapping;
}

From source file:com.aionemu.gameserver.model.TribeRelationCheck.java

@BeforeClass
public static void init() throws Exception {
    File xml = new File("./data/static_data/tribe/tribe_relations.xml");
    Schema schema = null;//  w ww . j  a v a2  s  .co m
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    TribeRelationsData tribeRelations = null;
    NpcData npcTemplates = null;

    try {
        schema = sf.newSchema(new File("./data/static_data/tribe/tribe_relations.xsd"));
        JAXBContext jc = JAXBContext.newInstance(TribeRelationsData.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        unmarshaller.setSchema(schema);
        tribeRelations = (TribeRelationsData) unmarshaller.unmarshal(xml);

        xml = new File("./data/static_data/npcs/npc_templates.xml");
        schema = sf.newSchema(new File("./data/static_data/npcs/npcs.xsd"));
        jc = JAXBContext.newInstance(NpcData.class);
        unmarshaller = jc.createUnmarshaller();
        unmarshaller.setSchema(schema);
        npcTemplates = (NpcData) unmarshaller.unmarshal(xml);
    } catch (SAXException e1) {
        System.out.println(e1.getMessage());
    } catch (JAXBException e2) {
        System.out.println(e2.getMessage());
    }

    // Not interesting
    DataManager.NPC_SKILL_DATA = new NpcSkillData();
    DataManager.NPC_DATA = npcTemplates;
    DataManager.TRIBE_RELATIONS_DATA = tribeRelations;
    DataManager.ZONE_DATA = new DummyZoneData();
    DataManager.WORLD_MAPS_DATA = new DummyWorldMapData();

    Config.load();
    // AIConfig.ONCREATE_DEBUG = true;
    AIConfig.EVENT_DEBUG = true;
    ThreadConfig.THREAD_POOL_SIZE = 20;
    ThreadPoolManager.getInstance();

    AI2Engine.getInstance().load(null);

    /**
     * Comment out these lines in DAOManager.registerDAO() if not using DB: <tt> 
     * if (!dao.supports(getDatabaseName(),
     *       getDatabaseMajorVersion(), getDatabaseMinorVersion())) { return; } 
     * </tt>
     */
    DAOManager.init();

    world = World.getInstance();
    asmo = DummyPlayer.createAsmodian();
    asmoPosition = World.getInstance().createPosition(DummyWorldMapData.DEFAULT_MAP, 100f, 100f, 0f, (byte) 0,
            0);

    MapRegion asmoRegion = asmoPosition.getWorldMapInstance().getRegion(100f, 100f, 0);
    asmoRegion.getObjects().put(asmo.getObjectId(), asmo);
    asmoRegion.activate();
    asmo.setPosition(asmoPosition);

    ely = DummyPlayer.createElyo();
    elyPosition = World.getInstance().createPosition(DummyWorldMapData.DEFAULT_MAP, 200f, 200f, 0f, (byte) 0,
            0);
    MapRegion elyRegion = elyPosition.getWorldMapInstance().getRegion(200f, 200f, 0);
    elyRegion.getObjects().put(ely.getObjectId(), ely);
    elyRegion.activate();
    ely.setPosition(elyPosition);

    PacketBroadcaster.getInstance();
    DuelService.getInstance();
    PlayerMoveTaskManager.getInstance();
    MoveTaskManager.getInstance();
}

From source file:eu.scape_project.tool.toolwrapper.data.tool_spec.utils.Utils.java

private static void setSchemaTo(Unmarshaller unmarshaller) throws IOException, SAXException {
    // copy XML Schema from resources to a temporary location
    File schemaFile = File.createTempFile("schema", null);
    FileUtils.copyInputStreamToFile(Utils.class.getResourceAsStream(TOOLSPEC_FILENAME_IN_RESOURCES),
            schemaFile);//from   w  w  w.  ja v a  2 s . com
    Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaFile);

    // validate provided toolspec against XML Schema
    unmarshaller.setSchema(schema);
}

From source file:energy.usef.core.util.XMLUtil.java

/**
 * Converts xml to an object after optional validation against the xsd.
 *
 * @param xml xml string//from  w ww  .j a va 2 s . co m
 * @param validate true when the xml needs to be validated
 * @return object corresponding to this xml
 */
public static Object xmlToMessage(String xml, boolean validate) {
    try (InputStream is = IOUtils.toInputStream(xml, UTF_8)) {
        Unmarshaller unmarshaller = CONTEXT.createUnmarshaller();

        if (validate) {
            // setup xsd validation
            SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = sf.newSchema(XMLUtil.class.getClassLoader().getResource(MESSAGING_XSD_FILE));

            unmarshaller.setSchema(schema);
        }

        return unmarshaller.unmarshal(is);
    } catch (JAXBException | IOException e) {
        LOGGER.error(e.getMessage(), e);
        throw new TechnicalException("Invalid XML content: " + e.getMessage(), e);
    } catch (SAXException e) {
        LOGGER.error(e.getMessage(), e);
        throw new TechnicalException("Unable to read XSD schema", e);
    }
}

From source file:com.smartitengineering.cms.spi.impl.type.validator.XMLSchemaBasedTypeValidator.java

protected boolean isValid(Document document) throws Exception {
    // create a SchemaFactory capable of understanding WXS schemas
    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    final InputStream xsdStream = getClass().getClassLoader().getResourceAsStream(XSD_LOCATION);
    // load a WXS schema, represented by a Schema instance
    Source schemaFile = new StreamSource(xsdStream);
    schemaFile.setSystemId(CONTENT_TYPE_SCHEMA_URI);
    Schema schema = factory.newSchema(schemaFile);
    // create a Validator instance, which can be used to validate an instance document
    Validator validator = schema.newValidator();
    // validate the DOM tree
    try {/*from   w w w.  ja v  a  2  s .  c  o  m*/
        validator.validate(new DOMSource(document));
        return true;
    } catch (SAXException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:fr.cls.atoll.motu.library.misc.xml.XMLUtils.java

/**
 * Validate xml./* w  w w.j a va 2 s.com*/
 * 
 * @param inSchemas the in schemas
 * @param inXml the in xml
 * 
 * @return the xML error handler
 * 
 * @throws MotuException the motu exception
 */
public static XMLErrorHandler validateXML(String[] inSchemas, InputStream inXml) throws MotuException {

    return XMLUtils.validateXML(inSchemas, inXml, XMLConstants.W3C_XML_SCHEMA_NS_URI);
}

From source file:eu.europa.esig.dss.validation.ValidationResourceManager.java

/**
 * This is the utility method that loads the data from the inputstream determined by the inputstream parameter into
 * a//from  w  w w  .java 2  s  . c om
 * {@link ConstraintsParameters}.
 *
 * @param inputStream
 * @return
 */
public static ConstraintsParameters load(final InputStream inputStream) throws DSSException {
    try {
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = sf.newSchema(new StreamSource(
                ValidationResourceManager.class.getResourceAsStream(defaultPolicyXsdLocation)));

        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        unmarshaller.setSchema(schema);

        return (ConstraintsParameters) unmarshaller.unmarshal(inputStream);
    } catch (Exception e) {
        throw new DSSException("Unable to load policy : " + e.getMessage(), e);
    }
}

From source file:io.inkstand.jcr.util.JCRContentLoaderTest.java

@Test
public void testLoadContent_validating_validResource() throws Exception {
    // prepare//from  ww w.j a  va2s . co  m
    final URL resource = getClass().getResource("test01_inkstandJcrImport_v1-0.xml");
    final Session actSession = repository.login("admin", "admin");
    final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    final Schema schema = schemaFactory.newSchema(getClass().getResource("inkstandJcrImport_v1-0.xsd"));
    // act
    subject.setSchema(schema);
    subject.loadContent(actSession, resource);
    // assert
    final Session verifySession = repository.getRepository().login();
    verifySession.refresh(true);
    assertNodeExistByPath(verifySession, "/root");
    final Node root = verifySession.getNode("/root");
    assertPrimaryNodeType(root, "nt:unstructured");
    assertMixinNodeType(root, "mix:title");
    assertStringPropertyEquals(root, "jcr:title", "TestTitle");
}

From source file:ee.ria.xroad.opmonitordaemon.QueryRequestHandler.java

private static Schema createSchema() {
    try {//w  w w  . ja  v a 2  s .  co  m
        return SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
                .newSchema(ResourceUtils.getClasspathResource("op-monitoring.xsd"));
    } catch (SAXException e) {
        throw new CodedException(X_INTERNAL_ERROR, e);
    }
}