mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
ALF-7260: schema validation: ensure outputting UTF-8 and Windows line endings.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32183 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -29,6 +29,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.sql.Array;
|
import java.sql.Array;
|
||||||
import java.sql.Blob;
|
import java.sql.Blob;
|
||||||
@@ -72,12 +73,10 @@ import org.alfresco.repo.domain.hibernate.dialect.AlfrescoSybaseAnywhereDialect;
|
|||||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
import org.alfresco.util.LogUtil;
|
import org.alfresco.util.LogUtil;
|
||||||
import org.alfresco.util.TempFileProvider;
|
import org.alfresco.util.TempFileProvider;
|
||||||
import org.alfresco.util.schemacomp.Difference;
|
|
||||||
import org.alfresco.util.schemacomp.ExportDb;
|
import org.alfresco.util.schemacomp.ExportDb;
|
||||||
import org.alfresco.util.schemacomp.Result;
|
import org.alfresco.util.schemacomp.Result;
|
||||||
import org.alfresco.util.schemacomp.Results;
|
import org.alfresco.util.schemacomp.Results;
|
||||||
import org.alfresco.util.schemacomp.SchemaComparator;
|
import org.alfresco.util.schemacomp.SchemaComparator;
|
||||||
import org.alfresco.util.schemacomp.ValidationResult;
|
|
||||||
import org.alfresco.util.schemacomp.XMLToSchema;
|
import org.alfresco.util.schemacomp.XMLToSchema;
|
||||||
import org.alfresco.util.schemacomp.model.Schema;
|
import org.alfresco.util.schemacomp.model.Schema;
|
||||||
import org.alfresco.util.schemadump.Main;
|
import org.alfresco.util.schemadump.Main;
|
||||||
@@ -1676,17 +1675,22 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
|||||||
PrintWriter pw = null;
|
PrintWriter pw = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pw = new PrintWriter(outputFile);
|
pw = new PrintWriter(outputFile, SchemaComparator.CHAR_SET);
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException error)
|
catch (FileNotFoundException error)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Unable to open file for writing: " + outputFile);
|
throw new RuntimeException("Unable to open file for writing: " + outputFile);
|
||||||
}
|
}
|
||||||
|
catch (UnsupportedEncodingException error)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("Unsupported char set: " + SchemaComparator.CHAR_SET, error);
|
||||||
|
}
|
||||||
|
|
||||||
// Populate the file with details of the comparison's results.
|
// Populate the file with details of the comparison's results.
|
||||||
for (Result result : results)
|
for (Result result : results)
|
||||||
{
|
{
|
||||||
pw.println(result.describe());
|
pw.print(result.describe());
|
||||||
|
pw.print(SchemaComparator.LINE_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
pw.close();
|
pw.close();
|
||||||
|
@@ -19,6 +19,11 @@
|
|||||||
package org.alfresco.util.schemacomp;
|
package org.alfresco.util.schemacomp;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
@@ -77,12 +82,58 @@ public class DbToXML
|
|||||||
if (exporter != null)
|
if (exporter != null)
|
||||||
{
|
{
|
||||||
Schema schema = exporter.getSchema();
|
Schema schema = exporter.getSchema();
|
||||||
SchemaToXML schemaToXML = new SchemaToXML(schema, new StreamResult(outputFile));
|
// Write to a string buffer and then write the results to a file
|
||||||
|
// since we need to write windows line endings - and even passing in a suitable
|
||||||
|
// PrintWriter to StreamResult does not seem to result in the correct line endings.
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
SchemaToXML schemaToXML = new SchemaToXML(schema, new StreamResult(stringWriter));
|
||||||
schemaToXML.execute();
|
schemaToXML.execute();
|
||||||
|
writeToFile(stringWriter.getBuffer().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void writeToFile(String content)
|
||||||
|
{
|
||||||
|
PrintWriter pw = printWriter(outputFile, SchemaComparator.CHAR_SET, SchemaComparator.LINE_SEPARATOR);
|
||||||
|
|
||||||
|
String[] lines = content.split(System.getProperty("line.separator"));
|
||||||
|
for (String line : lines)
|
||||||
|
{
|
||||||
|
pw.println(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
pw.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PrintWriter printWriter(File file, String charSet, String lineSeparator)
|
||||||
|
{
|
||||||
|
Properties props = System.getProperties();
|
||||||
|
synchronized (props)
|
||||||
|
{
|
||||||
|
String oldLineSep = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
oldLineSep = (String) props.setProperty("line.separator", lineSeparator);
|
||||||
|
return new PrintWriter(file, charSet);
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException error)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("Unable to write to file " + file, error);
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException error)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("Unsupported encoding" + charSet, error);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (oldLineSep != null)
|
||||||
|
{
|
||||||
|
props.put("line.separator", oldLineSep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
if (args.length != 2)
|
if (args.length != 2)
|
||||||
|
@@ -20,6 +20,7 @@ package org.alfresco.util.schemacomp;
|
|||||||
|
|
||||||
import org.alfresco.util.schemacomp.Result.Strength;
|
import org.alfresco.util.schemacomp.Result.Strength;
|
||||||
import org.alfresco.util.schemacomp.model.Schema;
|
import org.alfresco.util.schemacomp.model.Schema;
|
||||||
|
import org.apache.xml.serialize.LineSeparator;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,6 +31,8 @@ import org.hibernate.dialect.Dialect;
|
|||||||
*/
|
*/
|
||||||
public class SchemaComparator
|
public class SchemaComparator
|
||||||
{
|
{
|
||||||
|
public static final String CHAR_SET = "UTF-8";
|
||||||
|
public static final String LINE_SEPARATOR = LineSeparator.Windows;
|
||||||
private final Schema referenceSchema;
|
private final Schema referenceSchema;
|
||||||
private final Schema targetSchema;
|
private final Schema targetSchema;
|
||||||
private final DiffContext ctx;
|
private final DiffContext ctx;
|
||||||
|
@@ -62,9 +62,9 @@ public class SchemaToXML
|
|||||||
// It was worth a try
|
// It was worth a try
|
||||||
}
|
}
|
||||||
t.setOutputProperty(OutputKeys.INDENT, "yes");
|
t.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||||
|
t.setOutputProperty(OutputKeys.ENCODING, SchemaComparator.CHAR_SET);
|
||||||
xmlOut.setResult(streamResult);
|
xmlOut.setResult(streamResult);
|
||||||
|
|
||||||
|
|
||||||
this.schema = schema;
|
this.schema = schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,54 +1,54 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!--
|
<!--
|
||||||
Test data used by the XMLToSchemaTest junit test class.
|
Test data used by the XMLToSchemaTest junit test class.
|
||||||
-->
|
-->
|
||||||
<schema name="alfresco">
|
<schema name="alfresco">
|
||||||
<objects>
|
<objects>
|
||||||
<table name="node">
|
<table name="node">
|
||||||
<columns>
|
<columns>
|
||||||
<column name="id">
|
<column name="id">
|
||||||
<type>NUMBER(10)</type>
|
<type>NUMBER(10)</type>
|
||||||
<nullable>false</nullable>
|
<nullable>false</nullable>
|
||||||
</column>
|
</column>
|
||||||
<column name="nodeRef">
|
<column name="nodeRef">
|
||||||
<type>VARCHAR2(200)</type>
|
<type>VARCHAR2(200)</type>
|
||||||
<nullable>false</nullable>
|
<nullable>false</nullable>
|
||||||
</column>
|
</column>
|
||||||
<column name="name">
|
<column name="name">
|
||||||
<type>VARCHAR2(150)</type>
|
<type>VARCHAR2(150)</type>
|
||||||
<nullable>true</nullable>
|
<nullable>true</nullable>
|
||||||
</column>
|
</column>
|
||||||
</columns>
|
</columns>
|
||||||
<primarykey name="pk_node">
|
<primarykey name="pk_node">
|
||||||
<columnnames>
|
<columnnames>
|
||||||
<columnname>id</columnname>
|
<columnname>id</columnname>
|
||||||
</columnnames>
|
</columnnames>
|
||||||
</primarykey>
|
</primarykey>
|
||||||
<foreignkeys>
|
<foreignkeys>
|
||||||
<foreignkey name="fk_node_noderef">
|
<foreignkey name="fk_node_noderef">
|
||||||
<localcolumn>nodeRef</localcolumn>
|
<localcolumn>nodeRef</localcolumn>
|
||||||
<targettable>node</targettable>
|
<targettable>node</targettable>
|
||||||
<targetcolumn>nodeRef</targetcolumn>
|
<targetcolumn>nodeRef</targetcolumn>
|
||||||
</foreignkey>
|
</foreignkey>
|
||||||
</foreignkeys>
|
</foreignkeys>
|
||||||
<indexes>
|
<indexes>
|
||||||
<index name="idx_node_by_id" unique="true">
|
<index name="idx_node_by_id" unique="true">
|
||||||
<columnnames>
|
<columnnames>
|
||||||
<columnname>id</columnname>
|
<columnname>id</columnname>
|
||||||
<columnname>nodeRef</columnname>
|
<columnname>nodeRef</columnname>
|
||||||
</columnnames>
|
</columnnames>
|
||||||
<validators>
|
<validators>
|
||||||
<validator class="org.alfresco.util.schemacomp.validator.NameValidator">
|
<validator class="org.alfresco.util.schemacomp.validator.NameValidator">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="pattern">idx_.+</property>
|
<property name="pattern">idx_.+</property>
|
||||||
</properties>
|
</properties>
|
||||||
</validator>
|
</validator>
|
||||||
</validators>
|
</validators>
|
||||||
</index>
|
</index>
|
||||||
</indexes>
|
</indexes>
|
||||||
</table>
|
</table>
|
||||||
<sequence name="node_seq"/>
|
<sequence name="node_seq"/>
|
||||||
<sequence name="person_seq"/>
|
<sequence name="person_seq"/>
|
||||||
<sequence name="content_seq"/>
|
<sequence name="content_seq"/>
|
||||||
</objects>
|
</objects>
|
||||||
</schema>
|
</schema>
|
||||||
|
Reference in New Issue
Block a user