Package com.dbxml.db.client

Examples of com.dbxml.db.client.CollectionClient


         this.err = new PrintWriter(err, true);
   }

   public void process() {
      String line = null;
      CollectionClient col = null;
      String colName = "";

      if ( getProperty(INTERACTIVE) == Boolean.TRUE ) {
         out.println(dbXML.Title + " " + dbXML.Version + " Interactive Mode");
         out.println("Type 'HELP' for a list of command categories");
      }

      do {
         try {
            CollectionClient nc = (CollectionClient)getProperty(COLLECTION);
            if ( nc != col ) {
               col = nc;
               if ( col != null )
                  colName = col.getCanonicalName();
               else
View Full Code Here


   public int doStartTag() throws JspException {
      Object obj = pageContext.getAttribute(collection);
      if ( obj == null || !(obj instanceof CollectionClient) )
         throw new JspException("No Collection named '" + collection + "' has been declared");
      CollectionClient col = (CollectionClient)obj;

      try {
         col.remove(key);
      }
      catch ( dbXMLException e ) {
         throw new JspException("Can't remove Document '" + key + "' from Collection '" + collection + "'", e);
      }
View Full Code Here

   public int doStartTag() throws JspException {
      Object obj = pageContext.getAttribute(collection);
      if ( obj == null || !(obj instanceof CollectionClient) )
         throw new JspException("No Collection named '" + collection + "' has been declared");
      CollectionClient col = (CollectionClient)obj;

      try {
         if ( name != null ) {
            if ( text )
               pageContext.setAttribute(name, col.getDocumentAsText(key));
            else
               pageContext.setAttribute(name, col.getDocument(key));
         }
         else {
            String document = col.getDocumentAsText(key);
            if ( !prefix && document.startsWith("<?xml ") ) {
               int idx = document.indexOf('\n');
               if ( idx != -1 )
                  document = document.substring(idx + 1);
            }
View Full Code Here

   public int doEndTag() throws JspException {
      Object obj = pageContext.getAttribute(collection);
      if ( obj == null || !(obj instanceof CollectionClient) )
         throw new JspException("No Collection named '" + collection + "' has been declared");
      CollectionClient col = (CollectionClient)obj;

      try {
         Map nsMap = new HashMap();
         Enumeration iter = getValues();
         while ( iter != null && iter.hasMoreElements() ) {
            String key = (String)iter.nextElement();
            Object value = getValue(key);
            if ( value != null && value instanceof String ) {
               if ( key.startsWith("xmlns:") ) {
                  String prefix = key.substring(6);
                  nsMap.put(prefix, value);
               }
               else if ( key.equals("xmlns") )
                  nsMap.put("", value);
            }
         }

         BodyContent content = getBodyContent();
         String query = content.getString();
         ResultSetClient rs;
         if ( key != null )
            rs = col.queryDocument(style, query, nsMap, key);
         else
            rs = col.queryCollection(style, query, nsMap);

         if ( name != null )
            pageContext.setAttribute(name, rs);
         else {
            while ( rs.next() ) {
View Full Code Here

   private static final String RECURSIVE = "RECURSIVE";
   private static final String[] STRS = {"NONE", "READ", "WRITE", "EXECUTE", "CREATE"};
   private static final int[] INTS = {Access.NONE, Access.READ, Access.WRITE, Access.EXECUTE, Access.CREATE};

   public void process() throws dbXMLException {
      CollectionClient col = (CollectionClient)cl.getProperty(CommandLine.COLLECTION);
      if ( col == null )
         throw new dbXMLException("Collection context required");

      String roleID = cl.getNextToken("Role ID");
      int permissions = 0;
View Full Code Here

   protected void process(CollectionClient col, String roleID, int permissions, boolean recursive) throws dbXMLException {
      process(col.getCanonicalName(), roleID, permissions);
      if ( recursive ) {
         String[] children = col.listCollections();
         for ( int i = 0; i < children.length; i++ ) {
            CollectionClient child = col.getCollection(children[i]);
            process(child, roleID, permissions, recursive);
         }
      }
   }
View Full Code Here

* CreateBase is a base class for several creation-related Commands.
*/

public abstract class CreateBase extends CommandBase {
   public final void process() throws dbXMLException {
      CollectionClient col = (CollectionClient)cl.getProperty(CommandLine.COLLECTION);
      if ( col == null )
         throw new dbXMLException("Collection context required");

      String name = cl.getNextToken(getType()+" Name");
      Properties props = cl.parseProperties();
View Full Code Here

* only one argument.
*/

public abstract class SingletonBase extends CommandBase {
   public final void process() throws dbXMLException {
      CollectionClient col = (CollectionClient)cl.getProperty(CommandLine.COLLECTION);
      if ( col == null )
         throw new dbXMLException("Collection context required");

      if ( cl.hasMoreTokens() ) {
         String argument = cl.getNextToken();
View Full Code Here

                  int idx = currentFile.lastIndexOf('/');
                  String colName = currentFile.substring(0, idx);
                  String docName = currentFile.substring(idx + 1);
                  Content c = mf.getContent(currentFile);

                  CollectionClient lclCol = (CollectionClient)lclColCache.get(colName);
                  if ( lclCol == null ) {
                     lclCol = localContentClient.getCollection(colName);
                     lclColCache.put(colName, lclCol);
                     if ( lclCol.getCollectionType() == CollectionClient.TYPE_DOCUMENTS )
                        lclColXML.add(colName);
                  }

                  if ( c.getStatus() != Constants.STATUS_DELETED ) {
                     CollectionClient srcCol = (CollectionClient)srcColCache.get(colName);
                     if ( srcCol == null ) {
                        srcCol = sourceContentClient.getCollection(colName);
                        srcColCache.put(colName, srcCol);
                        if ( srcCol.getCollectionType() == CollectionClient.TYPE_DOCUMENTS )
                           srcColXML.add(colName);
                     }
                     File f = File.createTempFile("dbxml_", ".sync");
                     tempFiles.put(currentFile, f);
                     if ( srcColXML.contains(colName) ) {
                        String doc = srcCol.getDocumentAsText(docName);
                        FileOutputStream fos = new FileOutputStream(f);
                        BufferedOutputStream bos = new BufferedOutputStream(fos, 4096);
                        OutputStreamWriter osw = new OutputStreamWriter(bos, "UTF8");
                        osw.write(doc);
                        osw.flush();
                        osw.close();
                     }
                     else {
                        byte[] doc = srcCol.getValue(docName);
                        FileOutputStream fos = new FileOutputStream(f);
                        fos.write(doc);
                        fos.close();
                     }
                  }
                  else
                     delList.put(currentFile, lclCol);
                  percentComplete = 100 * docNum++ / totalDocs;
               }
            }

            if ( !cancel ) {
               Iterator iter = delList.entrySet().iterator();
               while ( iter.hasNext() ) {
                  Map.Entry entry = (Map.Entry)iter.next();
                  String path = (String)entry.getKey();
                  CollectionClient col = (CollectionClient)entry.getValue();
                  int idx = path.lastIndexOf('/');
                  String docName = path.substring(idx + 1);
                  col.remove(docName);
               }

               iter = tempFiles.entrySet().iterator();
               while ( iter.hasNext() ) {
                  Map.Entry entry = (Map.Entry)iter.next();
                  String path = (String)entry.getKey();
                  File f = (File)entry.getValue();
                  int idx = path.lastIndexOf('/');
                  String colName = path.substring(0, idx);
                  String docName = path.substring(idx + 1);

                  CollectionClient lclCol = (CollectionClient)lclColCache.get(colName);
                  if ( lclCol == null ) {
                     lclCol = localContentClient.getCollection(colName);
                     lclColCache.put(colName, lclCol);
                     if ( lclCol.getCollectionType() == CollectionClient.TYPE_DOCUMENTS )
                        lclColXML.add(colName);
                  }

                  if ( lclColXML.contains(colName) ) {
                     FileInputStream fis = new FileInputStream(f);
                     BufferedInputStream bis = new BufferedInputStream(fis, 4096);
                     InputStreamReader isr = new InputStreamReader(bis, "UTF8");
                     char[] buf = new char[(int)f.length()];
                     int size = isr.read(buf);
                     isr.close();
                     lclCol.setDocumentAsText(docName, new String(buf, 0, size));
                  }
                  else {
                     FileInputStream fis = new FileInputStream(f);
                     byte[] buf = new byte[(int)f.length()];
                     fis.read(buf);
                     fis.close();
                     lclCol.setValue(docName, buf);
                  }
               }
            }
            log.add("Synchronization complete");
         }
         else
            log.add("No files are out of date");

         if ( !cancel ) {
            // Write the last sync to the Database
            Document doc = DOMHelper.newDocument();
            Element srvElem = doc.createElement("server");
            doc.appendChild(srvElem);
            srvElem.setAttribute("host", src_host);
            srvElem.setAttribute("date", new Variant(startTime).getString());
            for ( int i = 0; i < log.size(); i++ ) {
               Element logElem = doc.createElement("log");
               DOMUtils.setText(logElem, (String)log.get(i));
               srvElem.appendChild(logElem);
            }

            CollectionClient col = localContentClient.getCollection("/system/SysConfig");
            col.setDocument("sync" + src_host + ".xml", doc);
         }
      }
      catch ( Exception e ) {
         error = true;
         log.add("Exception: " + e.getMessage());
View Full Code Here

   public String getCanonicalName() {
      Stack s = new Stack();
      try {
         s.push(col.getName());
         CollectionClient c = col;
         while ( true ) {
            c = c.getParentCollection();
            s.push(c.getName());
         }
      }
      catch ( Exception e ) {
      }
View Full Code Here

TOP

Related Classes of com.dbxml.db.client.CollectionClient

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.