commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gu...@apache.org
Subject svn commit: r967028 - /commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java
Date Fri, 23 Jul 2010 10:45:25 GMT
Author: guixl
Date: Fri Jul 23 10:45:25 2010
New Revision: 967028

URL: http://svn.apache.org/viewvc?rev=967028&view=rev
Log:
add SCXML document format function

Modified:
    commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java

Modified: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java?rev=967028&r1=967027&r2=967028&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java
(original)
+++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java
Fri Jul 23 10:45:25 2010
@@ -221,7 +221,8 @@ public class ModelingDocumentExportWizar
 				monitor.worked(1);
 				content=content.replace("xmlns_attribute_url_in_xslt_file", "xmlns");
 				monitor.worked(1);
-				xmlFile.setContents(shc.string2InputStream(content), 1, null);
+				
+				xmlFile.setContents(shc.string2InputStream(formatXML(content)), 1, null);
 				monitor.worked(1);
 				if (monitor.isCanceled()) throw new InterruptedException(
 				"The SCXML document export operation was cancelled");
@@ -231,6 +232,47 @@ public class ModelingDocumentExportWizar
 				e.printStackTrace();
 			}
 		}
+		
+		/**
+		 * 
+		 * @param content (initial SCXML content,without new line char)
+		 * @return format SCXML content
+		 */
+		public String formatXML(String content){
+			String newContent="";
+			int tabNumber=0;
+			char lastChar='-';
+			for(int i=0;i<content.length();i++){
+				char each=content.charAt(i);
+				if(each=='<'&&i<content.length()-1){
+					char after=content.charAt(i+1);
+					if(after!='?'){
+						if(after=='/'){
+							newContent=newContent.concat("\r\n");
+							if(lastChar=='-') tabNumber--;
+							for(int j=0;j<tabNumber;j++)
+								newContent=newContent.concat("\t");
+							lastChar='-';
+						}else{
+							newContent=newContent.concat("\r\n");
+							if(lastChar=='+') tabNumber++;
+							for(int j=0;j<tabNumber;j++)
+								newContent=newContent.concat("\t");
+							lastChar='+';
+						}
+					}
+				}else if(each=='/'&&i<content.length()-1){
+					char before=content.charAt(i-1);
+					if(before!='<'){
+						lastChar='-';
+					}
+				}
+				
+				newContent=newContent.concat(String.valueOf(each));
+			}
+			
+			return newContent;
+		}
 	}
 
 	/**



Mime
View raw message