Example usage for java.util.logging Level FINER

List of usage examples for java.util.logging Level FINER

Introduction

In this page you can find the example usage for java.util.logging Level FINER.

Prototype

Level FINER

To view the source code for java.util.logging Level FINER.

Click Source Link

Document

FINER indicates a fairly detailed tracing message.

Usage

From source file:com.google.enterprise.connector.salesforce.storetype.DBStore.java

public DocListEntry getDocsImmediatelyAfter(String checkpoint) {
    DatabaseMetaData dbm = null;/*from w  w w  . j  a  v  a 2  s  .c o m*/
    Connection connection = null;

    try {

        connection = ds.getConnection();
        connection.setAutoCommit(true);

        dbm = connection.getMetaData();
        //get the most recent database row after 'checkpoint'
        if (dbm.getDatabaseProductName().equals("MySQL")) {
            Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            String update_stmt = "select crawl_set,insert_timestamp,UNCOMPRESS(crawl_data) as cdata from "
                    + this.instance_table + " where crawl_set>" + checkpoint + "  LIMIT 1";
            logger.log(Level.FINER, update_stmt);
            ResultSet rs = statement.executeQuery(update_stmt);

            boolean ret_rows = rs.first();

            if (!ret_rows) {
                logger.log(Level.FINER, "No Rows Returned.");
                connection.close();
                return null;
            }
            BigDecimal crawl_set = null;
            String crawl_data = null;
            while (ret_rows) {
                crawl_set = rs.getBigDecimal("crawl_set");
                //crawl_data = rs.getString("crawl_data");
                crawl_data = rs.getString("cdata");
                ret_rows = rs.next();
            }

            rs.close();
            statement.close();
            connection.close();

            //BASE64 DECODE 
            byte[] byte_decoded_entry = org.apache.commons.codec.binary.Base64
                    .decodeBase64(crawl_data.getBytes());
            crawl_data = new String(byte_decoded_entry);

            logger.log(Level.INFO, "Returning from DBStore. Index Value: " + crawl_set.toPlainString());
            logger.log(Level.FINEST, "Returning from DBStore. " + crawl_data);
            DocListEntry dret = new DocListEntry(crawl_set.toPlainString(), crawl_data);
            return dret;
        }
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Unable to retrieve docListEntry " + ex);
    }
    return new DocListEntry(checkpoint, null);
}

From source file:com.granule.json.utils.internal.JSONObject.java

/**
 * Internal method to write out all children JSON objects attached to this JSON object.
 * @param writer The writer to use while writing the JSON text.
 * @param depth The indention depth of the JSON text.
 * @param compact Flag to denote whether or not to write in nice indent format, or compact format.
 * @throws IOException Trhown if an error occurs on write.
 *///from   w  w  w . j  a  v a 2  s .c  o m
