Example usage for org.dom4j DocumentHelper createDocument

List of usage examples for org.dom4j DocumentHelper createDocument

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createDocument.

Prototype

public static Document createDocument() 

Source Link

Usage

From source file:com.easyjf.generator.AllGenerator.java

License:Apache License

private Document getDocument(String xmlFileName) throws DocumentException {
    SAXReader reader = new SAXReader();
    File file = new File(xmlFileName);
    if (file.exists()) {
        return reader.read(xmlFileName);
    } else {//from w  w  w. j  ava 2 s. c om
        return DocumentHelper.createDocument();
    }
}

From source file:com.ethercis.compositionservice.CompositionService.java

License:Apache License

@QuerySetting(dialect = {
        @QuerySyntax(mode = I_ServiceRunMode.DialectSpace.STANDARD, httpMethod = "GET", method = "create", path = "vehr/composition", responseType = ResponseType.Json),
        @QuerySyntax(mode = I_ServiceRunMode.DialectSpace.EHRSCAPE, httpMethod = "POST", method = "post", path = "rest/v1/composition", responseType = ResponseType.Json) })
public Object create(I_SessionClientProperties props) throws Exception {

    auditSetter.handleProperties(getDataAccess(), props);
    String sessionId = auditSetter.getSessionId();
    String templateId = props.getClientProperty(I_CompositionService.TEMPLATE_ID, (String) null);
    UUID ehrId = retrieveEhrId(sessionId, props);

    UUID committerUuid = auditSetter.getCommitterUuid();
    UUID systemUuid = auditSetter.getSystemUuid();

    I_CompositionService.CompositionFormat format = I_CompositionService.CompositionFormat
            .valueOf(props.getClientProperty(I_CompositionService.FORMAT, "XML"));

    if ((format == CompositionFormat.FLAT || format == CompositionFormat.ECISFLAT)
            && (templateId == null || templateId.length() == 0))
        throw new ServiceManagerException(getGlobal(), SysErrorCode.USER_ILLEGALARGUMENT, ME,
                "Template Id must be specified");

    //get body stuff
    String content = props.getClientProperty(Constants.REQUEST_CONTENT, (String) null);

    if (content == null)
        throw new ServiceManagerException(getGlobal(), SysErrorCode.USER_ILLEGALARGUMENT, ME,
                "Content cannot be empty for a new composition");

    Integer contentLength = (Integer) props.getClientProperty(Constants.REQUEST_CONTENT_LENGTH, (Integer) 0);

    if (content.length() != contentLength)
        throw new ServiceManagerException(getGlobal(), SysErrorCode.USER_ILLEGALARGUMENT, ME,
                "Content may be altered found length =" + content.length() + " expected:" + contentLength);

    //        String contentType = props.getClientProperty(Constants.REQUEST_CONTENT_TYPE, "");

    UUID compositionId;/*from  ww  w  .j ava  2 s.co m*/

    switch (format) {
    case XML:
        CanonicalHandler canonicalHandler = new CanonicalHandler(knowledgeCache.getKnowledgeCache(), templateId,
                null);
        Composition composition = canonicalHandler.build(getGlobal(), content);
        templateId = composition.getArchetypeDetails().getTemplateId().getValue();
        I_CompositionAccess compositionAccess = I_CompositionAccess.getNewInstance(getDataAccess(), composition,
                DateTime.now(), ehrId);
        I_EntryAccess entryAccess = I_EntryAccess.getNewInstance(getDataAccess(), templateId, 0,
                compositionAccess.getId(), composition);
        compositionAccess.addContent(entryAccess);
        compositionId = compositionAccess.commit(committerUuid, systemUuid, auditSetter.getDescription());

        //create an XML response
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("compositionCreateRestResponseData");
        root.addElement("action").addText("CREATE");
        root.addElement("compositionUid").addText(encodeUuid(compositionId, 1));
        root.addElement("meta").addElement("href")
                .addText(Constants.URI_TAG + "?" + encodeURI(null, compositionId, 1, null));
        global.getProperty().set(MethodName.RETURN_TYPE_PROPERTY, "" + MethodName.RETURN_XML);
        return document;

    case ECISFLAT:
        PvCompoHandler pvCompoHandler = new PvCompoHandler(this.getDataAccess(), templateId, null);
        Map<String, String> kvPairs = FlatJsonUtil
                .inputStream2Map(new StringReader(new String(content.getBytes())));
        compositionId = pvCompoHandler.storeComposition(ehrId, kvPairs, auditSetter.getCommitterUuid(),
                auditSetter.getSystemUuid(), auditSetter.getDescription());

        //create json response
        global.getProperty().set(MethodName.RETURN_TYPE_PROPERTY, "" + MethodName.RETURN_JSON);
        Map<String, Object> retmap = new HashMap<>();
        retmap.put("action", "CREATE");
        retmap.put(COMPOSITION_UID, encodeUuid(compositionId, 1));
        Map<String, Map<String, String>> metaref = MetaBuilder.add2MetaMap(null, "href",
                Constants.URI_TAG + "?" + encodeURI(null, compositionId, 1, null));
        retmap.putAll(metaref);
        return retmap;

    case FLAT:
        I_FlatJsonCompositionConverter flatJsonCompositionConverter = FlatJsonCompositionConverter
                .getInstance(getDataAccess().getKnowledgeManager());
        Map flatMap = FlatJsonUtil.inputStream2Map(new StringReader(new String(content.getBytes())));
        Composition newComposition = flatJsonCompositionConverter.toComposition(templateId, flatMap);
        I_CompositionAccess access = I_CompositionAccess.getNewInstance(getDataAccess(), newComposition,
                DateTime.now(), ehrId);
        I_EntryAccess entry = I_EntryAccess.getNewInstance(getDataAccess(), templateId, 0, access.getId(),
                newComposition);
        access.addContent(entry);
        compositionId = access.commit(committerUuid, systemUuid, auditSetter.getDescription());
        //create json response
        global.getProperty().set(MethodName.RETURN_TYPE_PROPERTY, "" + MethodName.RETURN_JSON);
        retmap = new HashMap<>();
        retmap.put("action", "CREATE");
        retmap.put(COMPOSITION_UID, encodeUuid(compositionId, 1));
        metaref = MetaBuilder.add2MetaMap(null, "href",
                Constants.URI_TAG + "?" + encodeURI(null, compositionId, 1, null));
        retmap.putAll(metaref);
        return retmap;

    default:
        throw new ServiceManagerException(getGlobal(), SysErrorCode.USER_ILLEGALARGUMENT, ME,
                "This format is not supported:" + format);
    }
}

