Package org.exist.dom

Examples of org.exist.dom.QName


                final Expression outerExpr = contextInfo.getContextStep();
                if (outerExpr != null && outerExpr instanceof LocationStep) {
                    final LocationStep outerStep = (LocationStep) outerExpr;
                    final NodeTest test = outerStep.getTest();
                    if (!test.isWildcardTest() && test.getName() != null) {
                        contextQName = new QName(test.getName());
                        if (outerStep.getAxis() == Constants.ATTRIBUTE_AXIS ||
                                outerStep.getAxis() == Constants.DESCENDANT_ATTRIBUTE_AXIS)
                            {contextQName.setNameType(ElementValue.ATTRIBUTE);}
                        contextStep = firstStep;
                        axis = outerStep.getAxis();
                        optimizeSelf = true;
                    }
                }
            } else if (firstStep != null && lastStep != null) {
                final NodeTest test = lastStep.getTest();
                if (!test.isWildcardTest() && test.getName() != null) {
                    contextQName = new QName(test.getName());
                    if (lastStep.getAxis() == Constants.ATTRIBUTE_AXIS ||
                            lastStep.getAxis() == Constants.DESCENDANT_ATTRIBUTE_AXIS)
                        {contextQName.setNameType(ElementValue.ATTRIBUTE);}
                    contextStep = lastStep;
                    axis = firstStep.getAxis();
View Full Code Here


      final Object[] result = (Object[]) rpcClient.execute("getIndexedElements", params);
      final Occurrences occurrences[] = new Occurrences[result.length];
      Object[] row;
      for (int i = 0; i < occurrences.length; i++) {
        row = (Object[]) result[i];
        final QName qname = new QName((String)row[0], (String)row[1],
            (String)row[2]);
        occurrences[i] = new Occurrences(qname);
        occurrences[i].addOccurrences(((Integer) row[3]).intValue());
      }
      return occurrences;
View Full Code Here

                final Expression outerExpr = contextInfo.getContextStep();
                if (outerExpr != null && outerExpr instanceof LocationStep) {
                    final LocationStep outerStep = (LocationStep) outerExpr;
                    final NodeTest test = outerStep.getTest();
                    if (!test.isWildcardTest() && test.getName() != null) {
                        contextQName = new QName(test.getName());
                        if (outerStep.getAxis() == Constants.ATTRIBUTE_AXIS || outerStep.getAxis() == Constants.DESCENDANT_ATTRIBUTE_AXIS)
                            {contextQName.setNameType(ElementValue.ATTRIBUTE);}
                        contextStep = firstStep;
                        axis = outerStep.getAxis();
                        optimizeSelf = true;
                    }
                }
            } else if (firstStep != null && lastStep != null) {
                final NodeTest test = lastStep.getTest();
                if (!test.isWildcardTest() && test.getName() != null) {
                    contextQName = new QName(test.getName());
                    if (lastStep.getAxis() == Constants.ATTRIBUTE_AXIS || lastStep.getAxis() == Constants.DESCENDANT_ATTRIBUTE_AXIS)
                        {contextQName.setNameType(ElementValue.ATTRIBUTE);}
                    contextStep = lastStep;
                    axis = firstStep.getAxis();
                    if (axis == Constants.SELF_AXIS && steps.size() > 1) {
View Full Code Here

      if (prefix.equalsIgnoreCase("xml") && !namespace.equalsIgnoreCase(Namespaces.XML_NS))
        {throw new XPathException(this, ErrorCodes.XQDY0044, "prefix 'xml' can be used only with '"+Namespaces.XML_NS+"'");}
     
    }
   
    final QName qname = new QName(localName, namespace, prefix);
        if (prefix != null && namespace != null) {
            if (context.getURIForPrefix(prefix) == null) {
              //TOCHECK : context.declareInScopeNamespace(prefix, uri) ?             
                context.declareNamespace(prefix, namespace);
            }


            //context.declareInScopeNamespace(prefix, namespace);
        }

        if(!XMLChar.isValidName(qname.getLocalName()))
            {throw new XPathException(this, ErrorCodes.FOCA0002, "'" + qname.getLocalName() + "' is not a valid local name.");}

        final Sequence result = new QNameValue(context, qname);

        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
View Full Code Here

   
    SVNWCClient wcClient = manager.getWCClient();

    MemTreeBuilder builder = context.getDocumentBuilder();
        builder.startDocument();
        builder.startElement(new QName("status", null, null), null);
   
        try {
      statusClient.doStatus(
          new Resource(uri),
          SVNRevision.HEAD,
          SVNDepth.getInfinityOrFilesDepth(true),
          true, true, false, false, 
          new AddStatusHandler(false, builder),
          null);
    } catch (SVNException e1) {
          builder.startElement(new QName("error", null, null), null);
          builder.characters(e1.getMessage());
          builder.endElement();
    }
   
        builder.endElement();
View Full Code Here

        NodeImpl node;
        try {
            MemTreeBuilder builder = context.getDocumentBuilder();
            builder.setReplaceAttributeFlag(true);
            context.proceed(this, builder);
            QName qn = null;
            String name = null;
            if (qnameExpr != null) {
                Sequence nameSeq = qnameExpr.eval(contextSequence, contextItem);
                if (!nameSeq.hasOne())
                    throw new XPathException(this, "The name expression should evaluate to a single value");
View Full Code Here

    private Sequence encodeResponseAsXML(final XQueryContext context, final HttpMethod method, final int statusCode, final Map<String, Boolean> parserFeatures, final Map<String, String> parserProperties) throws XPathException, IOException {

        final MemTreeBuilder builder = context.getDocumentBuilder();

        builder.startDocument();
        builder.startElement(new QName("response", NAMESPACE_URI, PREFIX), null );
        builder.addAttribute(new QName("statusCode", null, null), String.valueOf(statusCode));

        //Add all the response headers
        builder.startElement(new QName("headers", NAMESPACE_URI, PREFIX), null);

        final NameValuePair[] headers = method.getResponseHeaders();

        for(final NameValuePair header : headers) {
            builder.startElement(new QName("header", NAMESPACE_URI, PREFIX), null);
            builder.addAttribute(new QName("name", null, null), header.getName());
            builder.addAttribute(new QName("value", null, null), header.getValue());
            builder.endElement();
        }

        builder.endElement();

        if(!(method instanceof HeadMethod || method instanceof OptionsMethod)) { // Head and Options methods never have any response body

            // Add the response body node
            builder.startElement(new QName("body", NAMESPACE_URI, PREFIX), null);

            insertResponseBody(context, method, builder, parserFeatures, parserProperties);

            builder.endElement();
        }
View Full Code Here

    private Sequence encodeErrorResponse(final XQueryContext context, final String message) throws IOException, XPathException {

        final MemTreeBuilder builder = context.getDocumentBuilder();

        builder.startDocument();
        builder.startElement(new QName("response", NAMESPACE_URI, PREFIX), null);
        builder.addAttribute(new QName("statusCode", null, null), HTTP_EXCEPTION_STATUS_CODE);

        builder.startElement(new QName("body", NAMESPACE_URI, PREFIX), null);

        builder.addAttribute(new QName("type", null, null), "text");
        builder.addAttribute(new QName("encoding", null, null), "URLEncoded");

        if(message != null) {
            builder.characters(URLEncoder.encode(message, "UTF-8"));
        }
View Full Code Here

                // determine the type of the response document
                final Header responseContentType = method.getResponseHeader("Content-Type");

                final MimeType responseMimeType = getResponseMimeType(responseContentType);
                if(responseContentType != null) {
                    builder.addAttribute(new QName("mimetype", null, null), responseContentType.getValue());
                }

                //try and parse the response as XML
                try {
                    //we have to use CloseShieldInputStream otherwise the parser closes the stream and we cant later reread
                    final InputStream shieldedInputStream = new CloseShieldInputStream(cfis);
                    responseNode = (NodeImpl)ModuleUtils.streamToXML(context, shieldedInputStream);
                    builder.addAttribute(new QName("type", null, null ), "xml");
                    responseNode.copyTo(null, new DocumentBuilderReceiver(builder));
                } catch(final SAXException se) {
                    // could not parse to xml
                    // not an error in itself, it will be treated either as HTML,
                    // text or binary here below
                    final String msg = "Request for URI '"
                        + method.getURI().toString()
                        + "' Could not parse http response content as XML (will try html, text or fallback to binary): "
                        + se.getMessage();
                    if(logger.isDebugEnabled()) {
                        logger.debug(msg, se);
                    } else {
                        logger.info(msg);
                    }
                } catch(final IOException ioe) {
                    final String msg = "Request for URI '" + method.getURI().toString() + "' Could not read http response content: " + ioe.getMessage();
                    logger.error(msg, ioe);
                    throw new XPathException(msg, ioe);
                }

                if(responseNode == null) {
                    //response is NOT parseable as XML

                    //is it a html document?
                    if(responseMimeType.getName().equals(MimeType.HTML_TYPE.getName())) {

                        //html document
                        try {

                            //reset the stream to the start, as we need to reuse since attempting to parse to XML
                            cfis.reset();

                            //parse html to xml(html)
                           
                            //we have to use CloseShieldInputStream otherwise the parser closes the stream and we cant later reread
                            final InputStream shieldedInputStream = new CloseShieldInputStream(cfis);
                           
                            responseNode = (NodeImpl)ModuleUtils.htmlToXHtml(context, method.getURI().toString(), new InputSource(shieldedInputStream), parserFeatures, parserProperties).getDocumentElement();
                            builder.addAttribute(new QName("type", null, null), "xhtml" );
                            responseNode.copyTo(null, new DocumentBuilderReceiver(builder));
                        } catch(final URIException ue) {
                            throw new XPathException(this, ue.getMessage(), ue);
                        } catch(final SAXException se) {
                            //could not parse to xml(html)
                            logger.debug("Could not parse http response content from HTML to XML: " + se.getMessage(), se);
                        }
                    }
                }

                if(responseNode == null) {

                    //reset the stream to the start, as we need to reuse since attempting to parse to HTML->XML
                    cfis.reset();

                    if(responseMimeType.getName().startsWith("text/")) {

                        // Assume it's a text body and URL encode it
                        builder.addAttribute(new QName("type", null, null), "text");
                        builder.addAttribute(new QName("encoding", null, null), "URLEncoded");
                       
                        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        final byte buf[] = new byte[4096];
                        int read = -1;
                        while((read = cfis.read(buf)) > -1) {
                            baos.write(buf);
                        }
                       
                        builder.characters(URLEncoder.encode(EncodingUtil.getString(baos.toByteArray(), ((HttpMethodBase)method).getResponseCharSet()), "UTF-8"));
                        baos.close();
                    } else {

                        // Assume it's a binary body and Base64 encode it
                        builder.addAttribute( new QName( "type", null, null ), "binary" );
                        builder.addAttribute( new QName( "encoding", null, null ), "Base64Encoded" );

                        BinaryValue binary = null;
                        try {
                            binary = BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), cfis);
                            builder.characters(binary.getStringValue());
View Full Code Here

                    throw new DatabaseConfigurationException("Range index module: Invalid match path in collection config: " + match);
            } catch (IllegalArgumentException e) {
                throw new DatabaseConfigurationException("Range index module: invalid qname in configuration: " + e.getMessage());
            }
        } else if (node.hasAttribute("qname")) {
            QName qname = LuceneIndexConfig.parseQName(node, namespaces);
            path = new NodePath(NodePath.SKIP);
            path.addComponent(qname);
            isQNameIndex = true;
        }
        String typeStr = node.getAttribute("type");
View Full Code Here

TOP

Related Classes of org.exist.dom.QName

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.