private void writeChildren(Writer writer, int depth, boolean compact) throws IOException {
    if (logger.isLoggable(Level.FINER))
        logger.entering(className, "writeChildren(Writer, int, boolean)");

    if (!jsonObjects.isEmpty()) {
        Enumeration keys = jsonObjects.keys();
        while (keys.hasMoreElements()) {
            String objName = (String) keys.nextElement();
            Vector vect = (Vector) jsonObjects.get(objName);
            if (vect != null && !vect.isEmpty()) {
                /**
                 * Non-array versus array elements.
                 */
                if (vect.size() == 1) {
                    if (logger.isLoggable(Level.FINEST))
                        logger.logp(Level.FINEST, className, "writeChildren(Writer, int, boolean)",
                                "Writing child object: [" + objName + "]");

                    JSONObject obj = (JSONObject) vect.elementAt(0);
                    obj.writeObject(writer, depth + 1, false, compact);
                    if (keys.hasMoreElements()) {
                        try {
                            if (!compact) {
                                if (!obj.isTextOnlyObject() && !obj.isEmptyObject()) {
                                    writeIndention(writer, depth + 1);
                                }
                                writer.write(",\n");
                            } else {
                                writer.write(",");
                            }
                        } catch (Exception ex) {
                            IOException iox = new IOException("Error occurred on serialization of JSON text.");
                            iox.initCause(ex);
                            throw iox;
                        }
                    } else {
                        if (obj.isTextOnlyObject() && !compact) {
                            writer.write("\n");
                        }
                    }
                } else {
                    if (logger.isLoggable(Level.FINEST))
                        logger.logp(Level.FINEST, className, "writeChildren(Writer, int, boolean)",
                                "Writing array of JSON objects with attribute name: [" + objName + "]");

                    try {
                        if (!compact) {
                            writeIndention(writer, depth + 1);
                            writer.write("\"" + objName + "\"");
                            writer.write(" : [\n");
                        } else {
                            writer.write("\"" + objName + "\"");
                            writer.write(":[");
                        }
                        for (int i = 0; i < vect.size(); i++) {
                            JSONObject obj = (JSONObject) vect.elementAt(i);
                            obj.writeObject(writer, depth + 2, true, compact);

                            /**
                             * Still more we haven't handled.
                             */
                            if (i != (vect.size() - 1)) {
                                if (!compact) {
                                    if (!obj.isTextOnlyObject() && !obj.isEmptyObject()) {
                                        writeIndention(writer, depth + 2);
                                    }
                                    writer.write(",\n");
                                } else {
                                    writer.write(",");
                                }
                            }
                        }

                        if (!compact) {
                            writer.write("\n");
                            writeIndention(writer, depth + 1);
                        }

                        writer.write("]");
                        if (keys.hasMoreElements()) {
                            writer.write(",");
                        }

                        if (!compact) {
                            writer.write("\n");
                        }
                    } catch (Exception ex) {
                        IOException iox = new IOException("Error occurred on serialization of JSON text.");
                        iox.initCause(ex);
                        throw iox;
                    }
                }
            }
        }
    }

    if (logger.isLoggable(Level.FINER))
        logger.exiting(className, "writeChildren(Writer, int, boolean)");
}

From source file:sit.web.client.HttpHelper.java

public HTTPResponse doHttpUrlConnectionRequest(URL url, String method, String contentType, byte[] payload,
        String unamePword64) throws MalformedURLException, ProtocolException, IOException, URISyntaxException {

    if (payload == null) { //make sure payload is initialized
        payload = new byte[0];
    }// w w  w .j a v  a  2  s .  c o m

    boolean isHTTPS = url.getProtocol().equalsIgnoreCase("https");
    HttpURLConnection connection;

    if (isHTTPS) {
        connection = (HttpsURLConnection) url.openConnection();
    } else {
        connection = (HttpURLConnection) url.openConnection();
    }

    connection.setRequestMethod(method);
    connection.setRequestProperty("Host", url.getHost());
    connection.setRequestProperty("Content-Type", contentType);
    connection.setRequestProperty("Content-Length", String.valueOf(payload.length));

    if (isHTTPS) {
        connection.setRequestProperty("Authorization", "Basic " + unamePword64);
    }

    Logger.getLogger(HttpHelper.class.getName()).log(Level.FINER,
            "trying to connect:\n" + method + " " + url + "\nhttps:" + isHTTPS + "\nContentType:" + contentType
                    + "\nContent-Length:" + String.valueOf(payload.length));

    connection.setDoInput(true);
    if (payload.length > 0) {
        // open up the output stream of the connection
        connection.setDoOutput(true);
        FilterOutputStream output = new FilterOutputStream(connection.getOutputStream());

        // write out the data
        output.write(payload);
        output.close();
    }

    HTTPResponse response = new HTTPResponse(method + " " + url.toString(), payload, Charset.defaultCharset()); //TODO forward charset ot this method

    response.code = connection.getResponseCode();
    response.message = connection.getResponseMessage();

    Logger.getLogger(HttpHelper.class.getName()).log(Level.FINE,
            "received response: " + response.message + " with code: " + response.code);

    if (response.code != 500) {
        byte[] buffer = new byte[20480];

        ByteBuilder bytes = new ByteBuilder();

        // get ready to read the response from the cgi script
        DataInputStream input = new DataInputStream(connection.getInputStream());
        boolean done = false;
        while (!done) {
            int readBytes = input.read(buffer);
            done = (readBytes == -1);

            if (!done) {
                bytes.append(buffer, readBytes);
            }
        }
        input.close();
        response.reply = bytes.toString(Charset.defaultCharset());
    }
    return response;
}

From source file:com.google.enterprise.connector.sharepoint.client.SiteDataHelper.java

/**
 * Gets the collection of all the lists on the sharepoint server which are of
 * a given type. E.g., DocumentLibrary//www .  j  a va  2 s  . c  om
 *
 * @param webstate The web from which the list/libraries are to be discovered
 * @return list of BaseList objects.
 */
