Example usage for org.apache.commons.lang StringUtils defaultIfEmpty

List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfEmpty.

Prototype

public static String defaultIfEmpty(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is empty or null, the value of defaultStr.

Usage

From source file:org.carrot2.workbench.core.WorkbenchCorePlugin.java

/**
 * Scan all declared extensions of {@link #COMPONENT_SUITE_EXTENSION_ID} extension
 * point./*  ww  w .j  a  va  2 s .c  o m*/
 */
private void scanSuites() {
    final List<ProcessingComponentSuite> suites = Lists.newArrayList();

    final IExtension[] extensions = Platform.getExtensionRegistry()
            .getExtensionPoint(COMPONENT_SUITE_EXTENSION_ID).getExtensions();

    // Load suites from extension points.
    for (IExtension extension : extensions) {
        final IConfigurationElement[] configElements = extension.getConfigurationElements();
        if (configElements.length == 1 && "suite".equals(configElements[0].getName())) {
            String suiteRoot = configElements[0].getAttribute("resourceRoot");
            if (StringUtils.isEmpty(suiteRoot))
                suiteRoot = "";

            final String suiteResourceName = configElements[0].getAttribute("resource");
            if (StringUtils.isEmpty(suiteResourceName)) {
                continue;
            }

            String bundleId = configElements[0].getAttribute("bundleId");
            if (StringUtils.isEmpty(bundleId)) {
                final IContributor c = extension.getContributor();
                bundleId = c.getName();
            }

            final Bundle b = Platform.getBundle(bundleId);
            if (b == null) {
                Utils.logError("Suite's bundle not found: " + bundleId, false);
                continue;
            }

            if (b.getState() != Bundle.ACTIVE) {
                try {
                    b.start();
                } catch (BundleException e) {
                    Utils.logError("Bundle inactive: " + bundleId, false);
                    continue;
                }
            }

            final ResourceLookup resourceLookup = new ResourceLookup(workspaceLocator,
                    new PrefixDecoratorLocator(new BundleResourceLocator(b), suiteRoot));

            IResource suiteResource = resourceLookup.getFirst(suiteResourceName);
            if (suiteResource == null) {
                String message = "Suite extension resource not found in " + b.getSymbolicName() + ": "
                        + bundleId;
                Utils.logError(message, false);
                continue;
            }

            /* This piece of code is currently quite fragile and hacky, but works. 
             * 
             * First, we rely on Eclipse-BuddyPolicy declared on the simplexml framework
             * to instantiate arbitrary classes (from sources and algorithms). 
             * This policy could be removed if we passed an explicit Persister
             * with a strategy substituting the context class loader with the given
             * Bundle's loadClass() call. I leave it for now.
             * 
             * We use a custom resource locator that searches the contributing
             * plugin for resources matching the included resource.
             */
            try {
                final ProcessingComponentSuite suite = ProcessingComponentSuite.deserialize(suiteResource,
                        resourceLookup);

                /*
                 * Remove invalid descriptors, cache icons.
                 */
                failed.addAll(suite.removeUnavailableComponents());
                for (ProcessingComponentDescriptor d : suite.getComponents()) {
                    final String iconPath = d.getIconPath();
                    if (StringUtils.isEmpty(iconPath)) {
                        continue;
                    }

                    componentImages.put(d.getId(), imageDescriptorFromPlugin(bundleId, iconPath));
                }

                suites.add(suite);
            } catch (Exception e) {
                // Skip errors, logging them.
                Utils.logError("Failed to load suite extension.", e, false);
            }
        }
    }

    // Merge all available suites
    final ArrayList<DocumentSourceDescriptor> sources = Lists.newArrayList();
    final ArrayList<ProcessingComponentDescriptor> algorithms = Lists.newArrayList();

    for (ProcessingComponentSuite s : suites) {
        sources.addAll(s.getSources());
        algorithms.addAll(s.getAlgorithms());
    }

    this.componentSuite = new ProcessingComponentSuite(sources, algorithms);

    // Extract and cache bindableDescriptors.
    for (ProcessingComponentDescriptor pcd : componentSuite.getComponents()) {
        try {
            final String id = pcd.getId();
            BindableDescriptor bindableDescriptor = pcd.getBindableDescriptor();
            bindableDescriptors.put(id, bindableDescriptor);
            processingDescriptors.put(id, pcd);
        } catch (Exception e) {
            Utils.logError("Failed to extract descriptor from: " + pcd.getId(), e, false);
        }
    }

    /*
     * Log errors.
     */
    if (!failed.isEmpty()) {
        for (ProcessingComponentDescriptor d : failed) {
            getLog().log(
                    new Status(
                            Status.ERROR, PLUGIN_ID, "Plugin loading failure: " + d.getId() + " ("
                                    + d.getTitle() + ")" + "\n" + StringUtils.defaultIfEmpty(
                                            d.getInitializationFailure().getMessage(), "(no message)"),
                            d.getInitializationFailure()));
        }
    }
}

From source file:org.codice.ddf.security.interceptor.AnonymousInterceptor.java

private void createAddressing(SoapMessage message, SOAPMessage soapMessage, SOAPFactory soapFactory) {

    String addressingProperty = org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_INBOUND;
    AddressingProperties addressingProperties = new AddressingProperties();
    SOAPElement action = null;/*from   w  w w  .ja  v a  2 s  .  c  o  m*/

    try {
        action = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ACTION_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        action.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        AttributedURIType attributedString = new AttributedURIType();
        String actionValue = StringUtils.defaultIfEmpty((String) message.get(SoapBindingConstants.SOAP_ACTION),
                "");
        attributedString.setValue(actionValue);
        addressingProperties.setAction(attributedString);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing action.", e);
    }

    SOAPElement messageId = null;
    try {
        messageId = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_MESSAGEID_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        String uuid = "urn:uuid:" + UUID.randomUUID().toString();
        messageId.addTextNode(uuid);
        AttributedURIType attributedString = new AttributedURIType();
        attributedString.setValue(uuid);
        addressingProperties.setMessageID(attributedString);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing action.", e);
    }

    SOAPElement to = null;
    try {
        to = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_TO_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        to.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        EndpointReferenceType endpointReferenceType = new EndpointReferenceType();
        AttributedURIType attributedString = new AttributedURIType();
        attributedString.setValue((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        endpointReferenceType.setAddress(attributedString);
        addressingProperties.setTo(endpointReferenceType);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing action.", e);
    }

    SOAPElement replyTo = null;
    try {
        replyTo = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_REPLYTO_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        SOAPElement address = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ADDRESS_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        address.addTextNode(org.apache.cxf.ws.addressing.Names.WSA_ANONYMOUS_ADDRESS);
        replyTo.addChildElement(address);

        soapMessage.getSOAPHeader().addChildElement(messageId);
        soapMessage.getSOAPHeader().addChildElement(action);
        soapMessage.getSOAPHeader().addChildElement(to);
        soapMessage.getSOAPHeader().addChildElement(replyTo);
        message.put(addressingProperty, addressingProperties);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing action.", e);
    }
}

From source file:org.codice.ddf.security.interceptor.GuestInterceptor.java

private void createAddressing(SoapMessage message, SOAPMessage soapMessage) {
    SOAPFactory soapFactory;/*from   www .  j av  a 2 s  . co m*/
    try {
        soapFactory = SOAPFactory.newInstance();
    } catch (SOAPException e) {
        LOGGER.error("Could not create a SOAPFactory.", e);
        return; // can't add anything if we can't create it
    }

    String addressingProperty = org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_INBOUND;
    AddressingProperties addressingProperties = new AddressingProperties();

    try {
        SOAPElement action = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ACTION_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        action.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        AttributedURIType attributedString = new AttributedURIType();
        String actionValue = StringUtils.defaultIfEmpty((String) message.get(SoapBindingConstants.SOAP_ACTION),
                "");
        attributedString.setValue(actionValue);
        addressingProperties.setAction(attributedString);
        soapMessage.getSOAPHeader().addChildElement(action);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing action.", e);
    }

    try {
        SOAPElement messageId = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_MESSAGEID_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        String uuid = "urn:uuid:" + UUID.randomUUID().toString();
        messageId.addTextNode(uuid);
        AttributedURIType attributedString = new AttributedURIType();
        attributedString.setValue(uuid);
        addressingProperties.setMessageID(attributedString);
        soapMessage.getSOAPHeader().addChildElement(messageId);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing messageId.", e);
    }

    try {
        SOAPElement to = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_TO_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        to.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        EndpointReferenceType endpointReferenceType = new EndpointReferenceType();
        AttributedURIType attributedString = new AttributedURIType();
        attributedString.setValue((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        endpointReferenceType.setAddress(attributedString);
        addressingProperties.setTo(endpointReferenceType);
        soapMessage.getSOAPHeader().addChildElement(to);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing to.", e);
    }

    try {
        SOAPElement replyTo = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_REPLYTO_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        SOAPElement address = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ADDRESS_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        address.addTextNode(org.apache.cxf.ws.addressing.Names.WSA_ANONYMOUS_ADDRESS);
        replyTo.addChildElement(address);
        soapMessage.getSOAPHeader().addChildElement(replyTo);

    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing replyTo.", e);
    }
    message.put(addressingProperty, addressingProperties);
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction.java

/**
 * Constructs a DeleteAction with a {@link DeleteType} and a map of XML namespace prefixes to
 * their respective URIs. The map should contain the prefix to URI mappings declared in the
 * transaction request XML./*from  www.j a v a  2s .c  o  m*/
 * <p>
 * If an error occurs while processing this delete action, {@link DeleteType#handle} will be
 * included in the exception report response so the specific action within the transaction that
 * caused the error can be identified.
 *
 * @param deleteType          the {@code DeleteType} representing the delete action
 * @param prefixToUriMappings the map that contains the XML namespace prefix to URI mappings
 *                            declared in the transaction request XML
 */
public DeleteAction(DeleteType deleteType, Map<String, String> prefixToUriMappings) {
    super(StringUtils.defaultIfEmpty(deleteType.getTypeName(), CswConstants.CSW_RECORD),
            StringUtils.defaultIfEmpty(deleteType.getHandle(), ""));
    queryConstraintType = deleteType.getConstraint();
    this.prefixToUriMappings = prefixToUriMappings;
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteActionImpl.java

/**
 * Constructs a DeleteActionImpl with a {@link DeleteType} and a map of XML namespace prefixes to
 * their respective URIs. The map should contain the prefix to URI mappings declared in the
 * transaction request XML./*w ww . j  a v  a 2 s  . c  o m*/
 *
 * <p>If an error occurs while processing this delete action, {@link DeleteType#handle} will be
 * included in the exception report response so the specific action within the transaction that
 * caused the error can be identified.
 *
 * @param deleteType the {@code DeleteType} representing the delete action
 * @param prefixToUriMappings the map that contains the XML namespace prefix to URI mappings
 *     declared in the transaction request XML
 */
public DeleteActionImpl(DeleteType deleteType, Map<String, String> prefixToUriMappings) {
    this.typeName = StringUtils.defaultIfEmpty(deleteType.getTypeName(), CswConstants.CSW_RECORD);
    this.handle = StringUtils.defaultIfEmpty(deleteType.getHandle(), "");
    this.queryConstraintType = deleteType.getConstraint();
    this.prefixToUriMappings = prefixToUriMappings;
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.GmdConverter.java

/**
 * Builds up the xml paths and values to write.
 * Order matters!  Paths should be added in the order they must be written.
 *
 * @param metacard//from ww w  .  ja va  2  s  .  c  om
 * @return XstreamPathValueTracker containing XML paths and values to write
 */
protected XstreamPathValueTracker buildPaths(MetacardImpl metacard) {

    XstreamPathValueTracker pathValueTracker = new XstreamPathValueTracker();

    pathValueTracker.add(new Path("/MD_Metadata/@xmlns"), GmdMetacardType.GMD_NAMESPACE);

    pathValueTracker.add(new Path("/MD_Metadata/@xmlns:" + GmdMetacardType.GCO_PREFIX),
            GmdMetacardType.GCO_NAMESPACE);
    pathValueTracker.add(new Path(GmdMetacardType.FILE_IDENTIFIER_PATH), metacard.getId());

    pathValueTracker.add(new Path(GmdMetacardType.CODE_LIST_VALUE_PATH),
            StringUtils.defaultIfEmpty(metacard.getContentTypeName(), "dataset"));
    pathValueTracker.add(new Path(GmdMetacardType.CODE_LIST_PATH), GmdMetacardType.METACARD_URI);

    pathValueTracker.add(new Path(GmdMetacardType.CONTACT_PATH), (String) null);

    GregorianCalendar modifiedCal = new GregorianCalendar();
    if (metacard.getModifiedDate() != null) {

        modifiedCal.setTime(metacard.getModifiedDate());
    }
    modifiedCal.setTimeZone(UTC_TIME_ZONE);

    pathValueTracker.add(new Path(GmdMetacardType.DATE_TIME_STAMP_PATH),
            XSD_FACTORY.newXMLGregorianCalendar(modifiedCal).toXMLFormat());

    addIdentificationInfo(metacard, pathValueTracker);

    addDistributionInfo(metacard, pathValueTracker);

    return pathValueTracker;

}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.GmdConverter.java

protected void addIdentificationInfo(MetacardImpl metacard, XstreamPathValueTracker pathValueTracker) {

    pathValueTracker.add(new Path(GmdMetacardType.TITLE_PATH), StringUtils.defaultString(metacard.getTitle()));

    GregorianCalendar createdCal = new GregorianCalendar();

    if (metacard.getCreatedDate() != null) {

        createdCal.setTime(metacard.getCreatedDate());
    }/*from www.j ava  2 s.  com*/
    createdCal.setTimeZone(UTC_TIME_ZONE);
    pathValueTracker.add(new Path(GmdMetacardType.CREATED_DATE_PATH),
            XSD_FACTORY.newXMLGregorianCalendar(createdCal).toXMLFormat());

    pathValueTracker.add(new Path(GmdMetacardType.CREATED_DATE_TYPE_CODE_PATH), GmdMetacardType.METACARD_URI);
    pathValueTracker.add(new Path(GmdMetacardType.CREATED_DATE_TYPE_CODE_VALUE_PATH), Metacard.CREATED);

    pathValueTracker.add(new Path(GmdMetacardType.ABSTRACT_PATH),
            StringUtils.defaultString(metacard.getDescription()));
    pathValueTracker.add(new Path(GmdMetacardType.POINT_OF_CONTACT_PATH),
            StringUtils.defaultString(metacard.getPointOfContact()));

    pathValueTracker.add(new Path(GmdMetacardType.POINT_OF_CONTACT_ROLE_PATH), (String) null);

    pathValueTracker.add(new Path(GmdMetacardType.LANGUAGE_PATH),
            StringUtils.defaultIfEmpty(Locale.getDefault().getLanguage(), Locale.ENGLISH.getLanguage()));
    addExtent(metacard, pathValueTracker);

}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.TransactionRequestConverter.java

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    CswTransactionRequest cswTransactionRequest = new CswTransactionRequest();

    cswTransactionRequest.setVersion(reader.getAttribute(CswConstants.VERSION));
    cswTransactionRequest.setService(reader.getAttribute(CswConstants.SERVICE));
    cswTransactionRequest.setVerbose(Boolean.valueOf(reader.getAttribute(CswConstants.VERBOSE_RESPONSE)));

    XStreamAttributeCopier.copyXmlNamespaceDeclarationsIntoContext(reader, context);

    while (reader.hasMoreChildren()) {
        reader.moveDown();// www  . j  a v  a2 s  .c  o  m

        if (reader.getNodeName().contains("Insert")) {
            String typeName = StringUtils.defaultIfEmpty(reader.getAttribute(CswConstants.TYPE_NAME_PARAMETER),
                    CswConstants.CSW_RECORD);
            String handle = StringUtils.defaultIfEmpty(reader.getAttribute(CswConstants.HANDLE_PARAMETER), "");
            context.put(CswConstants.TRANSFORMER_LOOKUP_KEY, TransformerManager.ID);
            context.put(CswConstants.TRANSFORMER_LOOKUP_VALUE, typeName);
            List<Metacard> metacards = new ArrayList<>();
            // Loop through the individual records to be inserted, converting each into a Metacard
            while (reader.hasMoreChildren()) {
                reader.moveDown(); // move down to the record's tag
                Metacard metacard = (Metacard) context.convertAnother(null, MetacardImpl.class,
                        delegatingTransformer);
                if (metacard != null) {
                    metacards.add(metacard);
                }

                // move back up to the <SearchResults> parent of the <csw:Record> tags
                reader.moveUp();
            }
            cswTransactionRequest.getInsertActions().add(new InsertAction(typeName, handle, metacards));
        } else if (reader.getNodeName().contains("Delete")) {
            XStreamAttributeCopier.copyXmlNamespaceDeclarationsIntoContext(reader, context);

            Map<String, String> xmlnsAttributeToUriMappings = getXmlnsAttributeToUriMappingsFromContext(
                    context);
            Map<String, String> prefixToUriMappings = getPrefixToUriMappingsFromXmlnsAttributes(
                    xmlnsAttributeToUriMappings);

            StringWriter writer = new StringWriter();
            XStreamAttributeCopier.copyXml(reader, writer, xmlnsAttributeToUriMappings);

            DeleteType deleteType = getElementFromXml(writer.toString(), DeleteType.class);

            cswTransactionRequest.getDeleteActions().add(new DeleteAction(deleteType, prefixToUriMappings));
        } else if (reader.getNodeName().contains("Update")) {
            XStreamAttributeCopier.copyXmlNamespaceDeclarationsIntoContext(reader, context);
            UpdateAction updateAction = parseUpdateAction(reader, context);
            cswTransactionRequest.getUpdateActions().add(updateAction);
        }
        reader.moveUp();
    }

    return cswTransactionRequest;
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.TransactionRequestConverter.java

private UpdateAction parseUpdateAction(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Map<String, String> xmlnsAttributeToUriMappings = getXmlnsAttributeToUriMappingsFromContext(context);
    Map<String, String> prefixToUriMappings = getPrefixToUriMappingsFromXmlnsAttributes(
            xmlnsAttributeToUriMappings);

    String typeName = StringUtils.defaultIfEmpty(reader.getAttribute(CswConstants.TYPE_NAME_PARAMETER),
            CswConstants.CSW_RECORD);/*w ww  .  j  a  v a2  s  .  com*/
    String handle = StringUtils.defaultIfEmpty(reader.getAttribute(CswConstants.HANDLE_PARAMETER), "");

    // Move down to the content of the <Update>.
    reader.moveDown();

    UpdateAction updateAction;

    // Do we have a list of <RecordProperty> elements or a new <csw:Record>?
    if (reader.getNodeName().contains("RecordProperty")) {
        Map<String, Serializable> cswRecordProperties = new HashMap<>();

        while (reader.getNodeName().contains("RecordProperty")) {
            String cswField;
            Serializable newValue = null;

            // Move down to the <Name>.
            reader.moveDown();
            if (reader.getNodeName().contains("Name")) {
                String attribute = reader.getValue();
                cswField = CswRecordConverter.getCswAttributeFromAttributeName(attribute);
            } else {
                throw new ConversionException("Missing Parameter Value: missing a Name in a RecordProperty.");
            }
            // Move back up to the <RecordProperty>.
            reader.moveUp();

            // Is there a <Value>?
            if (reader.hasMoreChildren()) {
                // Move down to the <Value>.
                reader.moveDown();

                if (reader.getNodeName().contains("Value")) {
                    newValue = getRecordPropertyValue(reader, cswField);
                } else {
                    throw new ConversionException(
                            "Invalid Parameter Value: invalid element in a RecordProperty.");
                }

                // Back to the <RecordProperty>.
                reader.moveUp();
            }

            cswRecordProperties.put(cswField, newValue);

            // Back to the <Update>, look for the next <RecordProperty>.
            reader.moveUp();

            if (!reader.hasMoreChildren()) {
                // If there aren't any more children of the <Update>, that means there's no
                // Constraint, which is required.
                throw new ConversionException("Missing Parameter Value: missing a Constraint.");
            }

            // What's the next element in the <Update>?
            reader.moveDown();
        }

        // Now there should be a <Constraint> element.
        if (reader.getNodeName().contains("Constraint")) {
            StringWriter writer = new StringWriter();
            XStreamAttributeCopier.copyXml(reader, writer, xmlnsAttributeToUriMappings);

            QueryConstraintType constraint = getElementFromXml(writer.toString(), QueryConstraintType.class);

            // For any CSW attributes that map to basic metacard attributes (e.g. title,
            // modified date, etc.), update the basic metacard attributes as well.
            Map<String, String> cswToMetacardAttributeNames = DefaultCswRecordMap.getDefaultCswRecordMap()
                    .getCswToMetacardAttributeNames();
            Map<String, Serializable> cswRecordPropertiesWithMetacardAttributes = new HashMap<>(
                    cswRecordProperties);

            for (Entry<String, Serializable> recordProperty : cswRecordProperties.entrySet()) {
                String cswAttributeName = recordProperty.getKey();

                // If this CSW attribute maps to a basic metacard attribute, attempt to set the
                // basic metacard attribute.
                if (cswToMetacardAttributeNames.containsKey(cswAttributeName)) {
                    String metacardAttrName = cswToMetacardAttributeNames.get(cswAttributeName);
                    // If this basic metacard attribute hasn't already been set, set it.
                    if (!cswRecordPropertiesWithMetacardAttributes.containsKey(metacardAttrName)) {
                        Attribute metacardAttr = CswRecordConverter.getMetacardAttributeFromCswAttribute(
                                cswAttributeName, recordProperty.getValue(), metacardAttrName);
                        cswRecordPropertiesWithMetacardAttributes.put(metacardAttrName,
                                metacardAttr.getValue());
                    }
                }
            }

            updateAction = new UpdateAction(cswRecordPropertiesWithMetacardAttributes, typeName, handle,
                    constraint, prefixToUriMappings);
        } else {
            throw new ConversionException("Missing Parameter Value: missing a Constraint.");
        }
    } else {
        context.put(CswConstants.TRANSFORMER_LOOKUP_KEY, TransformerManager.ID);
        context.put(CswConstants.TRANSFORMER_LOOKUP_VALUE, typeName);
        Metacard metacard = (Metacard) context.convertAnother(null, MetacardImpl.class, delegatingTransformer);

        updateAction = new UpdateAction(metacard, typeName, handle);
        // Move back to the <Update>.
        reader.moveUp();
    }

    return updateAction;
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.reader.TransactionRequestConverter.java

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    CswTransactionRequest cswTransactionRequest = new CswTransactionRequest();

    cswTransactionRequest.setVersion(reader.getAttribute("version"));
    cswTransactionRequest.setService(reader.getAttribute("service"));
    cswTransactionRequest.setVerbose(Boolean.valueOf(reader.getAttribute("verboseResponse")));
    while (reader.hasMoreChildren()) {
        reader.moveDown();// w w w  .  j  a  va2s  .  c o m

        if (reader.getNodeName().contains("Insert")) {
            String typeName = StringUtils.defaultIfEmpty(reader.getAttribute("typeName"),
                    CswConstants.CSW_RECORD);
            String handle = StringUtils.defaultIfEmpty(reader.getAttribute("handle"), "");
            List<Metacard> metacards = new ArrayList<>();
            // Loop through the <SearchResults>, converting each <csw:Record> into a Metacard
            while (reader.hasMoreChildren()) {
                reader.moveDown(); // move down to the <csw:Record> tag
                String name = reader.getNodeName();
                Metacard metacard = (Metacard) context.convertAnother(null, MetacardImpl.class,
                        cswRecordConverter);
                if (metacard != null) {
                    metacards.add(metacard);
                }

                // move back up to the <SearchResults> parent of the <csw:Record> tags
                reader.moveUp();
            }
            cswTransactionRequest.setInsertTransaction(new InsertTransaction(typeName, handle, metacards));
        }
        reader.moveUp();
    }

    return cswTransactionRequest;
}