コード例 #1
0
ファイル: SqlExecutor.java プロジェクト: mihxil/mmbase
 protected void executeQuery(Statement stmt, String q) throws SQLException {
   q = q.replace("$PREFIX", getPrefix());
   LOG.info(" Executing " + q);
   ResultSet rs = stmt.executeQuery(q);
   StringBuilder header = new StringBuilder();
   for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
     if (i > 1) {
       header.append("|");
     }
     header.append(rs.getMetaData().getColumnName(i));
   }
   LOG.info(header);
   int seq = 0;
   while (true) {
     boolean valid = rs.next();
     if (!valid) break;
     seq++;
     StringBuilder line = new StringBuilder();
     for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
       if (i > 1) {
         line.append("|");
       }
       line.append(rs.getString(i));
     }
     LOG.info(seq + ":" + line);
   }
 }
コード例 #2
0
ファイル: ExampleBean.java プロジェクト: mihxil/mmbase
 /**
  * A real node-function (using the node argument). Returns the next newer node of same type. Also
  * a nice example on the difference between core and bridge.
  */
 public Object successor() {
   if (node == null) throw new IllegalArgumentException("successor is a node-function");
   if (cloud != null) {
     log.debug("Using bridge (security restrictions will be honoured)");
     NodeManager nm = node.getNodeManager();
     NodeQuery q = nm.createQuery();
     StepField field = q.getStepField(nm.getField("number"));
     q.setConstraint(
         q.createConstraint(
             field, FieldCompareConstraint.GREATER, Integer.valueOf(node.getNumber())));
     q.addSortOrder(field, SortOrder.ORDER_ASCENDING);
     q.setMaxNumber(1);
     NodeIterator i = nm.getList(q).nodeIterator();
     return i.hasNext() ? i.nextNode() : null;
   } else {
     log.debug("Using core.");
     throw new UnsupportedOperationException("Core implementation was dropped. See source code.");
     /* This is how it would go with core objects
     MMObjectBuilder builder = MMBase.getMMBase().getBuilder(node.getNodeManager().getName());
     NodeSearchQuery query = new NodeSearchQuery(builder);
     StepField field = query.getField(builder.getField("number"));
     BasicFieldValueConstraint cons = new BasicFieldValueConstraint(field, node.getNumber());
     cons.setOperator(FieldCompareConstraint.GREATER);
     query.setConstraint(cons);
     query.addSortOrder(field);
     query.setMaxNumber(1);
     try {
         java.util.Iterator<MMObjectNode> i = builder.getNodes(query).iterator();
         return i.hasNext() ?  i.next() : null;
     } catch (Exception e) {
         return null;
     }
     */
   }
 }
コード例 #3
0
ファイル: BasicFramework.java プロジェクト: mihxil/mmbase
 @Override
 public String getInternalUrl(String page, Map<String, ?> params, Parameters frameworkParameters)
     throws FrameworkException {
   if (log.isDebugEnabled()) {
     log.debug("calling urlConverter " + urlConverter);
   }
   return urlConverter.getInternalUrl(page, params, frameworkParameters).getUrl();
 }