public List<ListState> getNamedLists(final WebState webstate) {
    final ArrayList<ListState> listCollection = new ArrayList<ListState>();
    if (webstate == null) {
        LOGGER.warning("Unable to get the list collection because webstate is null");
        return listCollection;
    }

    final ArrayOf_sListHolder vLists = Util.makeWSRequest(sharepointClientContext, siteDataWS,
            new Util.RequestExecutor<ArrayOf_sListHolder>() {
                public ArrayOf_sListHolder onRequest(final BaseWS ws) throws Throwable {
                    return ((SiteDataWS) ws).getListCollection();
                }

                public void onError(final Throwable e) {
                    LOGGER.log(Level.WARNING, "Call to getListCollection failed.", e);
                }
            });
    if (vLists == null) {
        LOGGER.log(Level.WARNING, "Unable to get the list collection");
        return listCollection;
    }

    final Collator collator = Util.getCollator();

    try {
        final _sList[] sl = vLists.value;

        if (sl != null) {
            webstate.setExisting(true);
            for (_sList element : sl) {
                String url = null;
                String strBaseTemplate = null;

                if (element == null) {
                    continue;
                }

                final String baseType = element.getBaseType();
                LOGGER.log(Level.FINE, "Base Type returned by the Web Service : " + baseType);
                if (!collator.equals(baseType, (SPConstants.DISCUSSION_BOARD))
                        && !collator.equals(baseType, (SPConstants.DOC_LIB))
                        && !collator.equals(baseType, (SPConstants.GENERIC_LIST))
                        && !collator.equals(baseType, (SPConstants.ISSUE))
                        && !collator.equals(baseType, (SPConstants.SURVEYS))) {
                    LOGGER.log(Level.WARNING, "Skipping List [{0}] with unsupported base type [{1}]",
                            new Object[] { element.getTitle(), baseType });
                    continue;
                }
                MessageElement listMetadata = getListMetadata(element.getInternalName());
                if (listMetadata == null) {
                    LOGGER.log(Level.WARNING, "Unable to get metadata for List [{0}]. Skipping List",
                            element.getTitle());
                    continue;
                }
                String rootFolder = getMetadataAttributeForList(listMetadata, "RootFolder");
                if (Strings.isNullOrEmpty(rootFolder)) {
                    LOGGER.log(Level.WARNING, "Unable to get Root Folder for List [{0}]. Skipping List",
                            element.getTitle());
                    continue;
                }
                String defaultViewItemUrl = getMetadataAttributeForList(listMetadata, "DefaultViewItemUrl");
                if (Strings.isNullOrEmpty(defaultViewItemUrl)) {
                    LOGGER.log(Level.WARNING,
                            "Unable to get default View Item Url " + "for List [{0}]. Skipping List",
                            element.getTitle());
                    continue;
                }
                LOGGER.log(Level.FINE, "List [{0}] Root Folder [{1}] Default View Item URL [{2}]",
                        new Object[] { element.getTitle(), rootFolder, defaultViewItemUrl });
                String siteUrl = sharepointClientContext.getSiteURL();
                if (Strings.isNullOrEmpty(element.getDefaultViewUrl())) {
                    LOGGER.log(Level.WARNING,
                            "List [{0}] with empty default view URL." + " Using root folder for List URL.",
                            element.getTitle());
                    StringBuilder listUrl = new StringBuilder(siteUrl);
                    if (!siteUrl.endsWith("/")) {
                        listUrl.append("/");
                    }
                    listUrl.append(rootFolder);
                    url = listUrl.toString();
                } else {
                    url = Util.getWebApp(sharepointClientContext.getSiteURL()) + element.getDefaultViewUrl();
                }

                LOGGER.log(Level.INFO, "List url for List [{0}] is [{1}]",
                        new Object[] { element.getTitle(), url });

                strBaseTemplate = element.getBaseTemplate();
                if (strBaseTemplate == null) {
                    strBaseTemplate = SPConstants.NO_TEMPLATE;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_SLIDELIBRARY)) {// for
                    // SlideLibrary
                    strBaseTemplate = SPConstants.BT_SLIDELIBRARY;
                } else if (collator.equals(strBaseTemplate,
                        SPConstants.ORIGINAL_BT_TRANSLATIONMANAGEMENTLIBRARY)) {// for
                    // TranslationManagementLibrary
                    strBaseTemplate = SPConstants.BT_TRANSLATIONMANAGEMENTLIBRARY;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_TRANSLATOR)) {// for
                    // Translator
                    strBaseTemplate = SPConstants.BT_TRANSLATOR;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_REPORTLIBRARY)) {// for
                    // ReportLibrary
                    strBaseTemplate = SPConstants.BT_REPORTLIBRARY;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_PROJECTTASK)) {// for
                    // ReportLibrary
                    strBaseTemplate = SPConstants.BT_PROJECTTASK;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_SITESLIST)) {// for
                    // ReportLibrary
                    strBaseTemplate = SPConstants.BT_SITESLIST;
                } else {
                    // for FormLibrary
                    for (String formTemplate : sharepointClientContext.getInfoPathBaseTemplate()) {
                        if (collator.equals(strBaseTemplate, formTemplate)) {
                            strBaseTemplate = SPConstants.BT_FORMLIBRARY;
                            break;
                        }
                    }
                }

                LOGGER.config("List URL :" + url);

                // Children of all URLs are discovered
                ListState list = new ListState(element.getInternalName(), element.getTitle(),
                        element.getBaseType(), Util.siteDataStringToCalendar(element.getLastModified()),
                        strBaseTemplate, url, webstate);

                list.setInheritedSecurity(element.isInheritedSecurity());
                list.setApplyReadSecurity(element.getReadSecurity() == 2);

                String myNewListConst = "";
                LOGGER.log(Level.FINE, "getting listConst for list URL [{0}]", defaultViewItemUrl);
                if (defaultViewItemUrl != null) {
                    final StringTokenizer strTokList = new StringTokenizer(defaultViewItemUrl,
                            SPConstants.SLASH);
                    if (null != strTokList) {
                        while ((strTokList.hasMoreTokens()) && (strTokList.countTokens() > 1)) {
                            final String listToken = strTokList.nextToken();
                            if (list.isDocumentLibrary() && listToken.equals(SPConstants.FORMS_LIST_URL_SUFFIX)
                                    && (strTokList.countTokens() == 1)) {
                                break;
                            }
                            if (null != listToken) {
                                myNewListConst += listToken + SPConstants.SLASH;
                            }
                        }
                        list.setListConst(myNewListConst);
                        LOGGER.log(Level.CONFIG, "using listConst [ " + myNewListConst + " ] for list URL [ "
                                + defaultViewItemUrl + " ] ");

                        // Apply the URL filter here

                        // check if the entire list subtree is to excluded
                        // by comparing the prefix of the list URL with the
                        // patterns
                        if (sharepointClientContext
                                .isIncludedUrl(webstate.getWebUrl() + SPConstants.SLASH + myNewListConst)) {
                            // is included check if actual list url itself
                            // is to be excluded
                            if (sharepointClientContext.isIncludedUrl(url, LOGGER)) {
                                // if a List URL is included, it WILL be
                                // sent as a
                                // Document
                                list.setSendListAsDocument(true);
                            } else {
                                // if a List URL is EXCLUDED, it will NOT be
                                // sent as a
                                // Document
                                list.setSendListAsDocument(false);
                            }
                            // add the attribute(Metadata to the list )
                            list = getListWithAllAttributes(list, element);

                            listCollection.add(list);
                        } else {
                            // entire subtree is to be excluded
                            // do not construct list state
                            LOGGER.finest("Excluding " + url + " because entire subtree of " + myNewListConst
                                    + " is excluded");
                        }
                    }
                }

                // Sort the base list
                Collections.sort(listCollection);
            }
        }
    } catch (final Throwable e) {
        LOGGER.log(Level.FINER, e.getMessage(), e);
    }

    if (listCollection.size() > 0) {
        LOGGER.info("Discovered " + listCollection.size() + " lists/libraries under site [ " + webstate
                + " ] for crawling");
    } else {
        LOGGER.config("No lists/libraries to crawl under site [ " + webstate + " ]");
    }
    return listCollection;
}