From source file:com.eurelis.opencms.ant.task.ManifestBuilderTask.java

License:Open Source License

public Document createDocument() {

    document = DocumentHelper.createDocument();
    document.setXMLEncoding("UTF-8");
    Element root = document.addElement("export");

    Element info = root.addElement("info");
    if (creator != null)
        info.addElement("creator").addText(creator);
    if (opencmsversion != null)
        info.addElement("opencms_version").addText(opencmsversion);
    info.addElement("createdate").addText(dateformat.format(new Date()));
    if (project != null)
        info.addElement("infoproject").addText(project);
    if (exportversion != null)
        info.addElement("export_version").addText(exportversion);

    Element module = root.addElement("module");

    if (name != null)
        module.addElement("name").addText(name);
    if (nicename != null)
        module.addElement("nicename").addText(nicename);
    if (group != null)
        module.addElement("group").addText(group);
    if (moduleclass != null)
        module.addElement("class").addText(moduleclass);
    if (moduledescription != null)
        module.addElement("description").add(new FlyweightCDATA(moduledescription));
    if (version != null)
        module.addElement("version").addText(version);
    if (authorname != null)
        module.addElement("authorname").add(new FlyweightCDATA(authorname));
    if (authoremail != null)
        module.addElement("authoremail").add(new FlyweightCDATA(authoremail));
    module.addElement("datecreated").addText(dateformat.format(new Date()));
    module.addElement("userinstalled").addText(userinstalled);
    module.addElement("dateinstalled").addText(dateinstalled);

    Element dependenciesBlock = module.addElement("dependencies");
    for (Dependency dep : dependencies) {
        dependenciesBlock.addElement("dependency").addAttribute("name", dep.getName()).addAttribute("version",
                dep.getVersion());/*from   ww  w  .j  ava2 s  .c  o m*/
    }

    Element exportPointsBlock = module.addElement("exportpoints");
    for (ExportPoint ep : exportpoints) {
        exportPointsBlock.addElement("exportpoint").addAttribute("uri", ep.getSrc()).addAttribute("destination",
                ep.getDst());
    }

    Element resourcesBlock = module.addElement("resources");
    for (Resource res : resources) {
        resourcesBlock.addElement("resource").addAttribute("uri", res.getUri());
    }

    Element parametersBlock = module.addElement("parameters");
    for (Parameter par : parameters) {
        parametersBlock.addElement("param").addAttribute("name", par.getName()).addText(par.getValue());
    }

    insertResourceTypes(module);
    insertExplorerTypes(module);

    if (!filesets.isEmpty()) {

        Element files = root.addElement("files");

        for (FileSet fileset : filesets) {
            DirectoryScanner ds = fileset.getDirectoryScanner(fileset.getProject());
            String[] dirs = ds.getIncludedDirectories();
            String[] filesColl = ds.getIncludedFiles();

            String[] excluDirsArray = ds.getExcludedDirectories();
            List<String> excluDirs = new ArrayList<String>();
            excluDirs.addAll(Arrays.asList(excluDirsArray));

            String[] excluFilesArray = ds.getExcludedFiles();
            List<String> excluFiles = new ArrayList<String>();
            excluFiles.addAll(Arrays.asList(excluFilesArray));

            CmsUUID.init("B4:B6:76:78:7F:3E");

            // FOLDERS MANAGEMENT
            for (int i = 0; i < dirs.length; i++) {
                String filepath = dirs[i];
                String filepathUnix = dirs[i].replace(SEPARATOR, "/");
                if (dirs[i] != "") {
                    Element tmpFile = files.addElement("file");
                    tmpFile.addElement("destination").addText(filepathUnix);

                    String folderPropertiesPath = getProject().getBaseDir() + SEPARATOR + srcfolder + SEPARATOR
                            + folderPropertiesPath(filepath);
                    String tmpType = getEurelisProperty("type", folderPropertiesPath);
                    if (null == tmpType) {
                        tmpType = "folder";
                    }
                    tmpFile.addElement("type").addText(tmpType);

                    if (generateuuids) {
                        Element uuidNode = tmpFile.addElement("uuidstructure");
                        String tmpUUID = getEurelisProperty("structureUUID", folderPropertiesPath);
                        if (null != tmpUUID)
                            uuidNode.addText(tmpUUID);
                        else
                            uuidNode.addText(new CmsUUID().toString());
                        // AJOUTER SAUVEGARDE DU NOUVEL UUID
                    }

                    long date = new File(
                            getProject().getBaseDir() + SEPARATOR + srcfolder + SEPARATOR + filepath)
                                    .lastModified();
                    if (0L == date)
                        date = new Date().getTime();
                    String formattedDate = dateformat.format(date);
                    tmpFile.addElement("datelastmodified").addText(formattedDate);
                    tmpFile.addElement("userlastmodified").addText("Admin");
                    // WARNING : CONSTANT VALUE
                    tmpFile.addElement("datecreated").addText(formattedDate);
                    // WARNING : CONSTANT VALUE
                    tmpFile.addElement("usercreated").addText("Admin");
                    tmpFile.addElement("flags").addText("0");

                    Element properties = tmpFile.addElement("properties");
                    // props detection and implementation
                    String tmpPropFile = folderPropertiesPath;
                    addPropertiesToTree(properties, tmpPropFile);

                    String tmpAccessFile = getProject().getBaseDir() + SEPARATOR + srcfolder + SEPARATOR
                            + folderAccessesPath(filepath);
                    addAccessesToTree(tmpFile, tmpAccessFile);
                }
            }
            // FILES MANAGEMENT
            for (int i = 0; i < filesColl.length; i++) {
                String filepath = filesColl[i];
                String filepathUnix = filesColl[i].replace(SEPARATOR, "/");
                if (filesColl[i] != "") {
                    Element tmpFile = files.addElement("file");
                    tmpFile.addElement("source").addText(filepathUnix);
                    tmpFile.addElement("destination").addText(filepathUnix);

                    String propertiesFilepath = getProject().getBaseDir() + SEPARATOR + srcfolder + SEPARATOR
                            + filePropertiesPath(filepath);
                    String tmpType = getEurelisProperty("type", propertiesFilepath);
                    if (null == tmpType) {
                        if (filepathUnix.endsWith(".config"))
                            tmpType = "module_config";
                        else if (filepathUnix.endsWith("main.jsp"))
                            tmpType = "containerpage_template";
                        else if (filepathUnix.endsWith(".jsp"))
                            tmpType = "jsp";
                        else if (filepathUnix.endsWith(".png") || filepathUnix.endsWith(".gif")
                                || filepathUnix.endsWith(".jpg") || filepathUnix.endsWith(".jpeg"))
                            tmpType = "image";
                        else if (filepathUnix.endsWith(".html") && filepathUnix.contains("/models/"))
                            tmpType = "containerpage";
                        else
                            tmpType = "plain";
                    }
                    tmpFile.addElement("type").addText(tmpType);

                    if (generateuuids) {
                        Element uuidNode = tmpFile.addElement("uuidresource");
                        Element uuidNode2 = tmpFile.addElement("uuidstructure");
                        String tmpUUID = getEurelisProperty("resourceUUID", propertiesFilepath);
                        if (null != tmpUUID)
                            uuidNode.addText(tmpUUID);
                        else
                            uuidNode.addText(new CmsUUID().toString());
                        tmpUUID = getEurelisProperty("structureUUID", propertiesFilepath);
                        if (null != tmpUUID)
                            uuidNode2.addText(tmpUUID);
                        else
                            uuidNode2.addText(new CmsUUID().toString());
                    }

                    long date = new File(
                            getProject().getBaseDir() + SEPARATOR + srcfolder + SEPARATOR + filepath)
                                    .lastModified();
                    if (0L == date)
                        date = new Date().getTime();
                    String formattedDate = dateformat.format(date);

                    tmpFile.addElement("datelastmodified").addText(formattedDate);
                    tmpFile.addElement("userlastmodified").addText("Admin");
                    tmpFile.addElement("datecreated").addText(formattedDate);
                    tmpFile.addElement("usercreated").addText("Admin");
                    tmpFile.addElement("flags").addText("0");
                    Element properties = tmpFile.addElement("properties");
                    String tmpPropFile = propertiesFilepath;
                    addPropertiesToTree(properties, tmpPropFile);

                    tmpFile.addElement("accesscontrol");

                }
            }
        }
    }

    return document;
}

