⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cfpipeadvertisement.java

📁 CoolFace是基于jxta的P2P系统
💻 JAVA
字号:
package com.cn.darkblue.entity;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Enumeration;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.cn.darkblue.listener.GroupBaseCommListener;

import net.jxta.document.Attributable;
import net.jxta.document.Document;
import net.jxta.document.Element;
import net.jxta.document.MimeMediaType;
import net.jxta.document.StructuredDocument;
import net.jxta.document.StructuredDocumentFactory;
import net.jxta.document.StructuredTextDocument;
import net.jxta.document.TextElement;
import net.jxta.id.ID;
import net.jxta.id.IDFactory;
import net.jxta.impl.id.UUID.PipeID;
import net.jxta.protocol.PipeAdvertisement;

public class CFPipeAdvertisement extends PipeAdvertisement{
	private static final Log log = LogFactory.getLog(CFPipeAdvertisement.class); 
	private final static String idTag = "id";
    private final static String nameTag = "name";
    private final static String typeTag = "Type";

	private final static String[] fields = {idTag, nameTag};
	TextElement doc = null;
	@Override
	public String[] getIndexFields() {
		return fields;
	}

	public CFPipeAdvertisement(InputStream stream) throws IOException {
        doc = (StructuredTextDocument)
                StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, stream);
        System.out.println("CF doc "+doc.toString());
        //initialize(doc);
    }
	
	protected void initialize(Element root) {
        if (!TextElement.class.isInstance(root)) {
            throw new IllegalArgumentException(getClass().getName() + " only supports TextElement");
        }
        TextElement doc = (TextElement) root;

        if (!doc.getName().equals(getAdvertisementType())) {
            throw new IllegalArgumentException(
                    "Could not construct : " + getClass().getName() + "from doc containing a " + doc.getName());
        }
        
        
    }
	
	@Override
    public Document getDocument(MimeMediaType asMimeType) {
        StructuredDocument adv = StructuredDocumentFactory.newStructuredDocument(asMimeType, getAdvertisementType());
        if (adv instanceof Attributable) {
            ((Attributable) adv).addAttribute("xmlns:jxta", "http://jxta.org");
        }
        
        Element e;

        e = adv.createElement(idTag, getID().toString());
        adv.appendChild(e);
        e = adv.createElement(nameTag, getName().trim());
        adv.appendChild(e);
        e = adv.createElement(typeTag, this.getType().trim());
        adv.appendChild(e);

        return adv;
    }

	public TextElement getDoc() {
		return doc;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -