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.codice.ddf.spatial.ogc.wfs.catalog.endpoint.TestWfsEndpoint.java

@Test
public void testDescribeFeatureTypeWithNamespacePrefix() throws WfsException {
    DescribeFeatureTypeRequest request = new DescribeFeatureTypeRequest();
    QName qname = WfsQnameBuilder.buildQName(MetacardType.DEFAULT_METACARD_TYPE_NAME, CONTENT_TYPE);
    request.setTypeName(qname.getPrefix() + ":" + qname.getLocalPart());
    XmlSchema schema = wfs.describeFeatureType(request);
    assertNotNull(schema);//from www  .  j  a  v  a2 s.c om
}

From source file:org.codice.ddf.spatial.ogc.wfs.catalog.endpoint.WfsEndpoint.java

private XmlSchema buildMultipleFeatureTypeImportSchema(Set<QName> qnames) throws WfsException {
    XmlSchema schema = new XmlSchema("", new XmlSchemaCollection());
    schema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
    schema.setTargetNamespace(XmlSchemaSerializer.XSD_NAMESPACE);
    NamespaceMap nsMap = new NamespaceMap();
    nsMap.add("", XmlSchemaSerializer.XSD_NAMESPACE);
    schema.setNamespaceContext(nsMap);/* www. j ava 2  s  .  c o m*/
    for (QName qName : qnames) {
        XmlSchemaImport schemaImport = new XmlSchemaImport(schema);
        schemaImport.setNamespace(qName.getNamespaceURI());
        URI fullUri = UriBuilder.fromUri(uri.getBaseUri())
                .queryParam("request", Wfs10Constants.DESCRIBE_FEATURE_TYPE)
                .queryParam("version", Wfs10Constants.VERSION_1_0_0).queryParam("service", Wfs10Constants.WFS)
                .queryParam("typeName", (StringUtils.isEmpty(qName.getPrefix())) ? qName.getLocalPart()
                        : qName.getPrefix() + ":" + qName.getLocalPart())
                .build();
        schemaImport.setSchemaLocation(fullUri.toString());
        schema.getExternals().add(schemaImport);
    }
    return schema;
}

From source file:org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.converter.impl.GenericFeatureConverterWfs20.java

/**
 * This method will convert a {@link Metacard} instance into xml that will validate against the
 * GML 2.1.2 AbstractFeatureType./*  www . j  a v a2s.c  o m*/
 *
 * @param value
 *            the {@link Metacard} to convert
 * @param writer
 *            the stream writer responsible for writing this xml doc
 * @param context
 *            a reference back to the Xstream marshalling context. Allows you to call
 *            "convertAnother" which will lookup other registered converters.
 */
@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    Metacard metacard = (Metacard) value;

    // TODO when we have a reference to the MCT we can get the namespace too
    QName qname = WfsQnameBuilder.buildQName(metacard.getMetacardType().getName(),
            metacard.getContentTypeName());

    writer.startNode(qname.getPrefix() + ":" + qname.getLocalPart());

    // Add the "id" attribute if we have an ID
    if (metacard.getAttribute(Metacard.ID).getValue() != null) {
        String id = (String) metacard.getAttribute(Metacard.ID).getValue();
        writer.addAttribute(ID, id);
    }

    if (null != metacard.getLocation()) {
        Geometry geo = XmlNode.readGeometry(metacard.getLocation());
        if (geo != null && !geo.isEmpty()) {
            XmlNode.writeEnvelope(WfsConstants.GML_PREFIX + ":" + "boundedBy", context, writer,
                    geo.getEnvelopeInternal());
        }
    }

    Set<AttributeDescriptor> descriptors = new TreeSet<AttributeDescriptor>(
            new AttributeDescriptorComparator());
    descriptors.addAll(metacard.getMetacardType().getAttributeDescriptors());

    for (AttributeDescriptor attributeDescriptor : descriptors) {
        Attribute attribute = metacard.getAttribute(attributeDescriptor.getName());
        if (attribute != null) {
            writeAttributeToXml(attribute, qname, attributeDescriptor.getType().getAttributeFormat(), context,
                    writer);
        }
    }
    writer.endNode();
}