From source file:com.ewcms.content.particular.service.ProjectBasicService.java

License:Open Source License

public Document exportXml(List<Long> projectBasicIds) {
    Document document = DocumentHelper.createDocument();

    Element root = document.addElement("MetaDatas");
    Element metaViewData = root.addElement("MetaViewData");

    if (projectBasicIds.isEmpty())
        return document;

    for (Long projectBasicId : projectBasicIds) {
        ProjectBasic projectBasic = projectBasicDAO.get(projectBasicId);

        Element projects = metaViewData.addElement("PROPERTIES");

        Element code = projects.addElement("?");
        code.addText(projectBasic.getCode() == null ? "" : projectBasic.getCode());

        Element name = projects.addElement("??");
        name.addText(projectBasic.getName() == null ? "" : projectBasic.getName());

        Element buildTime = projects.addElement("");
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (projectBasic.getBuildTime() != null) {
            buildTime.addText(dateFormat.format(projectBasic.getBuildTime()));
        } else {//from w  w  w  .  jav  a2 s  . co  m
            buildTime.addText("");
        }

        Element investmentScale = projects.addElement("");
        investmentScale
                .addText(projectBasic.getInvestmentScale() == null ? "" : projectBasic.getInvestmentScale());

        Element overview = projects.addElement("");
        overview.addText(projectBasic.getOverview() == null ? "" : projectBasic.getOverview());

        Element buildUnit = projects.addElement("??");
        buildUnit.addText(projectBasic.getBuildUnit() == null ? "" : projectBasic.getBuildUnit());

        Element unitPhone = projects.addElement("????");
        unitPhone.addText(projectBasic.getUnitPhone() == null ? "" : projectBasic.getUnitPhone());

        Element unitAddress = projects.addElement("???");
        unitAddress.addText(projectBasic.getUnitAddress() == null ? "" : projectBasic.getUnitAddress());

        Element zoningCode_code = projects.addElement("?");
        if (projectBasic.getZoningCode() != null)
            zoningCode_code.addText(projectBasic.getZoningCode().getCode() == null ? ""
                    : projectBasic.getZoningCode().getCode());
        else
            zoningCode_code.addText("");

        Element organizationCode = projects.addElement("?");
        organizationCode
                .addText(projectBasic.getOrganizationCode() == null ? "" : projectBasic.getOrganizationCode());

        Element industryCode_code = projects.addElement("?");
        if (projectBasic.getIndustryCode() != null)
            industryCode_code.addText(projectBasic.getIndustryCode().getCode() == null ? ""
                    : projectBasic.getIndustryCode().getCode());
        else
            industryCode_code.addText("");

        Element category = projects.addElement("");
        category.addText(projectBasic.getCategory() == null ? "" : projectBasic.getCategory());

        Element unitId = projects.addElement("???");
        unitId.addText(projectBasic.getUnitId() == null ? "" : projectBasic.getUnitId());

        Element approvalRecord_code = projects.addElement("?");
        if (projectBasic.getApprovalRecord() != null)
            approvalRecord_code.addText(projectBasic.getApprovalRecord().getCode() == null ? ""
                    : projectBasic.getApprovalRecord().getCode());
        else
            approvalRecord_code.addText("");

        Element address = projects.addElement("?");
        address.addText(projectBasic.getAddress() == null ? "" : projectBasic.getAddress());

        Element bildNature = projects.addElement("");
        if (projectBasic.getBildNature() != null)
            bildNature.addText(projectBasic.getBildNature().getDescription() == null ? ""
                    : projectBasic.getBildNature().getDescription());
        else
            bildNature.addText("");

        Element contact = projects.addElement("?");
        contact.addText(projectBasic.getContact() == null ? "" : projectBasic.getContact());

        Element phone = projects.addElement("??");
        phone.addText(projectBasic.getPhone() == null ? "" : projectBasic.getPhone());

        Element email = projects.addElement("??");
        email.addText(projectBasic.getEmail() == null ? "" : projectBasic.getEmail());
    }
    return document;
}

