Example usage for javax.xml XMLConstants DEFAULT_NS_PREFIX

List of usage examples for javax.xml XMLConstants DEFAULT_NS_PREFIX

Introduction

In this page you can find the example usage for javax.xml XMLConstants DEFAULT_NS_PREFIX.

Prototype

String DEFAULT_NS_PREFIX

To view the source code for javax.xml XMLConstants DEFAULT_NS_PREFIX.

Click Source Link

Document

Prefix to use to represent the default XML Namespace.

Usage

From source file:org.apache.openaz.xacml.std.dom.DOMResponse.java

/**
 * Helper: When outputting as XML string, extract any Namespace info from an AttributeValue.Value.Value
 * object. This must be done separately from getting the Value as a String because this info is put as an
 * attribute in the surrounding element. Currently only applies to XPathExpressionWrappers.
 *
 * @param valueObject// w ww  .  ja  v  a 2 s.  com
 * @return
 */
private static String getNamespaces(Object valueObject) {
    String returnString = "";
    if (!(valueObject instanceof XPathExpressionWrapper)) {
        // value is not XPathExpression, so has no Namespace info in it
        return returnString;
    }
    XPathExpressionWrapper xw = (XPathExpressionWrapper) valueObject;

    ExtendedNamespaceContext namespaceContext = xw.getNamespaceContext();
    if (namespaceContext != null) {
        // get the list of all namespace prefixes
        Iterator<String> prefixIt = namespaceContext.getAllPrefixes();
        while (prefixIt.hasNext()) {
            String prefix = prefixIt.next();
            String namespaceURI = namespaceContext.getNamespaceURI(prefix);
            if (prefix == null || prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
                returnString += " xmlns=\"" + namespaceURI + "\"";
            } else {
                returnString += " xmlns:" + prefix + "=\"" + namespaceURI + "\"";
            }
        }

    }
    return returnString;
}

From source file:org.apache.openaz.xacml.std.json.JSONRequest.java

/**
 * Create the appropriate object for JSON output. This needs to be a Boolean, Integer or Double for those
 * data types so that the ObjectMapper knows how to format the JSON text. For objects implementing
 * stringValue we use that string. for XPathExpressions use the Path. Otherwise default to using toString.
 *
 * @param obj/*from  w ww  .j av  a2 s . c  om*/
 * @return
 */
private static Object jsonOutputObject(Object obj, AttributeValue<?> attrValue) throws JSONStructureException {
    if (obj instanceof String || obj instanceof Boolean || obj instanceof BigInteger) {
        return obj;
    } else if (obj instanceof Double) {
        Double d = (Double) obj;
        if (d == Double.NaN) {
            return "NaN";
        } else if (d == Double.POSITIVE_INFINITY) {
            return "INF";
        } else if (d == Double.NEGATIVE_INFINITY) {
            return "-INF";
        }
        return obj;
    } else if (obj instanceof SemanticString) {
        return ((SemanticString) obj).stringValue();
    } else if (obj instanceof X500Principal || obj instanceof URI) {
        // something is very weird with X500Principal data type. If left on its own the output is a map
        // that includes encoding.
        return obj.toString();
    } else if (obj instanceof XPathExpressionWrapper) {
        // create a map containing the complex value for the XPathExpression
        Map<String, Object> xpathExpressionMap = new HashMap<String, Object>();
        Identifier xpathCategoryId = attrValue.getXPathCategory();
        if (xpathCategoryId == null) {
            throw new JSONStructureException("XPathExpression is missing XPathCategory");
        }
        xpathExpressionMap.put("XPathCategory", attrValue.getXPathCategory().stringValue());

        XPathExpressionWrapper xw = (XPathExpressionWrapper) obj;
        xpathExpressionMap.put("XPath", xw.getPath());

        ExtendedNamespaceContext namespaceContext = xw.getNamespaceContext();
        if (namespaceContext != null) {
            List<Object> namespaceList = new ArrayList<Object>();

            // get the list of all namespace prefixes
            Iterator<String> prefixIt = namespaceContext.getAllPrefixes();
            while (prefixIt.hasNext()) {
                String prefix = prefixIt.next();
                String namespaceURI = namespaceContext.getNamespaceURI(prefix);
                Map<String, Object> namespaceMap = new HashMap<String, Object>();
                if (prefix != null && !prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
                    namespaceMap.put("Prefix", prefix);
                }
                namespaceMap.put("Namespace", namespaceURI);
                namespaceList.add(namespaceMap);
            }

            xpathExpressionMap.put("Namespaces", namespaceList);
        }
        return xpathExpressionMap;

    } else {
        throw new JSONStructureException("Unhandled data type='" + obj.getClass().getName() + "'");
    }
}

From source file:org.apache.openaz.xacml.std.json.JSONResponse.java

/**
 * Create the appropriate object for JSON output. This needs to be a Boolean, Integer or Double for those
 * data types so that the ObjectMapper knows how to format the JSON text. For objects implementing
 * stringValue we use that string. for XPathExpressions use the Path. Otherwise default to using toString.
 *
 * @param obj//from w w w  .  ja va 2  s. c  o m
 * @return
 */
