[OLINGO-227] Fixing again windows build

This commit is contained in:
Francesco Chicchiriccò 2014-04-11 13:49:14 +02:00
parent 450ccfd4e3
commit e9b71f34bd
6 changed files with 86 additions and 37 deletions

View File

@ -24,7 +24,6 @@ import org.apache.olingo.commons.api.data.Link;
import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.core.data.AtomDeserializer;
import org.apache.olingo.commons.core.data.AtomFeedImpl; import org.apache.olingo.commons.core.data.AtomFeedImpl;
import org.apache.olingo.commons.core.data.LinkImpl; import org.apache.olingo.commons.core.data.LinkImpl;
import org.apache.olingo.fit.metadata.Metadata; import org.apache.olingo.fit.metadata.Metadata;
@ -89,6 +88,7 @@ import org.apache.olingo.fit.utils.FSManager;
import org.apache.olingo.fit.utils.Commons; import org.apache.olingo.fit.utils.Commons;
import org.apache.olingo.fit.methods.MERGE; import org.apache.olingo.fit.methods.MERGE;
import org.apache.olingo.fit.methods.PATCH; import org.apache.olingo.fit.methods.PATCH;
import org.apache.olingo.fit.serializer.FITAtomDeserializer;
import org.apache.olingo.fit.utils.AbstractJSONUtilities; import org.apache.olingo.fit.utils.AbstractJSONUtilities;
import org.apache.olingo.fit.utils.AbstractUtilities; import org.apache.olingo.fit.utils.AbstractUtilities;
import org.apache.olingo.fit.utils.AbstractXMLUtilities; import org.apache.olingo.fit.utils.AbstractXMLUtilities;
@ -243,8 +243,7 @@ public abstract class AbstractServices {
InputStream res = InputStream res =
util.patchEntity(entitySetName, entityId, IOUtils.toInputStream(changes), acceptType, ifMatch); util.patchEntity(entitySetName, entityId, IOUtils.toInputStream(changes), acceptType, ifMatch);
final FITAtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
final AtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
final ObjectMapper mapper = Commons.getJsonMapper(version); final ObjectMapper mapper = Commons.getJsonMapper(version);
@ -308,7 +307,7 @@ public abstract class AbstractServices {
res = json.addOrReplaceEntity(entityId, entitySetName, IOUtils.toInputStream(entity)); res = json.addOrReplaceEntity(entityId, entitySetName, IOUtils.toInputStream(entity));
} }
final AtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version); final FITAtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
final ObjectMapper mapper = Commons.getJsonMapper(version); final ObjectMapper mapper = Commons.getJsonMapper(version);
final Container<AtomEntryImpl> cres; final Container<AtomEntryImpl> cres;
@ -367,7 +366,7 @@ public abstract class AbstractServices {
utils = getUtilities(acceptType); utils = getUtilities(acceptType);
final AtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version); final FITAtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
final AtomSerializer atomSerializer = Commons.getAtomSerializer(version); final AtomSerializer atomSerializer = Commons.getAtomSerializer(version);
final ObjectMapper mapper = Commons.getJsonMapper(version); final ObjectMapper mapper = Commons.getJsonMapper(version);
@ -662,7 +661,7 @@ public abstract class AbstractServices {
final InputStream feed = FSManager.instance(version).readFile(builder.toString(), Accept.ATOM); final InputStream feed = FSManager.instance(version).readFile(builder.toString(), Accept.ATOM);
final AtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version); final FITAtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
final AtomSerializer atomSerializer = Commons.getAtomSerializer(version); final AtomSerializer atomSerializer = Commons.getAtomSerializer(version);
final Container<Feed> container = atomDeserializer.read(feed, AtomFeedImpl.class); final Container<Feed> container = atomDeserializer.read(feed, AtomFeedImpl.class);
@ -780,7 +779,7 @@ public abstract class AbstractServices {
InputStream entity = entityInfo.getValue(); InputStream entity = entityInfo.getValue();
final AtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version); final FITAtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
final AtomSerializer atomSerializer = Commons.getAtomSerializer(version); final AtomSerializer atomSerializer = Commons.getAtomSerializer(version);
final Container<Entry> container = atomDeserializer.<Entry, AtomEntryImpl>read(entity, AtomEntryImpl.class); final Container<Entry> container = atomDeserializer.<Entry, AtomEntryImpl>read(entity, AtomEntryImpl.class);

View File

