Package org.exist.xquery.value

Examples of org.exist.xquery.value.StringValue


    if(isWhitespaceOnly) // && context.stripWhitespace())
      return Sequence.EMPTY_SEQUENCE;
       
    if (sequenceItSelf) {
      if (text != null)
        return new StringValue(text);
       
      getContext().setStripWhitespace(false);
      for (Expression expr : steps) {
        if (expr instanceof Text) {
          return new StringValue(((Text) expr).text);
        }
        throw new XPathException("unsupported subelement");
      }
      getContext().setStripWhitespace(true);
    }
View Full Code Here


        xr.setProperty(Namespaces.SAX_LEXICAL_HANDLER, adapter);
        xr.parse(src);
        ret = (DocumentImpl) adapter.getDocument();

          } else if (output.equals(OutputTypeString)) {
        ret = new StringValue(query_cql.toString());
          } else {
        ret = new StringValue(query_cql.toCQL());
          }
          return ret;
          }
    catch (CQLParseException e) {
        throw new XPathException(this, "An error occurred while parsing the query expression (CQLParseException): " + e.getMessage(), e);         
View Full Code Here

   
    // iterate through the argument sequence and echo each item
    ValueSequence result = new ValueSequence();
    for (SequenceIterator i = args[0].iterate(); i.hasNext();) {
      String str = i.nextItem().getStringValue();
      result.add(new StringValue("echo: " + str));
    }
    return result;
  }
View Full Code Here

        try {
            ExistRepository repo = getContext().getRepository();
            Repository parent_repo = repo.getParentRepo();
            for ( Packages pkg :  parent_repo.listPackages() ) {
                String name = pkg.name();
                result.add(new StringValue(name));
            }
        } catch (Exception ex ) {
            throw new XPathException("Problem listing packages in expath repository ", ex);
        }
        return result;
View Full Code Here

            return (DocumentImpl) adapter.getDocument();
           
        } catch (ParserConfigurationException e) {
            throw new XPathException(this, "Error while constructing XML parser: " + e.getMessage(), e);
        } catch (SAXException e) {
            return new StringValue(data);
        } catch (IOException e) {
            return new StringValue(data);
        }
   
  }
View Full Code Here

        URI uri;
        try {
            uri = new URI(s);
        }
        catch ( URISyntaxException ex ) {
          throw new XPathException(this, EXPathErrorCode.EXPDY001, s + " is not a valid URI: " + ex.getMessage(), new StringValue(s), ex);
        }
        if ( uri.isAbsolute() ) {
            return uri;
        } else {
          throw new XPathException(this, EXPathErrorCode.EXPDY001, s + " must be an absolute URI", new StringValue(s));
        }
    }
View Full Code Here

    private BinaryDocument _getDocument(String path) throws XPathException {
      try {
      XmldbURI uri = XmldbURI.createInternal(path);
      DocumentImpl doc = context.getBroker().getXMLResource(uri, Lock.READ_LOCK);
      if (doc.getResourceType() != DocumentImpl.BINARY_FILE)
        throw new XPathException(this, EXPathErrorCode.EXPDY001, path + " is not a valid .xar", new StringValue(path));
      return (BinaryDocument) doc;
    } catch (PermissionDeniedException e) {
      throw new XPathException(this, EXPathErrorCode.EXPDY003, e.getMessage(), new StringValue(path), e);
    }
    }