コード例 #4
0
ファイル: ReferrerResolver.java プロジェクト: mihxil/mmbase
  public ModelAndView getModelAndView(HttpServletRequest request, ResultContainer result) {

    Map<String, Object> model = new HashMap<String, Object>();
    model.put("idmap", result.getIdMap());
    ModelAndView errorMandv = new ModelAndView(errorPage);

    List<GlobalError> globalErrors = result.getGlobalErrors();
    if (result.hasGlobalErrors()) {
      errorMandv.addObject(GlobalError.MODEL_MAPPING_KEY, globalErrors);
      log.debug("request has global errors, so the return page is: " + errorPage);
      return errorMandv;
    }

    if (result.hasFieldErrors()) {
      model.put(FieldError.MODEL_MAPPING_KEY, result.getFieldErrors());
      // Field errors are not displayed in the error page but in the referrer page (the form)
    }

    // has a new object been created?
    // String newObject = result.getNewObjects();
    // set the new object in the request (why?)
    // if (newObject != null) {
    // request.setAttribute("newObject", newObject);
    // if (log.isDebugEnabled()) {
    // log.debug("object number " + newObject);
    // }
    // }
    final String callerPage = request.getHeader("referer");
    if (callerPage == null) {
      // this is an error for this view resolver
      globalErrors.add(new GlobalError("error.no.referrer.header", result.getLocale()));
      log.error("REFERRER NOT SET! This request's redirection wil fail.");
      errorMandv.addObject(GlobalError.MODEL_MAPPING_KEY, globalErrors);
      return errorMandv;
    }
    // add the node number of the new object to the referer url.

    //        if (result.getNewObject().size() > 0) {
    //            if (log.isDebugEnabled()) {
    //                log.debug("new object created.");
    //            }
    //            String newNodeNr = result.getNewObject().get(0);
    //            //newPage = newPage.substring(0, newPage.indexOf("?") + 1) + "nodenr=" +
    // newNodeNr;
    //            String newPage = new URLParamMap(callerPage).addParam("nodenr", newNodeNr,
    // true).toString();
    //        }

    URLParamMap u = new URLParamMap(callerPage);
    if (result.getExtraParams().size() > 0) {
      for (String param : result.getExtraParams().keySet()) {
        u.addParam(param, result.getExtraParams().get(param), true);
      }
    }

    RedirectView redirectView = new RedirectView(u.toString());
    return new ModelAndView(redirectView, model);
  }
コード例 #5
0
ファイル: PageMaster.java プロジェクト: mihxil/mmbase
 /**
  * Schedules a service-request on a file. Only "pages/main" services are handled. The
  * service-request is later handled through the {@link #probeCall} method.
  *
  * @param service the service to be performed
  * @param subservice the subservice to be performed
  * @param filename the filename to service
  * @return <code>true</code> if maintenance was performed, <code>false</code> otherwise
  */
 public boolean fileChange(String service, String subservice, String filename) {
   log.debug("frontend change -> " + filename);
   log.service("s=" + service + " sub=" + subservice + "file=" + filename);
   // jump to correct subhandles based on the subservice
   if (subservice.equals("main")) {
     handleMainCheck(service, subservice, filename);
   }
   return true;
 }
コード例 #6
0
ファイル: TransactionTest.java プロジェクト: mihxil/mmbase
  // same case as above, only no changes are made to the node.
  public void testDeleteNodeOutsideTransactionNodeInTransactionButNotChanged() {
    Cloud cloud = getCloud();
    Transaction t = cloud.getTransaction("bar11");
    Node nodeInTransaction = t.getNode(newNode2);
    // nodeInTransaction.setStringValue("title", "foo2");
    {
      // now delete the node
      Node nodeOutTransaction = cloud.getNode(newNode2);
      nodeOutTransaction.delete();
      assertFalse(cloud.hasNode(newNode2));
    }

    try {
      // make a relation to the (deleted) node, but in the transaction, where the node still
      // exists.
      // This demonstrate that there is an actual problem if the node ends up non-existing now.
      Node url = t.getNodeManager("urls").createNode();
      RelationManager rm = t.getRelationManager("news", "urls", "posrel");
      Relation r = nodeInTransaction.createRelation(url, rm);
      t.commit();
    } catch (Exception e) {
      // should not give exception. MMB-1680
      log.error(e.getMessage(), e);
      fail(e.getMessage());
    }

    assertTrue(cloud.hasNode(newNode2));
    assertEquals(1, cloud.getNode(newNode2).countRelations());
  }