From source file:org.deegree.services.wfs.query.QueryAnalyzer.java

/**
 * Returns whether the propName has to be considered for re-qualification.
 * //from w  ww.j  av a2s.  c  om
 * @param propName
 * @return
 */
private boolean isPrefixedAndBound(ValueReference propName) {
    QName name = propName.getAsQName();
    return !name.getPrefix().equals(DEFAULT_NS_PREFIX) && !name.getNamespaceURI().equals("");
}

From source file:org.deegree.services.wfs.query.QueryAnalyzer.java

/**
 * Repairs a {@link ValueReference} that contains the local name of a {@link FeatureType}'s property or a prefixed
 * name, but without a correct namespace binding.
 * <p>// w  ww .  jav  a 2  s . c om
 * This types of propertynames especially occurs in WFS 1.0.0 requests.
 * </p>
 * 
 * @param propName
 *            property name to be repaired, must be "simple", i.e. contain only of a QName
 * @param typeName
 *            feature type specification from the query, must not be <code>null</code>
 * @throws OWSException
 *             if no match could be found
 */
private void repairSimpleUnqualified(ValueReference propName, TypeName typeName) throws OWSException {

    FeatureType ft = service.lookupFeatureType(typeName.getFeatureTypeName());

    List<QName> propNames = new ArrayList<QName>();
    // TODO which GML version
    for (PropertyType pt : ft.getPropertyDeclarations()) {
        propNames.add(pt.getName());
    }

    QName match = QNameUtils.findBestMatch(propName.getAsQName(), propNames);
    if (match == null) {
        String msg = "Specified PropertyName '" + propName.getAsText() + "' does not exist for feature type '"
                + ft.getName() + "'.";
        throw new OWSException(msg, INVALID_PARAMETER_VALUE, "PropertyName");
    }
    if (!match.equals(propName.getAsQName())) {
        LOG.debug("Repairing unqualified PropertyName: " + QNameUtils.toString(propName.getAsQName()) + " -> "
                + QNameUtils.toString(match));
        // vague match
        String text = match.getLocalPart();
        if (!match.getPrefix().equals(DEFAULT_NS_PREFIX)) {
            text = match.getPrefix() + ":" + match.getLocalPart();
        }
        NamespaceBindings nsContext = new NamespaceBindings();
        nsContext.addNamespace(match.getPrefix(), match.getNamespaceURI());
        propName.set(text, nsContext);
    }
}

From source file:org.deegree.services.wps.provider.sextante.SextanteProcesslet.java

/**
 * This method determines all namespaces of a {@link Feature}. If the {@link Feature} is a {@link FeatureCollection}
 * , the first {@link Feature} of the {@link FeatureCollection} is used to determine the namespaces.
 * /*from   ww  w. j  a va  2 s  .  c o m*/
 * @param f
 *            {@link Feature}.
 * 
 * @return {@link HashMap} of namespaces. The key is the prefix and the value the namespace URI.
 */
static HashMap<String, String> determinePropertyNamespaces(Feature f) {

    Feature propertyTypeFeature = f;

    if (f instanceof FeatureCollection) {
        FeatureCollection fc = (FeatureCollection) f;
        Iterator<Feature> it = fc.iterator();
        if (it.hasNext()) {
            propertyTypeFeature = it.next();
        }
    }

    HashMap<String, String> namespaces = new HashMap<String, String>();

    List<Property> props = propertyTypeFeature.getProperties();
    for (int i = 0; i < props.size(); i++) {
        QName name = props.get(i).getName();
        namespaces.put(name.getNamespaceURI(), name.getPrefix());
    }

    return namespaces;
}

