Example usage for org.xml.sax.helpers NamespaceSupport declarePrefix

List of usage examples for org.xml.sax.helpers NamespaceSupport declarePrefix

Introduction

In this page you can find the example usage for org.xml.sax.helpers NamespaceSupport declarePrefix.

Prototype

public boolean declarePrefix(String prefix, String uri) 

Source Link

Document

Declare a Namespace prefix.

Usage

From source file:org.geoserver.gss.HTTPGSSClient.java

/**
 * Builds a XML encoder for the specified transaction. The code will declare all
 * prefix/namespace URI associations necessary for the elements in the transaction
 *//*w w  w.  jav a2 s  . co  m*/
Encoder buildEncoderForTransaction(TransactionType changes) throws IOException {
    Encoder encoder = new Encoder(configuration, configuration.getXSD().getSchema());

    // try to declare all namespace prefixes properly
    NamespaceSupport namespaces = encoder.getNamespaces();
    List<DeleteElementType> deletes = changes.getDelete();
    List<UpdateElementType> updates = changes.getUpdate();
    List<InsertElementType> inserts = changes.getInsert();
    for (DeleteElementType delete : deletes) {
        QName typeName = delete.getTypeName();
        namespaces.declarePrefix(typeName.getPrefix(), typeName.getNamespaceURI());
    }
    for (UpdateElementType update : updates) {
        QName typeName = update.getTypeName();
        namespaces.declarePrefix(typeName.getPrefix(), typeName.getNamespaceURI());
    }
    for (InsertElementType insert : inserts) {
        List<SimpleFeature> features = insert.getFeature();
        for (SimpleFeature feature : features) {
            Name typeName = feature.getType().getName();
            NamespaceInfo nsi = catalog.getNamespaceByURI(typeName.getNamespaceURI());
            if (nsi != null) {
                namespaces.declarePrefix(nsi.getPrefix(), nsi.getURI());
            }
        }
    }

    encoder.setEncoding(Charset.forName("UTF-8"));
    return encoder;
}

From source file:org.geoserver.wfs.notification.GMLNotificationSerializer.java

private static void loadNamespaceBindings(NamespaceSupport nss, XSDSchema schema, XSDSchema exclude) {
    Map excludePrefixes = exclude.getQNamePrefixToNamespaceMap();
    for (Map.Entry<String, String> e : ((Map<String, String>) schema.getQNamePrefixToNamespaceMap())
            .entrySet()) {/*from   w w w.  j a  v a 2 s . c  om*/
        if (excludePrefixes.containsKey(e.getKey()) || excludePrefixes.containsValue(e.getValue())) {
            continue;
        }
        String pref = e.getKey();
        nss.declarePrefix(pref == null ? "" : pref, e.getValue());
    }
}