[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.edm.constants.ODataServiceVersion;
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.LinkImpl;
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.methods.MERGE;
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.AbstractUtilities;
import org.apache.olingo.fit.utils.AbstractXMLUtilities;
@ -196,7 +196,7 @@ public abstract class AbstractServices {
return utils.getValue().createResponse(
FSManager.instance(version).readFile(Constants.get(version, ConstantKey.REF)
+ File.separatorChar + filename, utils.getKey()),
+ File.separatorChar + filename, utils.getKey()),
null,
utils.getKey());
} catch (Exception e) {
@ -243,8 +243,7 @@ public abstract class AbstractServices {
InputStream res =
util.patchEntity(entitySetName, entityId, IOUtils.toInputStream(changes), acceptType, ifMatch);
final AtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
final FITAtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
final ObjectMapper mapper = Commons.getJsonMapper(version);
@ -308,7 +307,7 @@ public abstract class AbstractServices {
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 Container<AtomEntryImpl> cres;
@ -367,7 +366,7 @@ public abstract class AbstractServices {
utils = getUtilities(acceptType);
final AtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
final FITAtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
final AtomSerializer atomSerializer = Commons.getAtomSerializer(version);
final ObjectMapper mapper = Commons.getJsonMapper(version);
@ -415,7 +414,7 @@ public abstract class AbstractServices {
} else {
final Container<JSONEntryImpl> jcontainer =
mapper.readValue(IOUtils.toInputStream(entity), new TypeReference<JSONEntryImpl>() {
});
});
entry = (new DataBinder(version)).
getAtomEntry(jcontainer.getObject());
@ -488,13 +487,13 @@ public abstract class AbstractServices {
replaceAll("\"Salary\":[0-9]*,", "\"Salary\":0,").
replaceAll("\"Title\":\".*\"", "\"Title\":\"[Sacked]\"").
replaceAll("\\<d:Salary m:type=\"Edm.Int32\"\\>.*\\</d:Salary\\>",
"<d:Salary m:type=\"Edm.Int32\">0</d:Salary>").
"<d:Salary m:type=\"Edm.Int32\">0</d:Salary>").
replaceAll("\\<d:Title\\>.*\\</d:Title\\>", "<d:Title>[Sacked]</d:Title>");
final FSManager fsManager = FSManager.instance(version);
fsManager.putInMemory(IOUtils.toInputStream(newContent, "UTF-8"),
fsManager.getAbsolutePath(Commons.getEntityBasePath("Person", entityId) + Constants.get(version,
ConstantKey.ENTITY), utils.getKey()));
ConstantKey.ENTITY), utils.getKey()));
return utils.getValue().createResponse(null, null, utils.getKey(), Response.Status.NO_CONTENT);
} catch (Exception e) {
@ -546,9 +545,9 @@ public abstract class AbstractServices {
final Long newSalary = Long.valueOf(salaryMatcher.group(1)) + n;
newContent = newContent.
replaceAll("\"Salary\":" + salaryMatcher.group(1) + ",",
"\"Salary\":" + newSalary + ",").
"\"Salary\":" + newSalary + ",").
replaceAll("\\<d:Salary m:type=\"Edm.Int32\"\\>" + salaryMatcher.group(1) + "</d:Salary\\>",
"<d:Salary m:type=\"Edm.Int32\">" + newSalary + "</d:Salary>");
"<d:Salary m:type=\"Edm.Int32\">" + newSalary + "</d:Salary>");
}
FSManager.instance(version).putInMemory(IOUtils.toInputStream(newContent, "UTF-8"),
@ -662,7 +661,7 @@ public abstract class AbstractServices {
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 Container<Feed> container = atomDeserializer.read(feed, AtomFeedImpl.class);
@ -680,7 +679,7 @@ public abstract class AbstractServices {
mapper.writeValue(
writer, new JsonFeedContainer<JSONFeedImpl>(container.getContextURL(), container.getMetadataETag(),
(new DataBinder(version)).getJsonFeed((AtomFeedImpl) container.getObject())));
(new DataBinder(version)).getJsonFeed((AtomFeedImpl) container.getObject())));
}
return xml.createResponse(new ByteArrayInputStream(content.toByteArray()),
@ -780,7 +779,7 @@ public abstract class AbstractServices {
InputStream entity = entityInfo.getValue();
final AtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
final FITAtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
final AtomSerializer atomSerializer = Commons.getAtomSerializer(version);
final Container<Entry> container = atomDeserializer.<Entry, AtomEntryImpl>read(entity, AtomEntryImpl.class);
@ -865,7 +864,7 @@ public abstract class AbstractServices {
final ObjectMapper mapper = Commons.getJsonMapper(version);
mapper.writeValue(
writer, new JsonEntryContainer<JSONEntryImpl>(container.getContextURL(), container.getMetadataETag(),
(new DataBinder(version)).getJsonEntry((AtomEntryImpl) container.getObject())));
(new DataBinder(version)).getJsonEntry((AtomEntryImpl) container.getObject())));
}
return xml.createResponse(new ByteArrayInputStream(content.toByteArray()),

View File

@ -54,7 +54,7 @@ public class Metadata extends AbstractMetadataElement {
try {
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
final XMLEvent event = reader.nextEvent();
if (event.isStartElement() && event.asStartElement().getName().equals(new QName("Schema"))) {
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 org.apache.commons.io.IOUtils;
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.op.InjectableSerializerProvider;
import org.apache.olingo.fit.metadata.Metadata;
import org.apache.olingo.fit.serializer.FITAtomDeserializer;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -57,8 +57,8 @@ public abstract class Commons {
*/
protected static final Logger LOG = LoggerFactory.getLogger(Commons.class);
private static Map<ODataServiceVersion, AtomDeserializer> atomDeserializer =
new EnumMap<ODataServiceVersion, AtomDeserializer>(ODataServiceVersion.class);
private static Map<ODataServiceVersion, FITAtomDeserializer> atomDeserializer =
new EnumMap<ODataServiceVersion, FITAtomDeserializer>(ODataServiceVersion.class);
private static Map<ODataServiceVersion, AtomSerializer> atomSerializer =
new EnumMap<ODataServiceVersion, AtomSerializer>(ODataServiceVersion.class);
@ -91,9 +91,9 @@ public abstract class Commons {
mediaContent.put("Car/Photo", null);
}
public static AtomDeserializer getAtomDeserializer(final ODataServiceVersion version) {
public static FITAtomDeserializer getAtomDeserializer(final ODataServiceVersion version) {
if (!atomDeserializer.containsKey(version)) {
atomDeserializer.put(version, new AtomDeserializer(version));
atomDeserializer.put(version, new FITAtomDeserializer(version));
}
return atomDeserializer.get(version);
}
@ -128,10 +128,7 @@ public abstract class Commons {
public static Metadata getMetadata(final ODataServiceVersion version) {
if (!metadata.containsKey(version)) {
final InputStream is = Commons.class.getResourceAsStream(
File.separatorChar
+ version.name()
+ File.separatorChar + "metadata.xml");
final InputStream is = Commons.class.getResourceAsStream("/" + version.name() + "/metadata.xml");
metadata.put(version, new Metadata(is));
}
@ -178,7 +175,7 @@ public abstract class Commons {
try {
return FSManager.instance(version)
.getAbsolutePath(basePath + Constants.get(version, ConstantKey.LINKS_FILE_PATH)
+ File.separatorChar + linkName, accept);
+ File.separatorChar + linkName, accept);
} catch (Exception e) {
throw new IOException(e);
}

View File

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

View File

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