use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class NavajoContextInstanceFactory method appendConditionalAlias.
private void appendConditionalAlias(Message aliasConditionalMessage, Map<String, Set<String>> aliases) {
for (Message m : aliasConditionalMessage.getAllMessages()) {
String name = m.getName();
Property conditionProp = m.getProperty("condition");
Property trueValueProp = m.getProperty("true_value");
Property falseValueProp = m.getProperty("false_value");
if (conditionProp == null || conditionProp.getTypedValue() == null) {
logger.warn("Invalid conditional alias message! {}", m);
continue;
}
boolean evaluated = checkEliasCondition(conditionProp.getValue());
String aliasValue = null;
if (evaluated && trueValueProp != null) {
aliasValue = trueValueProp.getValue();
} else if (!evaluated && falseValueProp != null) {
aliasValue = falseValueProp.getValue();
}
if (aliasValue != null) {
Set<String> found = aliases.get(aliasValue);
if (found == null) {
found = new HashSet<String>();
aliases.put(aliasValue, found);
}
found.add(name);
}
}
}
use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class TmlHttpServlet method sendResponse.
private static void sendResponse(HttpServletRequest request, HttpServletResponse response, Navajo resultMessage) {
ServletOutputStream outputStream = null;
try {
String dataPath = request.getParameter("dataPath");
outputStream = response.getOutputStream();
if (dataPath != null) {
Property bin = resultMessage.getProperty(dataPath);
if (bin == null) {
java.io.OutputStreamWriter out = new java.io.OutputStreamWriter(outputStream, "UTF-8");
response.setContentType("text/xml; charset=UTF-8");
resultMessage.write(out);
out.flush();
out.close();
} else {
// Will throw cce when not a binary?
if (bin.getTypedValue() instanceof Binary) {
Binary b = (Binary) bin.getTypedValue();
response.setContentType(b.getMimeType());
if (b.getLength() > 0) {
response.setContentLength((int) b.getLength());
response.setHeader("Accept-Ranges", "none");
response.setHeader("Connection", "close");
}
copyResource(outputStream, b.getDataAsStream());
} else {
outputStream.write(bin.getValue().getBytes());
}
outputStream.flush();
}
} else {
java.io.OutputStreamWriter out = new java.io.OutputStreamWriter(outputStream, "UTF-8");
response.setContentType("text/xml; charset=UTF-8");
resultMessage.write(out);
out.flush();
out.close();
}
} catch (NavajoException e) {
logger.error("Error handling response: ", e);
} catch (IOException e) {
logger.error("Error handling response: ", e);
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
logger.warn("Stream closing problem", e);
}
}
}
}
use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class DomainObjectMapper method mapObjectToProperties.
/**
* Automatically maps all 'getters' to a property.
*
* Only add property if:
* 1. attribute 'getter' does not expect any arguments.
* 2. attribute has a 'getter'.
* 3. corresponding property does not already exist in message.
* 4. corresponding property is not in exclusion list.
* @throws Exception
*/
private void mapObjectToProperties(Class myClass) throws Exception {
java.lang.reflect.Method[] all = myClass.getMethods();
if (myAccess == null) {
return;
}
Navajo out = myAccess.getOutputDoc();
Message currentOutMsg = myAccess.getCurrentOutMessage();
if (currentOutMsg == null) {
throw new Exception("No current message for mapping object attributes to properties.");
}
for (int i = 0; i < all.length; i++) {
String attributeName = all[i].getName().substring(3);
if (all[i].getParameterTypes().length == 0 && all[i].getName().startsWith("get") && !all[i].getName().startsWith("getClass") && currentOutMsg.getProperty(attributeName) == null && !isAnExcludedProperty(attributeName)) {
Object result = all[i].invoke(myObject, (Object[]) null);
if (result == null || !(result.toString().startsWith("[L") || List.class.isAssignableFrom(result.getClass()))) {
Property p = NavajoFactory.getInstance().createProperty(out, attributeName, "string", "", 0, "", "", "");
p.setAnyValue(result);
p.setDirection(isAnInputProperty(attributeName) ? Property.DIR_IN : Property.DIR_OUT);
currentOutMsg.addProperty(p);
}
}
}
}
use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class MappingUtils method getSelectedItems.
public static final List<Selection> getSelectedItems(Message msg, Navajo doc, String msgName) throws NavajoException {
Property prop = null;
if (msg != null) {
prop = msg.getProperty(msgName);
} else {
prop = doc.getProperty(msgName);
}
if (!prop.getType().equals(Property.SELECTION_PROPERTY)) {
throw doc.getNavajoFactory().createNavajoException("Selection Property expected");
}
List<Selection> result = prop.getAllSelectedSelections();
return result;
}
use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class MappingUtils method isSelection.
public static final boolean isSelection(Message msg, Navajo doc, String msgName) {
Property prop = null;
if (msgName.startsWith(Navajo.MESSAGE_SEPARATOR)) {
// Absolute reference!
msg = null;
msgName = msgName.substring(1, msgName.length());
}
if (msg != null) {
prop = msg.getProperty(msgName);
} else {
prop = doc.getProperty(msgName);
}
if (prop == null) {
return false;
}
return prop.getType().equals(Property.SELECTION_PROPERTY);
}
Aggregations