From source file:jenkins.security.ClassFilterImpl.java

@Override
public boolean isBlacklisted(String name) {
    if (Main.isUnitTest && name.contains("$$EnhancerByMockitoWithCGLIB$$")) {
        mockOff();/*w  ww. j  av a  2  s.  c om*/
        return false;
    }
    for (CustomClassFilter f : ExtensionList.lookup(CustomClassFilter.class)) {
        Boolean r = f.permits(name);
        if (r != null) {
            if (r) {
                LOGGER.log(Level.FINER, "{0} specifies a policy for {1}: {2}", new Object[] { f, name, true });
            } else {
                notifyRejected(null, name, String.format("%s specifies a policy for %s: %s", f, name, r));
            }

            return !r;
        }
    }
    // could apply a cache if the pattern search turns out to be slow
    if (ClassFilter.STANDARD.isBlacklisted(name)) {
        if (SUPPRESS_ALL) {
            notifyRejected(null, name, String.format(
                    "would normally reject %s according to standard blacklist; see https://jenkins.io/redirect/class-filter/",
                    name));
            return false;
        }
        notifyRejected(null, name, String.format(
                "rejecting %s according to standard blacklist; see https://jenkins.io/redirect/class-filter/",
                name));
        return true;
    } else {
        return false;
    }
}