コード例 #7
0
ファイル: TypeRel.java プロジェクト: mihxil/mmbase
 /**
  * Insert a new object (content provided) in the cloud, including an entry for the object alias
  * (if provided). This method indirectly calls {@link #preCommit}. If the typerel node specified
  * already exists (i.e. same snumber, dnumber,a nd rnumber fielfds), the typerel creation fails
  * and returns -1.
  *
  * @param owner The administrator creating the node
  * @param node The object to insert. The object need be of the same type as the current builder.
  * @return An <code>int</code> value which is the new object's unique number, -1 if the insert
  *     failed.
  */
 @Override
 public int insert(String owner, MMObjectNode node) {
   int snumber = node.getIntValue("snumber");
   int dnumber = node.getIntValue("dnumber");
   int rnumber = node.getIntValue("rnumber");
   if (contains(snumber, dnumber, rnumber, STRICT)) {
     log.error(
         "The typerel with snumber="
             + snumber
             + ", dnumber="
             + dnumber
             + ", rnumber="
             + rnumber
             + " already exists");
     throw new RuntimeException(
         "The typerel with snumber="
             + snumber
             + ", dnumber="
             + dnumber
             + ", rnumber="
             + rnumber
             + " already exists");
   }
   int res = super.insert(owner, node);
   return res;
 }
コード例 #8
0
ファイル: TypeRel.java プロジェクト: mihxil/mmbase
  @Override
  public String toString(MMObjectNode n) {
    try {
      int snumber = n.getIntValue("snumber");
      int dnumber = n.getIntValue("dnumber");
      int rnumber = n.getIntValue("rnumber");

      String sourceName = mmb.getTypeDef().getValue(snumber);
      String destName = mmb.getTypeDef().getValue(dnumber);

      if (sourceName == null) {
        sourceName = "unknown builder '" + snumber + "'";
      }
      if (destName == null) {
        destName = "unknown builder '" + dnumber + "'";
      }

      // unfilled should only happen during creation of the node.
      String source = snumber > -1 ? (sourceName + "(" + snumber + ")") : "[unfilled]";
      String destination = dnumber > -1 ? (destName + "(" + dnumber + ")") : "[unfilled]";
      MMObjectNode role = rnumber > -1 ? mmb.getRelDef().getNode(rnumber) : null;
      return source
          + "->"
          + destination
          + " ("
          + (role != null ? role.getStringValue("sname") : "???")
          + ") "
          + (isVirtual() ? "(virtual)" : "");
    } catch (Exception e) {
      log.warn(e);
    }
    return "typerel-node";
  }
コード例 #9
0
ファイル: BitrateLabeler.java プロジェクト: mihxil/mmbase
 @Override
 public void configure(DocumentReader reader, Element element) {
   bitrates.clear();
   try {
     for (Element bitrate :
         DocumentReader.getChildElements(reader.getElementByPath(element, CONFIG_TAG))) {
       BitrateInfo bri = new BitrateInfo(bitrate);
       log.debug("Adding BitrateInfo " + bri);
       bitrates.put(bri.getName(), bri);
     }
   } catch (Exception ex) {
     log.error("Error in filter.xml:" + ex, ex);
   }
   log.info("Configured bit rate labeler " + bitrates);
   FilterUtils.propertiesConfigure(this, reader, element);
 }
コード例 #10
0
ファイル: ErrorRenderer.java プロジェクト: mihxil/mmbase
 @Override
 public void render(Parameters blockParameters, Writer w, RenderHints hints)
     throws FrameworkException {
   log.debug("Error rendering " + blockParameters);
   switch (getType()) {
     case BODY:
       try {
         decorateIntro(hints, w, "error");
         w.write("<h1>" + error.status);
         w.write(": ");
         CharTransformer escape = new Xml(Xml.ESCAPE);
         w.write(escape.transform(error.exception.getMessage()));
         w.write(" ");
         w.write(escape.transform(url));
         w.write("</h1>");
         w.write("<pre>");
         HttpServletRequest request = blockParameters.get(Parameter.REQUEST);
         error.getErrorReport(w, request, escape);
         w.write("</pre>");
         decorateOutro(hints, w);
       } catch (IOException eio) {
         throw new FrameworkException(eio.getMessage(), eio);
       }
       break;
     default:
   }
 }