View Full Code Here

    BrokerPool pool = null;
    try {
      pool = BrokerPool.getInstance();
    } catch (Exception e) {
      result.add(new StringValue(e.getMessage()));
      return result;
    }
    TransactionManager transact = pool.getTransactionManager();

    // Start transaction
    Txn transaction = transact.beginTransaction();

    Collection thumbCollection = null;
    File thumbDir = null;
    if (isSaveToDataBase) {
      try {
        thumbCollection = dbbroker.getOrCreateCollection(transaction,
            thumbPath.toXmldbURI());
        dbbroker.saveCollection(transaction, thumbCollection);
      } catch (Exception e) {
        throw new XPathException(this, e.getMessage());
      }
    } else {
      thumbDir = new File(thumbPath.toString());
      if (!thumbDir.isDirectory())
        try {
          thumbDir.mkdirs();
        } catch (Exception e) {
          throw new XPathException(this, e.getMessage());
        }

    }

                Collection allPictures = null;
                Collection existingThumbsCol = null;
                File[] existingThumbsArray = null;
                try {
                    allPictures = dbbroker.getCollection(picturePath.toXmldbURI());

                    if (allPictures == null) {
                            return Sequence.EMPTY_SEQUENCE;
                    }

                    if (isSaveToDataBase) {
                            existingThumbsCol = dbbroker.getCollection(thumbPath.toXmldbURI());
                    } else {
                            existingThumbsArray = thumbDir.listFiles(new FilenameFilter() {
                                    public boolean accept(File dir, String name) {
                                            return (name.endsWith(".jpeg") || name.endsWith(".jpg"));
                                    }
                            });
                    }
                } catch (PermissionDeniedException pde) {
                    throw new XPathException(pde.getMessage(), pde);
                }

    DocumentImpl docImage = null;
    BinaryDocument binImage = null;
    @SuppressWarnings("unused")
    BinaryDocument doc = null;
    BufferedImage bImage = null;
    @SuppressWarnings("unused")
    byte[] imgData = null;
    Image image = null;
    ByteArrayOutputStream os = null;

                try {
    Iterator<DocumentImpl> i = allPictures.iterator(dbbroker);

    while (i.hasNext()) {
      docImage = (DocumentImpl) i.next();
      // is not already existing??
      if (!((fileExist(context.getBroker(), existingThumbsCol, docImage, prefix)) || (fileExist(
          existingThumbsArray, docImage, prefix)))) {
        if (docImage.getResourceType() == DocumentImpl.BINARY_FILE)
          // TODO maybe extends for gifs too.
          if (docImage.getMetadata().getMimeType().startsWith(
              "image/jpeg")) {

            binImage = (BinaryDocument) docImage;

            // get a byte array representing the image

            try {
                                                   InputStream is = dbbroker.getBinaryResource(binImage);
              image = ImageIO.read(is);
            } catch (IOException ioe) {
              throw new XPathException(this,ioe.getMessage());
            }

            try {
              bImage = ImageModule.createThumb(image, maxThumbHeight,
                  maxThumbWidth);
            } catch (Exception e) {
              throw new XPathException(this, e.getMessage());
            }

            if (isSaveToDataBase) {
              os = new ByteArrayOutputStream();
              try {
                ImageIO.write(bImage, "jpg", os);
              } catch (Exception e) {
                throw new XPathException(this, e.getMessage());
              }
              try {
                doc = thumbCollection.addBinaryResource(
                    transaction, dbbroker,
                    XmldbURI.create(prefix
                        + docImage.getFileURI()), os
                        .toByteArray(), "image/jpeg");
              } catch (Exception e) {
                throw new XPathException(this, e.getMessage());
              }
              // result.add(new
              // StringValue(""+docImage.getFileURI()+"|"+thumbCollection.getURI()+THUMBPREFIX
              // + docImage.getFileURI()));
            } else {
              try {
                ImageIO
                    .write(
                        bImage,
                        "jpg",
                        new File(thumbPath.toString()
                            + "/" + prefix
                            + docImage.getFileURI()));
              } catch (Exception e) {
                throw new XPathException(this, e.getMessage());
              }
              // result.add(new StringValue(
              // thumbPath.toString() + "/"
              // + THUMBPREFIX
              // + docImage.getFileURI()));
            }
          }
      } else {

        // result.add(new StringValue(""+docImage.getURI()+"|"
        // + ((existingThumbsCol != null) ? ""
        // + existingThumbsCol.getURI() : thumbDir
        // .toString()) + "/" + prefix
        // + docImage.getFileURI()));

        result.add(new StringValue(docImage.getFileURI().toString()));
      }
    }
                } catch(PermissionDeniedException pde) {
                    throw new XPathException(this, pde.getMessage(), pde);
                }
View Full Code Here

      throw new XPathException(this, e)
    }
   
    //TODO : return an *Item* built with sw.toString()
   
    return new StringValue( sw.toString() );
  }
View Full Code Here

        try {
          broker = pool.get(pool.getSecurityManager().getSystemSubject());
            TransactionManager transact = pool.getTransactionManager();
            Txn transaction = transact.beginTransaction();

            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Chair"), 1);
            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Table892.25"), 1);
            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Cabinet1525.00"), 1);

            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence seq = xquery.execute("//item[. = 'Chair']", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(1, seq.getItemCount());

            XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
            assertNotNull(proc);
            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            String xupdate =
                    XUPDATE_START +
                    "   <xu:update select=\"//item[@id = '1']/description\">Wardrobe</xu:update>" +
                    XUPDATE_END;
            Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Chair"), 0);
            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Wardrobe"), 1);

            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            xupdate =
                    XUPDATE_START +
                    "   <xu:update select=\"//item[@id = '1']/description/text()\">Wheelchair</xu:update>" +
                    XUPDATE_END;
            modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Wardrobe"), 0);
            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Wheelchair"), 1);

            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            xupdate =
                    XUPDATE_START +
                    "   <xu:update select=\"//item[@id = '1']/@attr\">abc</xu:update>" +
                    XUPDATE_END;
            modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();
            checkIndex(broker, docs, null, new StringValue("abc"), 1);

            transact.commit(transaction);
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
View Full Code Here

TOP

Related Classes of org.exist.xquery.value.StringValue

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.