From source file:com.ibm.jaggr.core.impl.AbstractAggregatorImpl.java

protected void processResourceRequest(HttpServletRequest req, HttpServletResponse resp, IResource res,
        String path) {//from  ww w. ja v  a2  s .c om
    final String sourceMethod = "processRequest"; //$NON-NLS-1$
    boolean isTraceLogging = log.isLoggable(Level.FINER);
    if (isTraceLogging) {
        log.entering(AbstractAggregatorImpl.class.getName(), sourceMethod,
                new Object[] { req, resp, res, path });
    }
    try {
        URI uri = res.getURI();
        if (path != null && path.length() > 0 && !uri.getPath().endsWith("/")) { //$NON-NLS-1$
            // Make sure we resolve against a folder path
            uri = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath() + "/", uri.getQuery(), //$NON-NLS-1$
                    uri.getFragment());
            res = newResource(uri);
        }
        IResource resolved = res.resolve(path);
        if (!resolved.exists()) {
            throw new NotFoundException(resolved.getURI().toString());
        }
        resp.setDateHeader("Last-Modified", resolved.lastModified()); //$NON-NLS-1$
        int expires = getConfig().getExpires();
        resp.addHeader("Cache-Control", //$NON-NLS-1$
                "public" + (expires > 0 ? (", max-age=" + expires) : "") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        );
        InputStream is = res.resolve(path).getInputStream();
        OutputStream os = resp.getOutputStream();
        CopyUtil.copy(is, os);
    } catch (NotFoundException e) {
        if (log.isLoggable(Level.INFO)) {
            log.log(Level.INFO, e.getMessage() + " - " + req.getRequestURI(), e); //$NON-NLS-1$
        }
        resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
    } catch (Exception e) {
        if (log.isLoggable(Level.WARNING)) {
            log.log(Level.WARNING, e.getMessage() + " - " + req.getRequestURI(), e); //$NON-NLS-1$
        }
        resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    if (isTraceLogging) {
        log.exiting(AbstractAggregatorImpl.class.getName(), sourceMethod);
    }

}

From source file:com.stratuscom.harvester.codebase.ClassServer.java

private boolean processRequest(Socket sock) {
    try {/*  w ww.j  a v a 2 s.c  o m*/
        DataOutputStream out = new DataOutputStream(sock.getOutputStream());
        String req;
        try {
            req = getInput(sock, true);
        } catch (Exception e) {
            logger.log(Level.FINE, "reading request", e);
            return true;
        }
        if (req == null) {
            return true;
        }
        String[] args = new String[3];
        boolean get = req.startsWith("GET ");
        if (!get && !req.startsWith("HEAD ")) {
            processBadRequest(args, out);
        }
        String path = parsePathFromRequest(req, get);
        if (path == null) {
            return processBadRequest(args, out);
        }
        if (args != null) {
            args[0] = path;
        }
        args[1] = sock.getInetAddress().getHostName();
        args[2] = Integer.toString(sock.getPort());

        logger.log(Level.FINER,
                get ? MessageNames.CLASS_SERVER_RECEIVED_REQUEST : MessageNames.CLASS_SERVER_RECEIVED_PROBE,
                args);
        byte[] bytes;
        try {
            bytes = getBytes(path);
        } catch (Exception e) {
            logger.log(Level.WARNING, MessageNames.CLASS_SERVER_EXCEPTION_GETTING_BYTES, e);
            out.writeBytes("HTTP/1.0 500 Internal Error\r\n\r\n");
            out.flush();
            return true;
        }
        if (bytes == null) {
            logger.log(Level.FINE, MessageNames.CLASS_SERVER_NO_CONTENT_FOUND, path);
            out.writeBytes("HTTP/1.0 404 Not Found\r\n\r\n");
            out.flush();
            return true;
        }
        writeHeader(out, bytes);
        if (get) {
            out.write(bytes);
        }
        out.flush();
        return false;
    } catch (Exception e) {
        logger.log(Level.FINE, MessageNames.CLASS_SERVER_EXCEPTION_WRITING_RESPONSE, e);
    } finally {
        try {
            sock.close();
        } catch (IOException e) {
        }
    }
    return false;
}

