Author: linus
Date: 2011-12-20 13:21:42-0800
New Revision: 19852

Added:
   
trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/conversions/umbrello.xsl
Modified:
   trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java

Log:
Added patch to allow patching of umbrello models on import.

Contributed by: Laurent Braud

Modified: 
trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java?view=diff&pathrev=19852&r1=19851&r2=19852
==============================================================================
--- 
trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java   
    (original)
+++ 
trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java   
    2011-12-20 13:21:42-0800
@@ -10,6 +10,7 @@
  *    Bob Tarling
  *    Tom Morris
  *    Luis Sergio Oliveira (euluis)
+ *    Laurent Braud
  *****************************************************************************
  *
  * Some portions of this file was previously release using the BSD License:
@@ -264,8 +265,19 @@
                 // MDR's autocommit mode
                 repository.beginTrans(true);
 
-                newElements = xmiReader.read(inputSource.getByteStream(),
-                        systemId, extent);
+                // Issue 5816 : invalid XMI
+                try {
+                    newElements = xmiReader.read(inputSource.getByteStream(),
+                            systemId, extent);
+                } catch (MalformedXMIException e) {
+                    repository.endTrans(true);
+                    repository.beginTrans(true);
+                    resolver.clearIdMaps();
+                    inputSource = convertFromInvalidXMI(inputSource);
+                    newElements = xmiReader.read(inputSource.getByteStream(),
+                            systemId, extent);
+
+                }
                 
                 // If a UML 1.3 file, attempt to upgrade it to UML 1.4
                 if (uml13) {
@@ -377,6 +389,29 @@
     }
 
     /**
+     * 
+     * @param input
+     * @return InputSource : a new XML to test
+     * @throws UmlException
+     */
+    private InputSource convertFromInvalidXMI(InputSource input)
+        throws UmlException {
+        
+        LOG.info("XMI file doesn't appear to be a valid XMI");
+        
+        final String[] transformFiles = new String[] { 
+            "umbrello.xsl",
+            };
+
+        unknownElement = false;
+        // InputSource xformedInput = chainedTransform(transformFiles, pIs);
+        InputSource xformedInput = serialTransform(transformFiles,
+                input);
+        xformedInput.setPublicId(input.getPublicId());
+        return xformedInput;
+    }
+    
+    /**
      * Defines the URI prefix of the temporary XMI file that is being read.
      * 
      * @return the URI prefix of the temporary XMI file that is being read.

Added: 
trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/conversions/umbrello.xsl
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/conversions/umbrello.xsl?view=markup&pathrev=19852
==============================================================================
--- (empty file)
+++ 
trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/conversions/umbrello.xsl
 2011-12-20 13:21:42-0800
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 
+  Add licence here...
+  
+  Author: Laurent Braud
+  Purpose: Issue 5816 - Import XMI from Umbrello
+  
+  The first package (Logical View,...) has an invalid namespace
+  
+  
+-->
+<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
+    
+     <xsl:output method="xml" indent="yes" encoding="UTF-8" />
+
+    <xsl:template match="*">
+       <!-- <xsl:copy-of select="."/> -->
+          <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy>
+
+    </xsl:template>
+    
+    <xsl:template match="@*">
+               <xsl:choose>
+                       <xsl:when test="name()='namespace' and contains(.,' ')">
+                               <xsl:attribute name="namespace"><xsl:value-of 
select="translate(.,' ', '_')"/></xsl:attribute>
+                       </xsl:when>
+                       <xsl:otherwise>
+                               <xsl:copy> <xsl:apply-templates select="@*"/> 
</xsl:copy>
+                       </xsl:otherwise>
+               </xsl:choose>
+               
+    </xsl:template>
+</xsl:stylesheet>
\ No newline at end of file

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2895202

To unsubscribe from this discussion, e-mail: 
[[email protected]].

Reply via email to