Example usage for javax.xml.namespace QName getPrefix

List of usage examples for javax.xml.namespace QName getPrefix

Introduction

In this page you can find the example usage for javax.xml.namespace QName getPrefix.

Prototype

public String getPrefix() 

Source Link

Document

Get the prefix of this QName.

The prefix assigned to a QName might NOT be valid in a different context.

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
 *///from  ww w. j  a v a  2 s .  com
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.test.GeoServerAbstractTestSupport.java

/**
 * Given a qualified layer name returns a string in the form "prefix:localPart" if prefix
 * is available, "localPart" if prefix is null
 * @param layerName//from w  w w .  ja v a2s . c o m
 * @return
 */
public String getLayerId(QName layerName) {
    if (layerName.getPrefix() != null)
        return layerName.getPrefix() + ":" + layerName.getLocalPart();
    else
        return layerName.getLocalPart();
}

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

public String getDeleteRawMessage(QName typeName, Identifier id) {
    StringBuilder builder = new StringBuilder(1024);
    builder.append("<wfs:Delete xmlns:wfs=\"http://www.opengis.net/wfs\" xmlns:").append(typeName.getPrefix())
            .append("=\"").append(typeName.getNamespaceURI()).append("\" typeName=\"")
            .append(typeName.getPrefix()).append(":").append(typeName.getLocalPart()).append("\">")
            .append(id.getID()).append("</wfs:Delete>");

    return builder.toString();
}

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

protected final QName getLayerName(TransactionEvent event) {
    final QName layerName;
    QName name = event.getLayerName();
    // Normalize the QName if needed
    if (name.getPrefix() == null || name.getPrefix().length() == 0) {
        NamespaceInfo info = catalog.getNamespaceByURI(name.getNamespaceURI());
        if (info == null) {
            throw new NoSuchElementException("No such namespace in our catalog: " + name.getNamespaceURI());
        }//from  ww w .j a va 2 s .c om
        name = new QName(name.getNamespaceURI(), name.getLocalPart(), info.getPrefix());
    }
    layerName = name;
    return layerName;
}

From source file:org.geoserver.wms.dimension.RasterTimeDimensionDefaultValueTest.java

private void prepareFutureCoverageData(QName coverageName) throws IOException {
    SimpleDateFormat tsFormatter = new SimpleDateFormat("yyyyMMdd");

    // Prepare the target dates for the dummy coverages to be created
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));
    long justPast = cal.getTimeInMillis();

    cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1);
    long oneMonthInFuture = cal.getTimeInMillis();

    cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1);
    cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));

    cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 1);
    long oneYearInFuture = cal.getTimeInMillis();

    // Copy watertemp.zip test coverage resource in the data dir under a different name:
    GeoServerResourceLoader loader = getCatalog().getResourceLoader();
    File targetDir = loader.createDirectory(getDataDirectory().root(),
            coverageName.getPrefix() + File.separator + coverageName.getLocalPart());
    File target = new File(targetDir, coverageName.getLocalPart() + ".zip");
    loader.copyFromClassPath("org/geoserver/wms/dimension/watertemp.zip", target);

    // unpack the archive
    IOUtils.decompress(target, targetDir);

    // delete archive
    target.delete();/*from w  ww  . ja  v  a  2  s.  com*/

    // Make three new dummy coverage files with the needed timestamps:
    File input = null;
    File output = null;
    FilenameFilter tiffFilter = new DefaultFileFilter("*.tiff");
    String[] tiffnames = targetDir.list(tiffFilter);

    if (tiffnames != null) {
        if (tiffnames.length > 0) {
            input = new File(targetDir, tiffnames[0]);
            output = new File(targetDir,
                    "DUMMY_watertemp_000_" + tsFormatter.format(new Date(justPast)) + "T0000000_12.tiff");
            FileUtils.copyFile(input, output);

            output = new File(targetDir, "DUMMY_watertemp_000_" + tsFormatter.format(new Date(oneMonthInFuture))
                    + "T0000000_12.tiff");
            FileUtils.copyFile(input, output);

            output = new File(targetDir, "DUMMY_watertemp_000_" + tsFormatter.format(new Date(oneYearInFuture))
                    + "T0000000_12.tiff");
            FileUtils.copyFile(input, output);
        }
    }
    addRasterLayerFromDataDir(WATTEMP_FUTURE, getCatalog());

}