@ -54,7 +54,7 @@ public class Metadata extends AbstractMetadataElement {
try { try {
while (reader.hasNext()) { while (reader.hasNext()) {
XMLEvent event = reader.nextEvent(); final XMLEvent event = reader.nextEvent();
if (event.isStartElement() && event.asStartElement().getName().equals(new QName("Schema"))) { if (event.isStartElement() && event.asStartElement().getName().equals(new QName("Schema"))) {
final Schema schema = getSchema(event.asStartElement(), reader); final Schema schema = getSchema(event.asStartElement(), reader);

View File

@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.fit.serializer;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamException;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.core.data.AtomDeserializer;
public class FITAtomDeserializer extends AtomDeserializer {
private static final Charset ENCODING = Charset.forName(Constants.UTF8);
public FITAtomDeserializer(final ODataServiceVersion version) {
super(version);
}
@Override
protected XMLEventReader getReader(final InputStream input) throws XMLStreamException {
final CharsetDecoder decoder = ENCODING.newDecoder();
decoder.onMalformedInput(CodingErrorAction.IGNORE);
decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
return FACTORY.createXMLEventReader(new InputStreamReader(input, decoder));
}
}

View File

@ -42,10 +42,10 @@ import java.util.Map;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.core.data.AtomDeserializer;
import org.apache.olingo.commons.core.data.AtomSerializer; import org.apache.olingo.commons.core.data.AtomSerializer;
import org.apache.olingo.commons.core.op.InjectableSerializerProvider; import org.apache.olingo.commons.core.op.InjectableSerializerProvider;
import org.apache.olingo.fit.metadata.Metadata; import org.apache.olingo.fit.metadata.Metadata;
import org.apache.olingo.fit.serializer.FITAtomDeserializer;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -57,8 +57,8 @@ public abstract class Commons {
*/ */
protected static final Logger LOG = LoggerFactory.getLogger(Commons.class); protected static final Logger LOG = LoggerFactory.getLogger(Commons.class);
private static Map<ODataServiceVersion, AtomDeserializer> atomDeserializer = private static Map<ODataServiceVersion, FITAtomDeserializer> atomDeserializer =
new EnumMap<ODataServiceVersion, AtomDeserializer>(ODataServiceVersion.class); new EnumMap<ODataServiceVersion, FITAtomDeserializer>(ODataServiceVersion.class);
private static Map<ODataServiceVersion, AtomSerializer> atomSerializer = private static Map<ODataServiceVersion, AtomSerializer> atomSerializer =
new EnumMap<ODataServiceVersion, AtomSerializer>(ODataServiceVersion.class); new EnumMap<ODataServiceVersion, AtomSerializer>(ODataServiceVersion.class);
@ -91,9 +91,9 @@ public abstract class Commons {
mediaContent.put("Car/Photo", null); mediaContent.put("Car/Photo", null);
} }
public static AtomDeserializer getAtomDeserializer(final ODataServiceVersion version) { public static FITAtomDeserializer getAtomDeserializer(final ODataServiceVersion version) {
if (!atomDeserializer.containsKey(version)) { if (!atomDeserializer.containsKey(version)) {
atomDeserializer.put(version, new AtomDeserializer(version)); atomDeserializer.put(version, new FITAtomDeserializer(version));
} }
return atomDeserializer.get(version); return atomDeserializer.get(version);
} }
@ -128,10 +128,7 @@ public abstract class Commons {
public static Metadata getMetadata(final ODataServiceVersion version) { public static Metadata getMetadata(final ODataServiceVersion version) {
if (!metadata.containsKey(version)) { if (!metadata.containsKey(version)) {
final InputStream is = Commons.class.getResourceAsStream( final InputStream is = Commons.class.getResourceAsStream("/" + version.name() + "/metadata.xml");
File.separatorChar
+ version.name()
+ File.separatorChar + "metadata.xml");
metadata.put(version, new Metadata(is)); metadata.put(version, new Metadata(is));
} }

View File

@ -32,7 +32,7 @@ import org.apache.commons.io.IOUtils;
public class XMLEventReaderWrapper implements XMLEventReader { public class XMLEventReaderWrapper implements XMLEventReader {
private static Charset encoding = Charset.forName("UTF-8"); private static final Charset ENCODING = Charset.forName("UTF-8");
public final static String CONTENT = "CONTENT_TAG"; public final static String CONTENT = "CONTENT_TAG";
@ -49,14 +49,14 @@ public class XMLEventReaderWrapper implements XMLEventReader {
factory.setProperty(XMLInputFactory.IS_VALIDATING, false); factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false); factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
final CharsetDecoder decoder = encoding.newDecoder(); final CharsetDecoder decoder = ENCODING.newDecoder();
decoder.onMalformedInput(CodingErrorAction.IGNORE); decoder.onMalformedInput(CodingErrorAction.IGNORE);
decoder.onUnmappableCharacter(CodingErrorAction.IGNORE); decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
InputStreamReader reader = new InputStreamReader( final InputStreamReader reader = new InputStreamReader(
new ByteArrayInputStream((XMLEventReaderWrapper.CONTENT_STAG new ByteArrayInputStream((XMLEventReaderWrapper.CONTENT_STAG
+ IOUtils.toString(stream, encoding).replaceAll("^<\\?xml.*\\?>", "") + IOUtils.toString(stream, ENCODING).replaceAll("^<\\?xml.*\\?>", "")
+ XMLEventReaderWrapper.CONTENT_ETAG).getBytes(encoding)), + XMLEventReaderWrapper.CONTENT_ETAG).getBytes(ENCODING)),
decoder); decoder);
this.wrapped = factory.createXMLEventReader(reader); this.wrapped = factory.createXMLEventReader(reader);

View File

@ -43,10 +43,14 @@ import org.apache.olingo.commons.core.edm.EdmTypeInfo;
public class AtomDeserializer extends AbstractAtomDealer { public class AtomDeserializer extends AbstractAtomDealer {
private static final XMLInputFactory FACTORY = XMLInputFactory.newInstance(); protected static final XMLInputFactory FACTORY = XMLInputFactory.newInstance();
private final AtomGeoValueDeserializer geoDeserializer; private final AtomGeoValueDeserializer geoDeserializer;
protected XMLEventReader getReader(final InputStream input) throws XMLStreamException {
return FACTORY.createXMLEventReader(input);
}
public AtomDeserializer(final ODataServiceVersion version) { public AtomDeserializer(final ODataServiceVersion version) {
super(version); super(version);
this.geoDeserializer = new AtomGeoValueDeserializer(); this.geoDeserializer = new AtomGeoValueDeserializer();
@ -284,7 +288,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
} }
private Container<AtomPropertyImpl> property(final InputStream input) throws XMLStreamException { private Container<AtomPropertyImpl> property(final InputStream input) throws XMLStreamException {
final XMLEventReader reader = FACTORY.createXMLEventReader(input); final XMLEventReader reader = getReader(input);
final StartElement start = skipBeforeFirstStartElement(reader); final StartElement start = skipBeforeFirstStartElement(reader);
return getContainer(start, property(reader, start)); return getContainer(start, property(reader, start));
} }
@ -359,7 +363,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
} }
private Container<XMLLinkCollectionImpl> linkCollection(final InputStream input) throws XMLStreamException { private Container<XMLLinkCollectionImpl> linkCollection(final InputStream input) throws XMLStreamException {
final XMLEventReader reader = FACTORY.createXMLEventReader(input); final XMLEventReader reader = getReader(input);
final StartElement start = skipBeforeFirstStartElement(reader); final StartElement start = skipBeforeFirstStartElement(reader);
return getContainer(start, linkCollection(reader, start)); return getContainer(start, linkCollection(reader, start));
} }
@ -545,7 +549,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
} }
private Container<AtomEntryImpl> entry(final InputStream input) throws XMLStreamException { private Container<AtomEntryImpl> entry(final InputStream input) throws XMLStreamException {
final XMLEventReader reader = FACTORY.createXMLEventReader(input); final XMLEventReader reader = getReader(input);
final StartElement start = skipBeforeFirstStartElement(reader); final StartElement start = skipBeforeFirstStartElement(reader);
return getContainer(start, entry(reader, start)); return getContainer(start, entry(reader, start));
} }
@ -615,7 +619,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
} }
private Container<AtomFeedImpl> feed(final InputStream input) throws XMLStreamException { private Container<AtomFeedImpl> feed(final InputStream input) throws XMLStreamException {
final XMLEventReader reader = FACTORY.createXMLEventReader(input); final XMLEventReader reader = getReader(input);
final StartElement start = skipBeforeFirstStartElement(reader); final StartElement start = skipBeforeFirstStartElement(reader);
return getContainer(start, feed(reader, start)); return getContainer(start, feed(reader, start));
} }
@ -671,7 +675,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
} }
private Container<XMLODataErrorImpl> error(final InputStream input) throws XMLStreamException { private Container<XMLODataErrorImpl> error(final InputStream input) throws XMLStreamException {
final XMLEventReader reader = FACTORY.createXMLEventReader(input); final XMLEventReader reader = getReader(input);
final StartElement start = skipBeforeFirstStartElement(reader); final StartElement start = skipBeforeFirstStartElement(reader);
return getContainer(start, error(reader, start)); return getContainer(start, error(reader, start));
} }