From source file:com.granule.json.utils.XML.java

/**
 * Method to do the transform from an JSON input stream to a XML stream.
 * Neither input nor output streams are closed.  Closure is left up to the caller.
 *
 * @param JSONStream The XML stream to convert to JSON
 * @param XMLStream The stream to write out JSON to.  The contents written to this stream are always in UTF-8 format.
 * @param verbose Flag to denote whether or not to render the XML text in verbose (indented easy to read), or compact (not so easy to read, but smaller), format.
 *
 * @throws IOException Thrown if an IO error occurs.
 *///from  www . j a v  a  2s .c om
public static void toXml(InputStream JSONStream, OutputStream XMLStream, boolean verbose) throws IOException {
    if (logger.isLoggable(Level.FINER)) {
        logger.entering(className, "toXml(InputStream, OutputStream)");
    }

    if (XMLStream == null) {
        throw new NullPointerException("XMLStream cannot be null");
    } else if (JSONStream == null) {
        throw new NullPointerException("JSONStream cannot be null");
    } else {

        if (logger.isLoggable(Level.FINEST)) {
            logger.logp(Level.FINEST, className, "transform", "Parsing the JSON and a DOM builder.");
        }

        try {
            //Get the JSON from the stream.
            JSONObject jObject = new JSONObject(JSONStream);

            //Create a new document

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbf.newDocumentBuilder();
            Document doc = dBuilder.newDocument();

            if (logger.isLoggable(Level.FINEST)) {
                logger.logp(Level.FINEST, className, "transform", "Parsing the JSON content to XML");
            }

            convertJSONObject(doc, doc.getDocumentElement(), jObject, "jsonObject");

            //Serialize it.
            TransformerFactory tfactory = TransformerFactory.newInstance();
            Transformer serializer = null;
            if (verbose) {
                serializer = tfactory.newTransformer(new StreamSource(new StringReader(styleSheet)));
                ;
            } else {
                serializer = tfactory.newTransformer();
            }
            Properties oprops = new Properties();
            oprops.put(OutputKeys.METHOD, "xml");
            oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
            oprops.put(OutputKeys.VERSION, "1.0");
            oprops.put(OutputKeys.INDENT, "true");
            serializer.setOutputProperties(oprops);
            serializer.transform(new DOMSource(doc), new StreamResult(XMLStream));

        } catch (Exception ex) {
            IOException iox = new IOException("Problem during conversion");
            iox.initCause(ex);
            throw iox;
        }
    }

    if (logger.isLoggable(Level.FINER)) {
        logger.exiting(className, "toXml(InputStream, OutputStream)");
    }
}

From source file:org.b3log.latke.servlet.RequestProcessors.java

/**
 * Scans classpath (classes directory) to discover request processor classes.
 *//*from   www.  j a  v a  2s . co  m*/