コード例 #11
0
ファイル: PageMaster.java プロジェクト: mihxil/mmbase
  /**
   * Handles a pages/mirror service request. Places a page in the file2copy queue, so it will be
   * sent to a mirror site by the FileCopier.
   *
   * @param filenode the filenet node that contains the service request
   * @param status the current status of the node
   * @param ctype the type of change on that node ("c" : node was changed)
   * @return <code>true</code>
   */
  public boolean handleMirror(MMObjectNode filenode, int status, String ctype) {
    switch (status) {
      case Netfiles.STATUS_REQUEST: // Request
        // register the node as being On Its Way
        filenode.setValue("status", Netfiles.STATUS_ON_ITS_WAY);
        filenode.commit();
        String filename = filenode.getStringValue("filename");
        String dstserver = filenode.getStringValue("mmserver");
        // recover the correct source/dest properties for this mirror
        //
        // why does it say "demoserver" ??
        //
        String sshpath = getProperty("demoserver", "sshpath");
        log.debug("sshpath=" + sshpath);
        String srcpath = getProperty("demoserver", "path");
        log.debug("srcpath=" + srcpath);
        String dstuser = getProperty(dstserver, "user");
        log.debug("dstuser="******"host");
        log.debug("dsthost=" + dsthost);
        String dstpath = getProperty(dstserver, "path");
        log.debug("dstpath=" + dstpath);

        /* this code can be dropped as it is handled in FileCopier

                SCPcopy scpcopy=new SCPcopy(sshpath,dstuser,dsthost,dstpath);

                synchronized(syncobj) {
                    scpcopy.copy(srcpath,filename);
                }
        */
        // create a new file2copy object and add it to the queue,
        // so the FileCopier thread will handle it.
        files2copy.append(new aFile2Copy(dstuser, dsthost, dstpath, srcpath, filename, sshpath));

        // register the node as being Done
        filenode.setValue("status", Netfiles.STATUS_DONE);
        filenode.commit();
        break;
      case Netfiles.STATUS_ON_ITS_WAY: // On its way
        break;
      case Netfiles.STATUS_DONE: // Done
        break;
    }
    return true;
  }
コード例 #12
0
ファイル: DownloadFunction.java プロジェクト: mihxil/mmbase
  @Override
  public String getFunctionValue(final Node node, final Parameters parameters) {
    if (log.isDebugEnabled()) {
      log.debug("node #" + node.getNumber());
      log.debug("params: " + parameters);
    }
    String status = getDownloadStatus(node);

    int timeout = 5;
    if (parameters.get(TIMEOUT) != null) {
      timeout = parameters.get(TIMEOUT);
    }

    if (status == null) {
      Action action = ActionRepository.getInstance().get("streams", "download_media");
      if (action == null) {
        throw new IllegalStateException("Action could not be found");
      }
      if (node.getCloud().may(action, null)) {
        synchronized (runningJobs) {
          Future<?> future = runningJobs.get(node.getNumber());
          if (future == null) {
            setDownloadStatus(node, "busy: " + System.currentTimeMillis());
            future = submit(node, parameters);

            ThreadPools.identify(
                future,
                DownloadFunction.class.getName()
                    + " downloading... for #"
                    + node.getNumber()
                    + " - status: "
                    + getDownloadStatus(node));
            String fname = ThreadPools.getString(future);
            log.info("Future name: " + fname);
            try {
              status = (String) future.get(timeout, TimeUnit.SECONDS);
              log.info("status: " + status);
            } catch (TimeoutException te) {
              status = ThreadPools.getString(future);
              log.info("TimeoutException: " + status);
            } catch (Exception e) {
              log.error(e);
            }

          } else {
            status = ThreadPools.getString(future);
          }
        }
        log.info("status: " + status);
        return status;
      } else {
        throw new org.mmbase.security.SecurityException("Not allowed");
      }
    }
    return status;
  }
コード例 #13
0
  @Override
  public org.mmbase.bridge.Node getNode(final Cloud userCloud, final Document doc) {
    String docId = doc.get("number");
    if (docId == null) {
      throw new IllegalArgumentException("No number found in " + doc);
    }
    LazyMap m = nodeCache.get(docId); //
    if (m == null) {
      Map<String, String> keys = new HashMap<String, String>();
      for (String keyWord : keyWords) {
        keys.put(keyWord, doc.get(keyWord));
      }
      m = new LazyMap(docId, keys);
      nodeCache.put(docId, m);
    }
    org.mmbase.bridge.Node node =
        new MapNode<String>(
            m,
            new MapNodeManager(userCloud, m) {
              @Override
              public boolean hasField(String name) {
                if (JdbcIndexDefinition.this.key.equals(name)) return true;
                return super.hasField(name);
              }

              @Override
              public org.mmbase.bridge.Field getField(String name) {
                if (map == null && JdbcIndexDefinition.this.key.equals(name)) {
                  org.mmbase.core.CoreField fd =
                      org.mmbase.core.util.Fields.createField(
                          name,
                          org.mmbase.core.util.Fields.classToType(Object.class),
                          org.mmbase.bridge.Field.TYPE_UNKNOWN,
                          org.mmbase.bridge.Field.STATE_VIRTUAL,
                          null);
                  return new org.mmbase.bridge.implementation.BasicField(fd, this);
                } else {
                  return super.getField(name);
                }
              }
            });
    if (log.isDebugEnabled()) {
      log.debug("Returning node for " + node);
    }
    return node;
  }
コード例 #14
0
 @Override
 public CloseableIterator<JdbcEntry> getSubCursor(String identifier) {
   if (isSub) {
     log.debug("Using getSubCursor for " + identifier);
     return getSqlCursor(getSql(identifier));
   } else {
     return getSqlCursor(getFindSql(identifier));
   }
 }
コード例 #15
0
ファイル: BasicFramework.java プロジェクト: mihxil/mmbase
 @SuppressWarnings("unchecked")
 protected void setBlockParametersForRender(State state, Parameters blockParameters) {
   ServletRequest request = state.getRequest();
   String prefix = getPrefix(state);
   log.debug("prefix " + prefix);
   blockParameters.setAutoCasting(true);
   for (Map.Entry<String, String[]> entry :
       ((Map<String, String[]>) request.getParameterMap()).entrySet()) {
     String key = entry.getKey();
     if (key.startsWith(prefix)) {
       log.trace("setting" + entry);
       blockParameters.setIfDefined(key.substring(prefix.length()), entry.getValue());
     }
   }
   if (log.isDebugEnabled()) {
     log.debug("Set " + blockParameters);
   }
 }
コード例 #16
0
ファイル: ResourceRenderer.java プロジェクト: mihxil/mmbase
 @Override
 public URI getUri() {
   try {
     ResourceLoader loader = ResourceLoader.Type.valueOf(resourceType.toUpperCase()).get();
     return loader.getResource(getResource()).toURI();
   } catch (URISyntaxException use) {
     log.warn(use);
     return null;
   }
 }
コード例 #17
0
ファイル: BasicFramework.java プロジェクト: mihxil/mmbase
  /**
   * Configures the framework by reading its configuration file 'config/framework.xml' containing a
   * list with UrlConverters.
   */
  protected final void configure(Element el) {
    try {
      description.fillFromXml("description", el);

      NodeList urlconverters = el.getElementsByTagName("urlconverter");
      for (int i = 0; i < urlconverters.getLength(); i++) {
        Element element = (Element) urlconverters.item(i);
        UrlConverter uc;
        try {
          uc = (UrlConverter) Instantiator.getInstance(element, (Framework) this);
        } catch (NoSuchMethodException nsme) {
          uc = (UrlConverter) Instantiator.getInstance(element);
        } catch (ClassNotFoundException cnfe) {
          log.warn(org.mmbase.util.xml.XMLWriter.write(element) + " " + cnfe);
          continue;
        } catch (Throwable t) {
          log.error(org.mmbase.util.xml.XMLWriter.write(element) + ": " + t.getMessage(), t);
          if (t.getCause() != null) {
            log.error("Caused by: " + t.getCause().getMessage(), t.getCause());
          }
          continue;
        }
        urlConverter.add(uc);
      }
      parDef = null;

    } catch (Throwable e) {
      log.error(e.getMessage(), e);
    }
    /*
    BasicUrlConverter buc = new BasicUrlConverter(this);
    if (! urlConverter.contains(buc)) {
        urlConverter.add(buc);
    }
    */
    log.info(
        "Configured with "
            + el.getOwnerDocument().getDocumentURI()
            + " "
            + getClass()
            + " "
            + this);
  }
コード例 #18
0
ファイル: TypeRel.java プロジェクト: mihxil/mmbase
  /** @since MMBase-1.6.2 */
  private void readCache(boolean buildersInitialized) {
    log.debug("Reading in typerels");
    typeRelNodes = new TypeRelSet();
    parentTypeRelNodes = new TypeRelSet();
    inverseTypeRelNodes = new InverseTypeRelSet();

    TypeDef typeDef = mmb.getTypeDef();
    typeDef.init();
    // Find all typerel nodes
    List<MMObjectNode> alltypes = getNodes();
    for (MMObjectNode typerel : alltypes) {
      addCacheEntry(typerel, buildersInitialized);
    }
    log.debug(
        "Done reading typerel cache "
            + (buildersInitialized ? "(considered inheritance)" : "")
            + ": "
            + typeRelNodes);
  }
コード例 #19
0
ファイル: BasicFramework.java プロジェクト: mihxil/mmbase
 @Override
 public String getProcessUrl(
     String path, Map<String, ?> parameters, Parameters frameworkParameters, boolean escapeAmps)
     throws FrameworkException {
   HttpServletRequest request =
       BasicUrlConverter.getUserRequest(frameworkParameters.get(Parameter.REQUEST));
   State state = State.getState(request);
   frameworkParameters.set(ACTION, state.getId());
   Url url = urlConverter.getProcessUrl(path, parameters, frameworkParameters, escapeAmps);
   if (url == Url.NOT) {
     log.debug("Fall back url");
     return fallbackConverter
         .getProcessUrl(path, parameters, frameworkParameters, escapeAmps)
         .getUrl();
   } else {
     log.debug("Url converter url " + url);
     return url.getUrl();
   }
 }
コード例 #20
0
ファイル: PageMaster.java プロジェクト: mihxil/mmbase
 /**
  * Recalculate a page. Invokes the SCAN parser (which will re-cache the page through the scancache
  * module) Only works for SCAN.
  *
  * @param url of the page to cache
  */
 public void calcPage(String url) {
   scanparser m = (scanparser) Vwms.getMMBase().getModule("SCANPARSER");
   url = url.substring(0, url.length() - 5);
   url = url.replace(':', '?');
   log.debug("getPage=" + url);
   if (m != null) {
     scanpage sp = new scanpage();
     m.calcPage(url, sp, 0);
   }
 }
コード例 #21
0
 @Override
 public boolean inIndex(String identifier) {
   CloseableIterator<JdbcEntry> i = getSqlCursor(getFindSql(identifier));
   boolean result = i.hasNext();
   try {
     i.close();
   } catch (IOException ex) {
     log.warn(ex);
   }
   return result;
 }
コード例 #22
0
ファイル: TypeRel.java プロジェクト: mihxil/mmbase
 @Override
 public void notify(SystemEvent se) {
   if (se instanceof SystemEvent.ServletContext) {
     ServletContext sx = ((SystemEvent.ServletContext) se).getServletContext();
     String def = sx.getInitParameter("mmbase.defaultRelationStepDirection");
     if (def != null && def.length() > 0) {
       defaultRelationStepDirection = org.mmbase.bridge.util.Queries.getRelationStepDirection(def);
       log.info("Found default relation step direction " + def);
     }
   }
 }