From source file:org.eclipse.swordfish.internal.core.interceptor.CxfDecoratingInterceptor.java

private void unwrapEnvelope(Message outMessage, Exchange messageExchange)
        throws ParserConfigurationException, IOException, SAXException, TransformerException {
    if (!messageExchange.getProperties().containsKey(PROCESSED_BY_CXF_DECORATING_INTERCEPTOR)
            || !((Boolean) messageExchange.getProperties().get(PROCESSED_BY_CXF_DECORATING_INTERCEPTOR))) {
        return;/*  www  .  j a v  a 2  s  . c o  m*/
    }
    String message = XmlUtil.toStringFromSource(outMessage.getBody(Source.class));
    if (message.contains(":Body")) {
        int index = message.indexOf(">") + 1;
        String xmlPrefix = message.substring(0, index);
        if (envelopeIsEmpty(message)) {
            Document document = DomUtil.createDocument();
            QName operation = messageExchange.getOperation();
            DomUtil.createElement(document, new QName(operation.getNamespaceURI(),
                    operation.getLocalPart() + "Response", operation.getPrefix()));
            outMessage.setBody(new DOMSource(document));
            return;
        }
        String cutMessage = message.substring(index);
        int startIndex = cutMessage.indexOf(":Body");
        startIndex = cutMessage.indexOf(">", startIndex) + 1;
        int endIndex = cutMessage.indexOf(":Body", startIndex);// end   of body
        endIndex = cutMessage.substring(0, endIndex).lastIndexOf("</");
        String bodyMessage = cutMessage.substring(startIndex, endIndex);
        bodyMessage = xmlPrefix + bodyMessage;
        outMessage.setBody(new SourceTransformer().toDOMSource(new StringSource(bodyMessage)));
    }
}

From source file:org.fireflow.model.io.Util4Serializer.java

public static Element addElement(Element parent, QName qname) {
    Document doc = parent.getOwnerDocument();

    String qualifiedName = qname.getLocalPart();
    if (!StringUtils.isEmpty(qname.getPrefix())) {
        qualifiedName = qname.getPrefix() + ":" + qname.getLocalPart();
    }/*ww  w .  ja  v a2s.co  m*/
    Element child = doc.createElementNS(parent.getNamespaceURI(), qualifiedName);
    parent.appendChild(child);
    return child;
}

From source file:org.geoserver.data.test.MockData.java

/**
 * Copies some content to a file udner a specific feature type directory 
 * of the data directory.//from   www  .java  2s.co m
 * Example:
 * <p>
 *  <code>
 *    dd.copyToFeautreTypeDirectory(input,MockData.PrimitiveGeoFeature,"info.xml");
 *  </code>
 * </p>
 * @param input The content to copy.
 * @param featureTypeName The name of the feature type.
 * @param location The resulting location to copy to relative to the 
 *  feautre type directory.
 */
public void copyToFeatureTypeDirectory(InputStream input, QName featureTypeName, String location)
        throws IOException {

    copyTo(input, "featureTypes" + File.separator + featureTypeName.getPrefix() + "_"
            + featureTypeName.getLocalPart() + File.separator + location);
}

From source file:org.geoserver.data.test.MockData.java

public void removeFeatureType(QName typeName) throws IOException {
    String prefix = typeName.getPrefix();
    String type = typeName.getLocalPart();
    File featureTypeDir = new File(featureTypes, prefix + "_" + type);
    if (!featureTypeDir.exists()) {
        throw new FileNotFoundException("Type directory not found: " + featureTypeDir.getAbsolutePath());
    }//from www .ja  va2s  .co m
    File info = new File(featureTypeDir, "info.xml");
    if (!info.exists()) {
        throw new FileNotFoundException("FeatureType file not found: " + featureTypeDir.getAbsolutePath());
    }
    if (!IOUtils.delete(featureTypeDir)) {
        throw new IOException("FetureType directory not deleted: " + featureTypeDir.getAbsolutePath());
    }
}