> Author: hboutemy
> Date: Sun Jul 13 09:34:06 2008
> New Revision: 676354
>
> URL:
http://svn.apache.org/viewvc?rev=676354&view=rev> Log:
> improved encoding support
>
> Modified:
> maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/
> org/apache/maven/project/builder/PomClassicDomainModel.java
>
> Modified: maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/
> java/org/apache/maven/project/builder/PomClassicDomainModel.java
> URL:
http://svn.apache.org/viewvc/maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java?rev=676354&r1=676353&r2=676354&view=diff> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/
> org/apache/maven/project/builder/PomClassicDomainModel.java (original)
> +++ maven/sandbox/branches/SI_MAVEN_2_1/maven-project/src/main/java/
> org/apache/maven/project/builder/PomClassicDomainModel.java Sun Jul
> 13 09:34:06 2008
> @@ -6,6 +6,8 @@
> import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
> import org.apache.maven.shared.model.InputStreamDomainModel;
> import org.codehaus.plexus.util.IOUtil;
> +import org.codehaus.plexus.util.ReaderFactory;
> +import org.codehaus.plexus.util.WriterFactory;
> import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
>
> import java.io.*;
> @@ -15,7 +17,7 @@
> */
> public final class PomClassicDomainModel implements
> InputStreamDomainModel {
>
> - private byte[] inputStream;
> + private byte[] inputBytes;
>
> private String eventHistory;
>
> @@ -29,16 +31,18 @@
> throw new IllegalArgumentException("model: null");
> }
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> + Writer out = WriterFactory.newXmlWriter( baos );
> MavenXpp3Writer writer = new MavenXpp3Writer();
> - writer.write(new OutputStreamWriter(baos), model);
> - inputStream = removeIllegalCharacters(baos.toByteArray());
> + writer.write( out, model );
> + out.close();
> + inputBytes = removeIllegalCharacters(baos.toByteArray());
> }
>
> public PomClassicDomainModel(InputStream inputStream) throws
> IOException {
> if (inputStream == null) {
> throw new IllegalArgumentException("inputStream: null");
> }
> - this.inputStream =
> removeIllegalCharacters(IOUtil.toByteArray(inputStream));
> + this.inputBytes =
> removeIllegalCharacters(IOUtil.toByteArray(inputStream));
> }
>
> public boolean matchesParent(Parent parent) {
> @@ -58,7 +62,15 @@
> }
>
> public String asString() {
> - return new String(inputStream);
> + try
> + {
> + return IOUtil.toString( ReaderFactory.newXmlReader( new
> ByteArrayInputStream( inputBytes ) ) );
> + }
> + catch ( IOException ioe )
> + {
> + // should not occur: everything is in-memory
> + return "";
> + }
> }
>
> /**
> @@ -68,7 +80,7 @@
> */
> public Model getModel() throws IOException {
> try {
> - return new MavenXpp3Reader().read(new StringReader(new
> String(inputStream)));
> + return new MavenXpp3Reader().read( new
> ByteArrayInputStream( inputBytes ) );
> }
> catch (XmlPullParserException e) {
> e.printStackTrace();
> @@ -77,8 +89,8 @@
> }
>
> public InputStream getInputStream() {
> - byte[] copy = new byte[inputStream.length];
> - System.arraycopy(inputStream, 0, copy, 0,
> inputStream.length);
> + byte[] copy = new byte[inputBytes.length];
> + System.arraycopy(inputBytes, 0, copy, 0, inputBytes.length);
> return new ByteArrayInputStream(copy);
> }
>
> @@ -92,6 +104,8 @@
>
> //TODO: Workaround
> private byte[] removeIllegalCharacters(byte[] bytes) {
> + // what is it supposed to do? which are the illegal
> characters to remove?
> + // for encoding support, new String(bytes) and
> String.getBytes() should not be used
> return new String(bytes).replaceAll("ø",
> "").replaceAll("&(?![a-zA-Z]{1,8};)", "&").getBytes();
> }
> }
>
>
Our achievements speak for themselves. What we have to keep track
of are our failures, discouragements and doubts. We tend to forget
groping. We see our past achievements as the end result of a