protected static MappingScript getMapping(XMLSchema source, XMLSchema target, String url) throws IOException { MappingScript mapping = new XMLMappingReader(new MappingFactoryImpl(ModelUtils.getRegistry())) .parse(new InputSource(url)); mapping.setSource(source); mapping.setTarget(target); new MappingResolver(ModelUtils.getRegistry()).resolveTemplate(mapping); return mapping; }
protected static MappingScript getEmptyMapping( XMLSchema source, XMLSchema target, String newMapID) throws IOException { MappingScript mapping; if (newMapID != null) mapping = new MappingModelImpl(newMapID, source, target); else { newMapID = "http://" + source.getID() + target.getID() + UUID.randomUUID().toString(); // Not incremental but semi-random... mapping = new MappingModelImpl(newMapID, source, target); } mapping.setSource(source); mapping.setTarget(target); new MappingResolver(ModelUtils.getRegistry()).resolveTemplate(mapping); return mapping; }
public static ResponseState saveMapping( MappingScriptProxy mappings, TransformationUI transformationUI, String oldTransId) { // System.out.println("SERVER - Save Mapping: "+mappings.getID()); // System.out.println("SERVER - Target ID: "+mappings.getTargetModel().getID()); // System.out.println("SERVER - Source ID: "+mappings.getSourceModel().getID()); ResponseState response; try { // 00 validate transformation response = validateTransformation( transformationUI.getIdentifier(), FilenameUtils.removeExtension(transformationUI.getXslFilePath()), oldTransId); if (response != ResponseState.SUCCESS) return response; // System.out.println("SERVER - The transformation is valid"); // Setup stuff for file writing URL tmpUrl = new URL(transformationUI.getSourceSchema()); XMLSchema source = getXSDSchema(tmpUrl); tmpUrl = new URL(transformationUI.getDestSchema()); XMLSchema target = getXSDSchema(tmpUrl); MappingFactory factory = new MappingFactoryImpl(ModelUtils.getRegistry()); MappingScript script = new UI2MappingAdapter(factory, source, target).adapt(mappings); // 1st STEP - create the xmap file String fileName = FilenameUtils.removeExtension(transformationUI.getXslFilePath()); createXmapFile(fileName, script); // 2nd STEP - Create the xsl file createXslFile(fileName, script); // 3rd STEP - Register transformation in the mdr response = saveTransformationMDR(transformationUI, oldTransId); // System.out.println("SERVER - EDITABLE: "+transformationUI.isEditable()); } catch (Exception e) { e.printStackTrace(); response = ResponseState.ERROR; } return response; }