private static Object jsonOutputObject(Object obj, AttributeValue<?> attrValue) throws JSONStructureException {
    if (obj instanceof String || obj instanceof Boolean || obj instanceof BigInteger) {
        return obj;
    } else if (obj instanceof Double) {
        Double d = (Double) obj;
        if (d == Double.NaN) {
            return "NaN";
        } else if (d == Double.POSITIVE_INFINITY) {
            return "INF";
        } else if (d == Double.NEGATIVE_INFINITY) {
            return "-INF";
        }
        return obj;
    } else if (obj instanceof SemanticString) {
        return ((SemanticString) obj).stringValue();
    } else if (obj instanceof X500Principal || obj instanceof URI) {
        // something is very weird with X500Principal data type. If left on its own the output is a map
        // that includes encoding.
        return obj.toString();
    } else if (obj instanceof XPathExpressionWrapper) {
        // create a map containing the complex value for the XPathExpression
        Map<String, Object> xpathExpressionMap = new HashMap<String, Object>();
        Identifier xpathCategoryId = attrValue.getXPathCategory();
        if (xpathCategoryId == null) {
            throw new JSONStructureException("XPathExpression is missing XPathCategory");
        }
        xpathExpressionMap.put("XPathCategory", attrValue.getXPathCategory().stringValue());

        XPathExpressionWrapper xw = (XPathExpressionWrapper) obj;
        xpathExpressionMap.put("XPath", xw.getPath());

        ExtendedNamespaceContext namespaceContext = xw.getNamespaceContext();
        if (namespaceContext != null) {
            List<Object> namespaceList = new ArrayList<Object>();

            // get the list of all namespace prefixes
            Iterator<String> prefixIt = namespaceContext.getAllPrefixes();
            while (prefixIt.hasNext()) {
                String prefix = prefixIt.next();
                String namespaceURI = namespaceContext.getNamespaceURI(prefix);
                Map<String, Object> namespaceMap = new HashMap<String, Object>();
                if (prefix != null && !prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
                    namespaceMap.put("Prefix", prefix);
                }
                namespaceMap.put("Namespace", namespaceURI);
                namespaceList.add(namespaceMap);
            }

            xpathExpressionMap.put("Namespaces", namespaceList);
        }
        return xpathExpressionMap;
    } else {
        throw new JSONStructureException("Unhandled data type='" + obj.getClass().getName() + "'");
    }
}

From source file:org.ballerinalang.model.values.BXMLItem.java

/**
 * {@inheritDoc}/*from  w w  w . ja va  2s .c  om*/
 */
@Override
public String getAttribute(String localName, String namespace) {
    return getAttribute(localName, namespace, XMLConstants.DEFAULT_NS_PREFIX);
}

From source file:org.betaconceptframework.astroboa.model.impl.item.ItemQNameImpl.java

public ItemQNameImpl(String prefix, String namespaceUrl, String localPart) {
    if (prefix == null)
        prefix = XMLConstants.DEFAULT_NS_PREFIX;

    this.qualifiedName = new QName(namespaceUrl, localPart, prefix);
}

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)/*  ww w  .j a v  a 2  s .  c o 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

/**
 * @see WFSProtocol#getFeaturePOST(Query, String)
 *//* w  w w.j a v a2s  .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 + ")");
    }/*  w  ww . j a va  2  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;
}

From source file:org.jumpmind.metl.ui.views.design.ImportXmlTemplateWindow.java

protected void importFromXsd(String text) throws Exception {
    XSModel xsModel = new XSParser().parseString(text, "");

    XSInstance xsInstance = new XSInstance();
    xsInstance.minimumElementsGenerated = 1;
    xsInstance.maximumElementsGenerated = 1;
    xsInstance.generateOptionalElements = Boolean.TRUE;

    XSNamedMap map = xsModel.getComponents(XSConstants.ELEMENT_DECLARATION);

    QName rootElement = new QName(map.item(0).getNamespace(), map.item(0).getName(),
            XMLConstants.DEFAULT_NS_PREFIX);
    StringWriter writer = new StringWriter();
    XMLDocument sampleXml = new XMLDocument(new StreamResult(writer), true, 4, null);
    xsInstance.generate(xsModel, rootElement, sampleXml);

    String xml = writer.toString();
    listener.onImport(xml);/*  w  w  w . j  a  va  2s  .  com*/
}

From source file:org.kalypso.gml.GMLSAXFactory.java

public void process(final GMLWorkspace workspace) throws SAXException {
    final Feature rootFeature = workspace.getRootFeature();

    final IFeatureType rootFT = rootFeature.getFeatureType();
    final QName rootQName = rootFT.getQName();

    // REMARK: always force the root element to have the empty namespace prefix
    final String rootNamespace = rootQName.getNamespaceURI();
    m_usedPrefixes.put(rootNamespace, XMLConstants.DEFAULT_NS_PREFIX);

    forcePrefixes(workspace, rootNamespace);

    // Add schemalocation string
    final AttributesImpl a = new AttributesImpl();
    final String schemaLocationString = workspace.getSchemaLocationString();
    if (schemaLocationString != null && schemaLocationString.length() > 0) {

        addAttribute(a, m_schemaLocationAttributeName, "CDATA", schemaLocationString);
    }/*ww w .j av  a 2s .  c om*/

    processFeature(rootFeature, a);
}