private static void discoverFromClassesDir() {
    final String webRoot = AbstractServletListener.getWebRoot();
    final File classesDir = new File(
            webRoot + File.separator + "WEB-INF" + File.separator + "classes" + File.separator);
    @SuppressWarnings("unchecked")
    final Collection<File> classes = FileUtils.listFiles(classesDir, new String[] { "class" }, true);
    final ClassLoader classLoader = RequestProcessors.class.getClassLoader();

    try {
        for (final File classFile : classes) {
            final String path = classFile.getPath();
            final String className = StringUtils
                    .substringBetween(path, "WEB-INF" + File.separator + "classes" + File.separator, ".class")
                    .replaceAll("\\/", ".").replaceAll("\\\\", ".");
            final Class<?> clz = classLoader.loadClass(className);

            if (clz.isAnnotationPresent(RequestProcessor.class)) {
                LOGGER.log(Level.FINER, "Found a request processor[className={0}]", className);
                final Method[] declaredMethods = clz.getDeclaredMethods();

                for (int i = 0; i < declaredMethods.length; i++) {
                    final Method mthd = declaredMethods[i];
                    final RequestProcessing annotation = mthd.getAnnotation(RequestProcessing.class);

                    if (null == annotation) {
                        continue;
                    }

                    addProcessorMethod(annotation, clz, mthd);
                }
            }
        }
    } catch (final Exception e) {
        LOGGER.log(Level.SEVERE, "Scans classpath (classes directory) failed", e);
    }
}

From source file:com.google.enterprise.connector.sharepoint.wsclient.soap.SPSiteDataWS.java

/**
 * Gets the collection of all the lists on the sharepoint server which are of
 * a given type. E.g., DocumentLibrary//from w  ww . java 2s .com
 *
 * @param webstate The web from which the list/libraries are to be discovered
 * @return list of BaseList objects.
 */