コード例 #23
0
ファイル: SqlExecutor.java プロジェクト: mihxil/mmbase
 public void run() {
   Connection con = null;
   Statement stmt = null;
   try {
     DataSource ds = getDataSource();
     con = ds.getConnection();
     if (executeOnlyIf(con, onlyIfQuery)) {
       stmt = con.createStatement();
       if (query != null) {
         executeQuery(stmt, query);
       } else if (update != null) {
         executeUpdate(stmt, update);
       } else {
         throw new IllegalStateException("Both query and update properties are unset");
       }
     } else {
       LOG.debug("Skipped because of " + onlyIfQuery);
     }
   } catch (RuntimeException e) {
     throw e;
   } catch (Throwable t) {
     if (ignore.matcher(t.getMessage()).matches()) {
       LOG.info("Ignoring " + t.getMessage());
     } else {
       throw new RuntimeException(t.getMessage(), t);
     }
   } finally {
     try {
       if (stmt != null) {
         stmt.close();
       }
     } catch (Exception g) {
     }
     try {
       if (con != null) {
         con.close();
       }
     } catch (Exception g) {
     }
   }
 }
コード例 #24
0
ファイル: BitrateLabeler.java プロジェクト: mihxil/mmbase
 @Override
 protected void label(URLComposer uc) {
   for (Map.Entry<String, BitrateInfo> entry : bitrates.entrySet()) {
     int bitrate = uc.getSource().getIntValue("bitrate");
     if (entry.getValue().matches(bitrate)) {
       log.debug("" + bitrate + " matched " + entry);
       if (overwrite || !uc.getInfo().containsKey(key)) {
         uc.getInfo().put(key, entry.getKey());
       }
     }
   }
 }
コード例 #25
0
ファイル: BasicFramework.java プロジェクト: mihxil/mmbase
 @Override
 public String getUrl(
     String path, Map<String, ?> parameters, Parameters frameworkParameters, boolean escapeAmps)
     throws FrameworkException {
   Url link = urlConverter.getUrl(path, parameters, frameworkParameters, escapeAmps);
   log.debug("got " + link + " from " + urlConverter);
   if (link == Url.NOT) {
     return fallbackConverter.getUrl(path, parameters, frameworkParameters, escapeAmps).getUrl();
   } else {
     return link.getUrl();
   }
 }
コード例 #26
0
ファイル: PageMaster.java プロジェクト: mihxil/mmbase
 /**
  * Performs general periodic maintenance. This routine handles alle open pages/main and
  * pages/mirror file service requests. These requests are obtained from the netfiles builder. For
  * each file that should be serviced, the filechange method is called. This routine handles a
  * maximum of 10 page/main, and 50 page/mirror service calls each time it is called. The first
  * time this method is call, nothing happens (?)
  *
  * @return <code>true</code> if maintenance was performed, <code>false</code> otherwise
  */
 public boolean probeCall() {
   if (first) {
     // skip first time this method is called
     first = false;
   } else {
     // handle up to 10 pages/main fileservice requests
     try {
       Netfiles bul = (Netfiles) Vwms.getMMBase().getMMObject("netfiles");
       // Enumeration e=bul.search("WHERE service='pages' AND subservice='main' AND
       // status="+Netfiles.STATUS_REQUEST+" ORDER BY number DESC");
       Enumeration e =
           bul.search("service=='pages'+subservice=='main'+status=" + Netfiles.STATUS_REQUEST);
       int i = 0;
       while (e.hasMoreElements() && i < 10) {
         MMObjectNode node = (MMObjectNode) e.nextElement();
         fileChange("" + node.getIntValue("number"), "c");
         i++;
       }
     } catch (Exception e) {
       log.error(Logging.stackTrace(e));
     }
     // handle up to 50 pages/mirror fileservice requests
     try {
       Netfiles bul = (Netfiles) Vwms.getMMBase().getMMObject("netfiles");
       Enumeration e =
           bul.search("service=='pages'+subservice=='mirror'+status=" + Netfiles.STATUS_REQUEST);
       // Enumeration e=bul.search("WHERE service='pages' AND subservice='mirror' AND
       // status="+Netfiles.STATUS_REQUEST+" ORDER BY number DESC");
       int i = 0;
       while (e.hasMoreElements() && i < 50) {
         MMObjectNode node = (MMObjectNode) e.nextElement();
         fileChange("" + node.getIntValue("number"), "c");
         i++;
       }
     } catch (Exception e) {
       log.error(Logging.stackTrace(e));
     }
   }
   return true;
 }