From source file:org.geoserver.wms.dimension.RasterTimeDimensionDefaultValueTest.java

private void addRasterLayerFromDataDir(QName qName, Catalog catalog) throws IOException {
    String prefix = qName.getPrefix();
    String name = qName.getLocalPart();

    // setup the data
    File file = new File(this.getDataDirectory().root() + File.separator + prefix, name);

    if (!file.exists()) {
        throw new IllegalArgumentException(
                "There is no file with name '" + prefix + File.separator + name + "' in the data directory");
    }// ww w.j  a  v a2  s  . c o m

    // load the format/reader
    AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(file);
    if (format == null) {
        throw new RuntimeException("No format for " + file.getCanonicalPath());
    }
    GridCoverage2DReader reader = null;
    try {
        reader = (GridCoverage2DReader) format.getReader(file);
        if (reader == null) {
            throw new RuntimeException(
                    "No reader for " + file.getCanonicalPath() + " with format " + format.getName());
        }

        // configure workspace if it doesn't already exist
        if (catalog.getWorkspaceByName(prefix) == null) {
            ((SystemTestData) this.testData).addWorkspace(prefix, qName.getNamespaceURI(), catalog);
        }
        // create the store
        CoverageStoreInfo store = catalog.getCoverageStoreByName(prefix, name);
        if (store == null) {
            store = catalog.getFactory().createCoverageStore();
        }

        store.setName(name);
        store.setWorkspace(catalog.getWorkspaceByName(prefix));
        store.setEnabled(true);
        store.setURL(DataUtilities.fileToURL(file).toString());
        store.setType(format.getName());

        if (store.getId() == null) {
            catalog.add(store);
        } else {
            catalog.save(store);
        }

        // create the coverage
        CatalogBuilder builder = new CatalogBuilder(catalog);
        builder.setStore(store);

        CoverageInfo coverage = null;

        try {

            coverage = builder.buildCoverage(reader, null);
            // coverage read params
            if (format instanceof ImageMosaicFormat) {
                // make sure we work in immediate mode
                coverage.getParameters().put(AbstractGridFormat.USE_JAI_IMAGEREAD.getName().getCode(),
                        Boolean.FALSE);
            }
        } catch (Exception e) {
            throw new IOException(e);
        }

        coverage.setName(name);
        coverage.setTitle(name);
        coverage.setDescription(name);
        coverage.setEnabled(true);

        CoverageInfo cov = catalog.getCoverageByCoverageStore(store, name);
        if (cov == null) {
            catalog.add(coverage);
        } else {
            builder.updateCoverage(cov, coverage);
            catalog.save(cov);
            coverage = cov;
        }

        LayerInfo layer = catalog.getLayerByName(new NameImpl(qName));
        if (layer == null) {
            layer = catalog.getFactory().createLayer();
        }
        layer.setResource(coverage);

        layer.setDefaultStyle(catalog.getStyleByName(SystemTestData.DEFAULT_RASTER_STYLE));
        layer.setType(LayerInfo.Type.RASTER);
        layer.setEnabled(true);

        if (layer.getId() == null) {
            catalog.add(layer);
        } else {
            catalog.save(layer);
        }
    } finally {
        if (reader != null) {
            reader.dispose();
        }
    }
}

From source file:org.geotools.data.complex.config.AppSchemaDataAccessConfigurator.java

/**
 * Throws an IllegalArgumentException if some Step in the given xpath StepList has a prefix for
 * which no prefix to namespace mapping were provided (as in the Namespaces section of the
 * mappings xml configuration file)/*from  w ww  .j  a v  a 2 s .co m*/
 * 
 * @param targetXPathSteps
 */
private void validateConfiguredNamespaces(StepList targetXPathSteps) {
    for (Iterator it = targetXPathSteps.iterator(); it.hasNext();) {
        Step step = (Step) it.next();
        QName name = step.getName();
        if (!XMLConstants.DEFAULT_NS_PREFIX.equals(name.getPrefix())) {
            if (XMLConstants.DEFAULT_NS_PREFIX.equals(name.getNamespaceURI())) {
                throw new IllegalArgumentException("location step " + step + " has prefix " + name.getPrefix()
                        + " for which no namespace was set. "
                        + "(Check the Namespaces section in the config file)");
            }
        }
    }
}