From source file:com.ewcms.util.XMLUtil.java

License:Open Source License

/**
 * ?Document
 */
public XMLUtil() {
    document = DocumentHelper.createDocument();
}

From source file:com.example.sample.pMainActivity.java

License:Apache License

public Document createXMLDocument() {
    Document doc = null;/* ww w.  j a  va  2 s .  co m*/
    doc = DocumentHelper.createDocument();
    doc.addComment("edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by  ()");
    //  doc.addDocType("class","//By Jack Chen","saveXML.xsd");
    Element root = doc.addElement("class");
    Element company = root.addElement("company");
    Element person = company.addElement("person");
    person.addAttribute("id", "11");
    person.addElement("name").setText("Jack Chen");
    person.addElement("sex").setText("");
    person.addElement("date").setText("2001-04-01");
    person.addElement("email").setText("chen@163.com");
    person.addElement("QQ").setText("2366001");
    return doc;
}

From source file:com.fivepebbles.ProcessFiles.java

License:MIT License

@Override
public void setFiles(String[][] valuesin) {

    //Create a XML file to hold AWS bucket names and related files/folders
    Document mydoc = DocumentHelper.createDocument();
    Element root = mydoc.addElement("s3backup");
    Element bucket1 = null;/*from   w w  w  .  ja va  2s .co m*/

    for (int a1 = 0; a1 < valuesin.length; a1++) {

        for (int b1 = 0; b1 < valuesin[a1].length; b1++) {
            //Bucket names are in index 0
            if (b1 == 0) {
                bucket1 = root.addElement("bucket").addAttribute("name", valuesin[a1][b1]);
            } else {
                if (bucket1 != null & valuesin[a1][b1] != null) {
                    bucket1.addElement("file").addText(valuesin[a1][b1]);
                }
            }
        }
        bucket1 = null;
    }

    //Save files and folders in file system
    FileWriter fWriter2;
    try {
        fWriter2 = new FileWriter(new File("target", "s3files.xml"));
        mydoc.write(fWriter2);
        fWriter2.flush();
        fWriter2.close();
    } catch (IOException e) {
        //***TODO*** log message
        e.printStackTrace();
    }
}