コード例 #27
0
ファイル: TypeRel.java プロジェクト: mihxil/mmbase
  /*
   * (non-Javadoc)
   * @see org.mmbase.module.core.MMObjectBuilder#notify(org.mmbase.core.event.NodeEvent)
   */
  @Override
  public void notify(NodeEvent event) {
    if (log.isDebugEnabled()) {
      log.debug(
          "Changed "
              + event.getMachine()
              + " "
              + event.getNodeNumber()
              + " "
              + event.getBuilderName()
              + " "
              + NodeEvent.newTypeToOldType(event.getType()));
    }
    if (tableName.equals(event.getBuilderName())) {
      if (event.getType() == Event.TYPE_NEW) {
        MMObjectNode typeRelNode = getNode(event.getNodeNumber());
        if (typeRelNode != null) {
          Set<MMObjectNode> newTypeRels = addCacheEntry(typeRelNode, true);
          log.service("Added to typerelcache: " + newTypeRels);
        } else {
          log.warn("Could not found typerel node with number " + event.getNodeNumber());
        }

      } else {
        // something else changed in a typerel node? reread the complete typeRelNodes Set
        log.service(
            "Received '" + event + "' which is about typrels. Now re-reading the entire cache");
        readCache();
      }
      // also, clear all query-caches, because result may change by this. See MMB-348
      for (Cache qc : CacheManager.getMap().values()) {
        if (qc instanceof QueryResultCache) {
          qc.clear();
        }
      }
    }
    super.notify(event);
  }
コード例 #28
0
 /**
  * Jdbc connection pooling of MMBase would kill the statement if too duratious. This produces a
  * 'direct connection' in that case, to circumvent that problem (Indexing queries _may_ take a
  * while).
  */
 protected Connection getDirectConnection() throws SQLException {
   directConnections++;
   try {
     if (dataSource instanceof GenericDataSource) {
       return ((GenericDataSource) dataSource).getDirectConnection();
     } else {
       return dataSource.getConnection();
     }
   } catch (SQLException sqe) {
     log.error("With direct connection #" + directConnections + ": " + sqe.getMessage());
     throw sqe;
   } catch (Throwable t) {
     throw new RuntimeException("direct connection #" + directConnections, t);
   }
 }
コード例 #29
0
ファイル: SwingRTFExtractor.java プロジェクト: mihxil/mmbase
 @Override
 public String extract(InputStream input) throws Exception {
   log.debug("extract stream");
   String result = null;
   DefaultStyledDocument styledDoc = new DefaultStyledDocument();
   try {
     new RTFEditorKit().read(input, styledDoc, 0);
     result = styledDoc.getText(0, styledDoc.getLength());
   } catch (IOException e) {
     throw new Exception("Cannot extract text from a RTF document", e);
   } catch (BadLocationException e) {
     throw new Exception("Cannot extract text from a RTF document", e);
   }
   return result;
 }
コード例 #30
0
ファイル: SqlExecutor.java プロジェクト: mihxil/mmbase
 protected boolean executeOnlyIf(Connection con, String q) throws SQLException {
   if (q == null) return true;
   Statement stmt = null;
   try {
     stmt = con.createStatement();
     q = q.replace("$PREFIX", getPrefix());
     LOG.debug(" Executing query " + q);
     ResultSet rs = stmt.executeQuery(q);
     rs.next();
     boolean res = rs.getBoolean(1);
     LOG.debug("Result: " + res);
     return res;
   } catch (SQLException sqe) {
     LOG.error(sqe.getMessage() + " from " + q);
     throw sqe;
   } finally {
     try {
       if (stmt != null) {
         stmt.close();
       }
     } catch (Exception g) {
     }
   }
 }