public List<ListState> getNamedLists(final WebState webstate) throws SharepointException {
    final ArrayList<ListState> listCollection = new ArrayList<ListState>();
    if (stub == null) {
        LOGGER.warning("Unable to get the list collection because stub is null");
        return listCollection;
    }

    if (webstate == null) {
        LOGGER.warning("Unable to get the list collection because webstate is null");
        return listCollection;
    }

    final Collator collator = Util.getCollator();
    final ArrayOf_sListHolder vLists = new ArrayOf_sListHolder();
    final UnsignedIntHolder getListCollectionResult = new UnsignedIntHolder();

    try {
        stub.getListCollection(getListCollectionResult, vLists);
    } catch (final AxisFault af) { // Handling of username formats for
        // different authentication models.
        if ((SPConstants.UNAUTHORIZED.indexOf(af.getFaultString()) != -1)
                && (sharepointClientContext.getDomain() != null)) {
            final String username = Util.switchUserNameFormat(stub.getUsername());
            LOGGER.log(Level.CONFIG, "Web Service call failed for username [ " + stub.getUsername()
                    + " ]. Trying with " + username);
            stub.setUsername(username);
            try {
                stub.getListCollection(getListCollectionResult, vLists);
            } catch (final Exception e) {
                LOGGER.log(Level.WARNING, "Unable to get List Collection for stubURL[ "
                        + sharepointClientContext.getSiteURL() + " ].", e);
            }
        } else {
            LOGGER.log(Level.WARNING, "Unable to get List Collection for stubURL[ "
                    + sharepointClientContext.getSiteURL() + " ].", af);
        }
    } catch (final Throwable e) {
        LOGGER.log(Level.WARNING,
                "Unable to get List Collection for stubURL[ " + sharepointClientContext.getSiteURL() + " ].",
                e);
    }

    if (vLists == null) {
        LOGGER.log(Level.WARNING, "Unable to get the list collection");
        return listCollection;
    }

    try {
        final _sList[] sl = vLists.value;

        if (sl != null) {
            webstate.setExisting(true);
            for (_sList element : sl) {
                String url = null;
                String strBaseTemplate = null;

                if (element == null) {
                    continue;
                }

                final String baseType = element.getBaseType();
                LOGGER.log(Level.FINE, "Base Type returned by the Web Service : " + baseType);
                if (!collator.equals(baseType, (SPConstants.DISCUSSION_BOARD))
                        && !collator.equals(baseType, (SPConstants.DOC_LIB))
                        && !collator.equals(baseType, (SPConstants.GENERIC_LIST))
                        && !collator.equals(baseType, (SPConstants.ISSUE))
                        && !collator.equals(baseType, (SPConstants.SURVEYS))) {
                    continue;
                }

                url = Util.getWebApp(sharepointClientContext.getSiteURL()) + element.getDefaultViewUrl();

                strBaseTemplate = element.getBaseTemplate();
                if (strBaseTemplate == null) {
                    strBaseTemplate = SPConstants.NO_TEMPLATE;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_SLIDELIBRARY)) {// for
                    // SlideLibrary
                    strBaseTemplate = SPConstants.BT_SLIDELIBRARY;
                } else if (collator.equals(strBaseTemplate,
                        SPConstants.ORIGINAL_BT_TRANSLATIONMANAGEMENTLIBRARY)) {// for
                    // TranslationManagementLibrary
                    strBaseTemplate = SPConstants.BT_TRANSLATIONMANAGEMENTLIBRARY;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_TRANSLATOR)) {// for
                    // Translator
                    strBaseTemplate = SPConstants.BT_TRANSLATOR;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_REPORTLIBRARY)) {// for
                    // ReportLibrary
                    strBaseTemplate = SPConstants.BT_REPORTLIBRARY;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_PROJECTTASK)) {// for
                    // ReportLibrary
                    strBaseTemplate = SPConstants.BT_PROJECTTASK;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_SITESLIST)) {// for
                    // ReportLibrary
                    strBaseTemplate = SPConstants.BT_SITESLIST;
                } else {
                    // for FormLibrary
                    for (String formTemplate : sharepointClientContext.getInfoPathBaseTemplate()) {
                        if (collator.equals(strBaseTemplate, formTemplate)) {
                            strBaseTemplate = SPConstants.BT_FORMLIBRARY;
                            break;
                        }
                    }
                }

                LOGGER.config("List URL :" + url);

                // Children of all URLs are discovered
                ListState list = new ListState(element.getInternalName(), element.getTitle(),
                        element.getBaseType(), Util.siteDataStringToCalendar(element.getLastModified()),
                        strBaseTemplate, url, webstate);

                list.setInheritedSecurity(element.isInheritedSecurity());
                list.setApplyReadSecurity(element.getReadSecurity() == 2);

                String myNewListConst = "";
                final String listUrl = element.getDefaultViewUrl();// e.g.
                // /sites/abc/Lists/Announcements/AllItems.aspx
                LOGGER.log(Level.FINE, "getting listConst for list URL [ " + listUrl + " ] ");
                if ((listUrl != null) /* && (siteRelativeUrl!=null) */) {
                    final StringTokenizer strTokList = new StringTokenizer(listUrl, SPConstants.SLASH);
                    if (null != strTokList) {
                        while ((strTokList.hasMoreTokens()) && (strTokList.countTokens() > 1)) {
                            final String listToken = strTokList.nextToken();
                            if (list.isDocumentLibrary() && listToken.equals(SPConstants.FORMS_LIST_URL_SUFFIX)
                                    && (strTokList.countTokens() == 1)) {
                                break;
                            }
                            if (null != listToken) {
                                myNewListConst += listToken + SPConstants.SLASH;
                            }
                        }
                        list.setListConst(myNewListConst);
                        LOGGER.log(Level.CONFIG,
                                "using listConst [ " + myNewListConst + " ] for list URL [ " + listUrl + " ] ");

                        // Apply the URL filter here

                        // check if the entire list subtree is to excluded
                        // by comparing the prefix of the list URL with the
                        // patterns
                        if (sharepointClientContext
                                .isIncludedUrl(webstate.getWebUrl() + SPConstants.SLASH + myNewListConst)) {
                            // is included check if actual list url itself
                            // is to be excluded
                            if (sharepointClientContext.isIncludedUrl(url)) {
                                // if a List URL is included, it WILL be
                                // sent as a
                                // Document
                                list.setSendListAsDocument(true);
                            } else {
                                // if a List URL is EXCLUDED, it will NOT be
                                // sent as a
                                // Document
                                list.setSendListAsDocument(false);
                                LOGGER.warning("excluding " + url.toString());
                            }
                            // add the attribute(Metadata to the list )
                            list = getListWithAllAttributes(list, element);

                            listCollection.add(list);
                        } else {
                            // entire subtree is to be excluded
                            // do not construct list state
                            LOGGER.warning("Excluding " + url + " because entire subtree of " + myNewListConst
                                    + " is excluded");
                        }
                    }
                }

                // Sort the base list
                Collections.sort(listCollection);
                // dumpcollection(listCollection);
            }
        }
    } catch (final Throwable e) {
        LOGGER.log(Level.FINER, e.getMessage(), e);
        return listCollection;
    }

    if (listCollection.size() > 0) {
        LOGGER.info("Discovered " + listCollection.size() + " lists/libraries under site [ " + webstate
                + " ] for crawling");
    } else {
        LOGGER.config("No lists/libraries to crawl under site [ " + webstate + " ]");
    }
    return listCollection;
}