From source file:org.geotools.data.wfs.v1_1_0.WFS_1_1_0_Protocol.java

public WFS_1_1_0_Protocol(InputStream capabilitiesReader, HTTPClient http, Charset defaultEncoding)
        throws IOException {
    this.defaultEncoding = defaultEncoding;
    this.strategy = new DefaultWFSStrategy();
    this.capabilities = parseCapabilities(capabilitiesReader);
    this.http = http;
    this.typeInfos = new HashMap<String, FeatureTypeType>();

    final List<FeatureTypeType> ftypes = capabilities.getFeatureTypeList().getFeatureType();
    QName typeName;
    for (FeatureTypeType ftype : ftypes) {
        typeName = ftype.getName();/*from  w w  w.j  a v  a  2s  .com*/
        assert !("".equals(typeName.getPrefix()));
        String prefixedTypeName = typeName.getPrefix() + ":" + typeName.getLocalPart();
        typeInfos.put(prefixedTypeName, ftype);
    }
}

From source file:org.geotools.data.wfs.v1_1_0.WFS_1_1_0_Protocol.java

/**
 * @see WFSProtocol#getFeaturePOST(Query, String)
 *//*from  w  ww.  j  av a 2 s  . c o  m*/
public WFSResponse issueGetFeaturePOST(final GetFeature request) throws IOException {
    if (!supportsOperation(WFSOperationType.GET_FEATURE, true)) {
        throw new UnsupportedOperationException("The server does not support GetFeature for HTTP method POST");
    }
    URL postURL = getOperationURL(WFSOperationType.GET_FEATURE, true);

    // support vendor parameters, GeoServer way
    if (request instanceof GetFeatureQueryAdapter) {
        GetFeatureQueryAdapter adapter = (GetFeatureQueryAdapter) request;
        if (adapter.getVendorParameter() != null) {
            String url = postURL.toString();
            if ((url == null) || !url.endsWith("?")) {
                url += "?";
            }

            boolean first = true;
            for (Map.Entry<String, String> entry : adapter.getVendorParameter().entrySet()) {
                if (first) {
                    first = false;
                } else {
                    url += "&";
                }
                url += entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), "UTF-8");
            }

            postURL = new URL(url);
        }
    }

    RequestComponents reqParts = strategy.createGetFeatureRequest(this, request);
    GetFeatureType serverRequest = reqParts.getServerRequest();

    Encoder encoder = new Encoder(strategy.getWfsConfiguration());

    // If the typeName is of the form prefix:typeName we better declare the namespace since we
    // don't know how picky the server parser will be
    String typeName = reqParts.getKvpParameters().get("TYPENAME");
    QName fullName = getFeatureTypeName(typeName);
    String prefix = fullName.getPrefix();
    String namespace = fullName.getNamespaceURI();
    if (!XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
        encoder.getNamespaces().declarePrefix(prefix, namespace);
    }
    WFSResponse response = issuePostRequest(serverRequest, postURL, encoder);

    return response;
}

From source file:org.geotools.data.wfs.v1_1_0.WFS_1_1_0_Protocol.java

private URL getDescribeFeatureTypeURLGet(String typeName, String outputFormat) {
    final FeatureTypeType typeInfo = getFeatureTypeInfo(typeName);

    final URL describeFeatureTypeUrl = getOperationURL(DESCRIBE_FEATURETYPE, false);

    Map<String, String> kvp = new HashMap<String, String>();
    kvp.put("SERVICE", "WFS");
    kvp.put("VERSION", getServiceVersion().toString());
    kvp.put("REQUEST", "DescribeFeatureType");
    kvp.put("TYPENAME", typeName);

    QName name = typeInfo.getName();
    if (!XMLConstants.DEFAULT_NS_PREFIX.equals(name.getPrefix())) {
        String nsUri = name.getNamespaceURI();
        kvp.put("NAMESPACE", "xmlns(" + name.getPrefix() + "=" + nsUri + ")");
    }//from w ww .j ava2 s  .c  o m

    // ommit output format by now, server should just return xml shcema
    // kvp.put("OUTPUTFORMAT", outputFormat);

    URL url;
    try {
        url = createUrl(describeFeatureTypeUrl, kvp);
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
    return url;
}