From source file:com.flaptor.hounder.crawler.modules.IndexerModule.java

License:Apache License

private void deleteFromIndex(Page page) {
    org.dom4j.Document dom = DocumentHelper.createDocument();
    Element root = dom.addElement("documentDelete");

    root.addElement("documentId").addText(getDocumentId(page));
    try {//from  w  w  w.  j  av  a2  s  .c  o  m
        int i = pageMapper.mapPage(page);
        while (indexers[i].index(dom) == IndexerReturnCode.RETRY_QUEUE_FULL) {
            try {
                Thread.sleep(indexerBusyRetryTime * 1000);
            } catch (InterruptedException e) {
                logger.debug("Sleep interrupted: " + e, e);
            }
        }
        page.setEmitted(false);
    } catch (Exception e) {
        logger.error(e, e);
    }
}

From source file:com.flaptor.hounder.crawler.modules.IndexerModule.java

License:Apache License

@SuppressWarnings("unchecked")
protected void addToIndex(FetchDocument doc) {

    byte[] content = doc.getContent();
    if (0 == content.length) {
        logger.warn("Page has no data. Ignoring this document.");
        return;/*w w  w. j a va2 s  .c om*/
    }

    Set<String> categories = doc.getCategories();
    Map<String, Object> attributes = doc.getAttributes();
    Map<String, Object> indexableAttributes = doc.getIndexableAttributes();

    // build xml doc
    org.dom4j.Document dom = DocumentHelper.createDocument();
    Element root = dom.addElement("documentAdd");
    Page page = doc.getPage();
    String text = doc.getText();
    String url = page.getUrl();
    String host = getHost(url);
    String title = doc.getTitle(titleLengthLimit);
    String tokenizedHost = tokenizeHost(host);
    String anchorText = getAnchorText(page);

    float categoryBoost = calculateCategoryBoost(attributes);
    float pagerankBoost = calculatePagerankBoost(page);
    float spamrankBoost = calculateSpamrankBoost(page);
    float logBoost = calculateLogBoost(page);
    float freshnessBoost = calculateFreshnessBoost(page);

    // add overall score
    float f1 = factor("category", categoryBoost, categoryBoostDamp);
    float f2 = factor("pagerank", pagerankBoost, pagerankBoostDamp);
    float f3 = factor("spamrank", spamrankBoost, spamrankBoostDamp);
    float f4 = factor("log", logBoost, logBoostDamp);
    float f5 = factor("freshness", freshnessBoost, freshnessBoostDamp);
    float f6 = ((Double) attributes.get("boost")).floatValue(); // as calculated by the boost module, or 1.0 if no boost module is defined.
    float boost = f1 * f2 * f3 * f4 * f5 * f6;

    // System.out.println("BOOST url=["+url+"]  category="+f1+" ("+categoryBoost+":"+categoryBoostDamp+")  pagerank="+f2+" ("+pagerankBoost+":"+pagerankBoostDamp+")  log="+f3+" ("+logBoost+":"+logBoostDamp+")  freshness="+f4+" ("+freshnessBoost+":"+freshnessBoostDamp+") moduleBoost="+f5+"  Boost="+boost);

    if (boost < 1e-6f) {
        logger.warn("Boost too low! (" + boost + ")  category=" + f1 + " (" + categoryBoost + ":"
                + categoryBoostDamp + ")  pagerank=" + f2 + " (" + pagerankBoost + ":" + pagerankBoostDamp
                + ")  spamrank=" + f3 + " (" + spamrankBoost + ":" + spamrankBoostDamp + ")  log=" + f4 + " ("
                + logBoost + ":" + logBoostDamp + ")  freshness=" + f5 + " (" + freshnessBoost + ":"
                + freshnessBoostDamp + ") moduleBoost=" + f6);
        boost = 1e-6f;
    }

    if (null == title || "".equals(title)) {
        title = "Untitled";
    }

    root.addElement("boost").addText(String.valueOf(boost));
    root.addElement("documentId").addText(getDocumentId(page));

    Map<String, Double> boostMap = (Map<String, Double>) attributes.get("field_boost");

    // add the search fields
    addField(root, "url", url, true, true, true, boostMap);
    addField(root, "site", host, true, true, false, boostMap);
    addField(root, "tokenizedHost", tokenizedHost, false, true, true, boostMap);
    addField(root, "title", title, true, true, true, boostMap);
    addField(root, "text", text, true, true, true, boostMap);
    addField(root, "anchor", anchorText, false, true, true, boostMap);
    addField(root, "crawl", crawlName, false, true, true, boostMap);

    if (sendContent) {
        addBody(root, doc, content);
    }

    // for debugging only
    //addField(root, "boostinfo", "category="+f1+" ("+categoryBoost+":"+categoryBoostDamp+")  pagerank="+f2+" ("+pagerankBoost+":"+pagerankBoostDamp+")  log="+f3+" ("+logBoost+":"+logBoostDamp+")  freshness="+f4+" ("+freshnessBoost+":"+freshnessBoostDamp+") moduleBoost="+f5+"  Boost="+boost, true, false, false, null);

    addAdditionalFields(root, page, boostMap);

    // Adding metainfo from attributes
    Set<Entry<String, Object>> attributeSet = indexableAttributes.entrySet();
    for (Entry<String, Object> attribute : attributeSet) {
        addField(root, attribute.getKey(), attribute.getValue() == null ? "" : attribute.getValue().toString(),
                true, true, true, boostMap);
    }

    StringBuffer assignedCategories = new StringBuffer();
    if (null != categories) {
        // iterate through the classes the page belongs to add each category and its score
        for (Iterator<String> iter = categories.iterator(); iter.hasNext();) {
            assignedCategories.append(iter.next());
            assignedCategories.append(" ");

            // repeat the field times proportional to the score (this is a way to boost the document by category);
            //for (int rep = 0; rep < score*10; rep++) {
            //    addField(root, "categoryBoost", categ, false, true, false);
            //}
        }
        addField(root, "categories", assignedCategories.toString().trim(), true, true, true, boostMap);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Indexing dom: " + DomUtil.domToString(dom));
    }
    // Send the document to the indexer. If the queue is full, wait and retry.
    try {
        int i = pageMapper.mapPage(page);
        while (indexers[i].index(dom) == IndexerReturnCode.RETRY_QUEUE_FULL) {
            try {
                Thread.sleep(indexerBusyRetryTime * 1000);
            } catch (InterruptedException e) {
                logger.debug("Sleep interrupted: " + e, e);
            }
        }
        page.setEmitted(true);
    } catch (Exception e) {
        logger.error(e, e);
    }
}

From source file:com.flaptor.hounder.crawler.modules.IndexerModule.java

License:Apache License

public void applyCommand(Object command) {
    if ("optimize".equals(command.toString())) {
        logger.info("optimize requested.");
        try {/*from   w  w  w  . j a v a2  s  . c  o  m*/
            org.dom4j.Document dom = DocumentHelper.createDocument();
            dom.addElement("command").addAttribute("name", "optimize");
            for (int i = 0; i < indexers.length; i++) {
                indexers[i].index(dom);
            }
        } catch (Exception e) {
            logger.error(e, e);
        }
    } else if ("delete".equals(command.toString())) {
        FetchDocument doc = ((CommandWithDoc) command).getDoc();
        Page page = doc.getPage();
        deleteFromIndex(page);
    } else if ("startCycle".equals(command.toString())) {
        PageDB pagedb = ((CommandWithPageDB) command).getPageDB();
        scoreThreshold = new float[11];
        for (int i = 0; i < 11; i++) {
            scoreThreshold[i] = pagedb.getScoreThreshold(i * 10);
        }
        antiScoreThreshold = new float[11];
        for (int i = 0; i < 11; i++) {
            antiScoreThreshold[i] = pagedb.getAntiScoreThreshold(i * 10);
        }
    }
}