| @@ -0,0 +1,387 @@ | ||
| /* | ||
| * SNMP4j.java | ||
| * Date: 4/1/2015 | ||
| * Time: 8:42 AM | ||
| * | ||
| * Copyright 2015 luoyuan. | ||
| * ALL RIGHTS RESERVED. | ||
| */ | ||
|
|
||
| package ly.snmp.core.snmputil; | ||
|
|
||
| import ly.snmp.core.model.OIDValueType; | ||
| import ly.snmp.core.model.Oid; | ||
| import ly.snmp.core.model.SNMPParameter; | ||
| import ly.snmp.core.model.SNMPVersion; | ||
| import ly.snmp.core.model.TableColumnOid; | ||
| import ly.snmp.core.model.TableOid; | ||
| import ly.snmp.core.snmputil.lysnmp.MessageDispatcherLy; | ||
| import org.snmp4j.CommunityTarget; | ||
| import org.snmp4j.MessageDispatcher; | ||
| import org.snmp4j.PDU; | ||
| import org.snmp4j.Snmp; | ||
| import org.snmp4j.Target; | ||
| import org.snmp4j.TransportMapping; | ||
| import org.snmp4j.UserTarget; | ||
| import org.snmp4j.event.ResponseEvent; | ||
| import org.snmp4j.mp.MPv1; | ||
| import org.snmp4j.mp.MPv2c; | ||
| import org.snmp4j.mp.MPv3; | ||
| import org.snmp4j.mp.SnmpConstants; | ||
| import org.snmp4j.security.AuthMD5; | ||
| import org.snmp4j.security.AuthSHA; | ||
| import org.snmp4j.security.Priv3DES; | ||
| import org.snmp4j.security.PrivAES128; | ||
| import org.snmp4j.security.PrivAES192; | ||
| import org.snmp4j.security.PrivAES256; | ||
| import org.snmp4j.security.PrivDES; | ||
| import org.snmp4j.security.SecurityLevel; | ||
| import org.snmp4j.security.SecurityModels; | ||
| import org.snmp4j.security.SecurityProtocols; | ||
| import org.snmp4j.security.USM; | ||
| import org.snmp4j.security.UsmUser; | ||
| import org.snmp4j.smi.Address; | ||
| import org.snmp4j.smi.OID; | ||
| import org.snmp4j.smi.OctetString; | ||
| import org.snmp4j.smi.SMIConstants; | ||
| import org.snmp4j.smi.TimeTicks; | ||
| import org.snmp4j.smi.UdpAddress; | ||
| import org.snmp4j.smi.Variable; | ||
| import org.snmp4j.smi.VariableBinding; | ||
| import org.snmp4j.transport.DefaultUdpTransportMapping; | ||
| import org.snmp4j.util.DefaultPDUFactory; | ||
| import org.snmp4j.util.PDUFactory; | ||
| import org.snmp4j.util.TableEvent; | ||
| import org.snmp4j.util.TableUtils; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.InetAddress; | ||
| import java.net.UnknownHostException; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Special use snmp4j to do the snmp collection. | ||
| */ | ||
| public class SNMP4JTCP implements SNMP { | ||
| private SNMPParameter parameter; | ||
| private Snmp snmp; | ||
| private Target target; | ||
| private PDUFactory pduFactory; | ||
| private TableUtils tableUtils; | ||
|
|
||
| public SNMP4JTCP(SNMPParameter parameter) throws IOException { | ||
| this.parameter = parameter; | ||
| TransportMapping transport = new DefaultUdpTransportMapping(); | ||
| SecurityProtocols.getInstance().addDefaultProtocols(); | ||
| MessageDispatcher disp = new MessageDispatcherLy(); | ||
| UsmUser user = null; | ||
| switch (parameter.getVersion()) { | ||
| case V1: | ||
| disp.addMessageProcessingModel(new MPv1()); | ||
| break; | ||
| case V2C: | ||
| disp.addMessageProcessingModel(new MPv2c()); | ||
| break; | ||
| case V3: | ||
| disp.addMessageProcessingModel(new MPv3()); | ||
| String auth = parameter.getAuthentication(); | ||
| String priv = parameter.getPrivacy(); | ||
| OID authPro = null, privPro = null; | ||
| if (auth != null) { | ||
| switch (parameter.getAuthProtocol()) { | ||
| case AuthMD5: | ||
| authPro = AuthMD5.ID; | ||
| break; | ||
| case AuthSHA: | ||
| authPro = AuthSHA.ID; | ||
| break; | ||
| default: | ||
| authPro = null; | ||
| } | ||
| } | ||
| if (priv != null) { | ||
| switch (parameter.getPrivacyProtocol()) { | ||
| case Priv3DES: | ||
| privPro = Priv3DES.ID; | ||
| break; | ||
| case PrivAES128: | ||
| privPro = PrivAES128.ID; | ||
| break; | ||
| case PriveAES192: | ||
| privPro = PrivAES192.ID; | ||
| break; | ||
| case PriveAES256: | ||
| privPro = PrivAES256.ID; | ||
| break; | ||
| case PrivDES: | ||
| privPro = PrivDES.ID; | ||
| break; | ||
| default: | ||
| privPro = null; | ||
| } | ||
| } | ||
| user = new UsmUser(new OctetString(parameter.getUserName()), authPro, auth != null ? new OctetString(auth) : null, privPro, priv != null ? new OctetString(priv) : null); | ||
| } | ||
| snmp = new Snmp(disp, transport); | ||
| OctetString localEngineID = new OctetString(MPv3.createLocalEngineID()); | ||
| USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0); | ||
| if (user != null) { | ||
| usm.addUser(user); | ||
| } | ||
| SecurityModels.getInstance().addSecurityModel(usm); | ||
| disp.addMessageProcessingModel(new MPv3(usm)); | ||
| transport.listen(); | ||
| this.target = createTarget(); | ||
| pduFactory = new DefaultPDUFactory(); | ||
| tableUtils = new TableUtils(snmp, pduFactory); | ||
| } | ||
|
|
||
| private Target createTarget() throws UnknownHostException { | ||
| Address targetAddress = new UdpAddress(InetAddress.getByName(parameter.getIp()), parameter.getPort()); | ||
| Target target = null; | ||
| switch (parameter.getVersion()) { | ||
| case V1: | ||
| case V2C: | ||
| CommunityTarget communityTarget = new CommunityTarget(); | ||
| communityTarget.setCommunity(new OctetString(parameter.getCommunity())); | ||
|
|
||
| if (parameter.getVersion() == SNMPVersion.V1) { | ||
| communityTarget.setVersion(SnmpConstants.version1); | ||
| } else { | ||
| communityTarget.setVersion(SnmpConstants.version2c); | ||
| } | ||
| target = communityTarget; | ||
| break; | ||
| case V3: | ||
| UserTarget userTarget = new UserTarget(); | ||
| userTarget.setVersion(SnmpConstants.version3); | ||
| userTarget.setSecurityName(new OctetString(parameter.getUserName())); | ||
| int secLev = 0; | ||
| if (parameter.getAuthentication() != null && parameter.getPrivacy() != null) { | ||
| secLev = SecurityLevel.AUTH_PRIV; | ||
| } else if (parameter.getAuthentication() == null && parameter.getPrivacy() == null) { | ||
| secLev = SecurityLevel.NOAUTH_NOPRIV; | ||
| } else if (parameter.getAuthentication() != null) { | ||
| secLev = SecurityLevel.AUTH_NOPRIV; | ||
| } | ||
| userTarget.setSecurityLevel(secLev); | ||
| target = userTarget; | ||
| break; | ||
| } | ||
| target.setAddress(targetAddress); | ||
| target.setRetries(parameter.getRetry()); | ||
| target.setTimeout(parameter.getTimeout()); | ||
| return target; | ||
| } | ||
|
|
||
| @Override | ||
| public Oid get(Oid oid) { | ||
| PDU pdu = pduFactory.createPDU(target); | ||
| OID oid4J = new OID(oid.getOids()); | ||
| pdu.add(new VariableBinding(oid4J)); | ||
| try { | ||
| ResponseEvent response = snmp.getNext(pdu, target); | ||
| for (VariableBinding vb : response.getResponse().toArray()) { | ||
| Variable variable = vb.getVariable(); | ||
| if (vb.getOid().startsWith(oid4J)) { | ||
| setValueAndType(oid, variable); | ||
| } else { | ||
| oid.setValueType(OIDValueType.ERROR); | ||
| } | ||
| } | ||
| } catch (IOException e) { | ||
| oid.setValueType(OIDValueType.ERROR); | ||
| oid.setException(e); | ||
| } | ||
| return oid; | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public Oid walk(Oid oid) { | ||
| throw new UnsupportedOperationException("UnSupport this operation in current version!"); | ||
| } | ||
|
|
||
| @Override | ||
| public Oid getNext(Oid oid) { | ||
| PDU pdu = pduFactory.createPDU(target); | ||
| OID oid4J = new OID(oid.getOids()); | ||
| pdu.add(new VariableBinding(oid4J)); | ||
| try { | ||
| ResponseEvent response = snmp.getNext(pdu, target); | ||
| for (VariableBinding vb : response.getResponse().toArray()) { | ||
| Variable variable = vb.getVariable(); | ||
| setValueAndType(oid, variable); | ||
| if (!vb.getOid().startsWith(oid4J)) { | ||
| oid.setOids(vb.getOid().getValue()); | ||
| oid.setNext(true); | ||
| } | ||
| } | ||
| } catch (IOException e) { | ||
| oid.setValueType(OIDValueType.ERROR); | ||
| oid.setException(e); | ||
| } | ||
| return oid; | ||
| } | ||
|
|
||
| @Override | ||
| public TableOid getTable(TableOid table) { | ||
| Map<String, TableColumnOid> columnMap = new HashMap<String, TableColumnOid>(table.getColumns().length); | ||
| OID[] columns = new OID[table.getColumns().length]; | ||
| for (int i = 0; i < columns.length; i++) { | ||
| columns[i] = new OID(table.getColumns()[i].getOids()); | ||
| columnMap.put(table.getColumns()[i].getOidString(), table.getColumns()[i]); | ||
| } | ||
| List<TableEvent> tableEvents = tableUtils.getTable(target, columns, null, null); | ||
| for (TableEvent tableEvent : tableEvents) { | ||
| if (tableEvent == null) { | ||
| continue; | ||
| } | ||
| OID index = tableEvent.getIndex(); | ||
| for (VariableBinding variableBinding : tableEvent.getColumns()) { | ||
| if (variableBinding == null) { | ||
| continue; | ||
| } | ||
| OID oid = variableBinding.getOid(); | ||
| oid.trim(index.size()); | ||
| TableColumnOid column = columnMap.get(oid.toDottedString()); | ||
| Variable variable = variableBinding.getVariable(); | ||
| if (variable != null && !variable.isException()) { | ||
| setTableColumnValueType(index, column, variable); | ||
| } else { | ||
| column.setValueType(OIDValueType.ERROR); | ||
| } | ||
| } | ||
| } | ||
| return table; | ||
| } | ||
|
|
||
| @Override | ||
| public Oid[] get(Oid... oids) { | ||
| PDU pdu = pduFactory.createPDU(target); | ||
| List<OID> oidList = new ArrayList<OID>(oids.length); | ||
| for (Oid oid : oids) { | ||
| if (oid instanceof TableOid) { | ||
| this.getTable((TableOid) oid); | ||
| } else { | ||
| OID oid4j = new OID(oid.getOids()); | ||
| pdu.add(new VariableBinding(oid4j)); | ||
| oidList.add(oid4j); | ||
| } | ||
| } | ||
| try { | ||
| ResponseEvent responseEvent = snmp.getNext(pdu, target); | ||
| PDU response = responseEvent.getResponse(); | ||
| for (int i = 0; i < response.size(); i++) { | ||
| VariableBinding variableBinding = response.get(i); | ||
| Variable variable = variableBinding.getVariable(); | ||
| if (variableBinding.getOid().startsWith(oidList.get(i))) { | ||
| setValueAndType(oids[i], variable); | ||
| } else { | ||
| oids[i].setValueType(OIDValueType.ERROR); | ||
| } | ||
| } | ||
|
|
||
| } catch (Exception e) { | ||
| for (Oid oid : oids) { | ||
| oid.setException(e); | ||
| oid.setValueType(OIDValueType.ERROR); | ||
| } | ||
| } | ||
| return oids; | ||
| } | ||
|
|
||
| @Override | ||
| public Oid[] getNext(Oid... oids) { | ||
| PDU pdu = pduFactory.createPDU(target); | ||
| List<OID> oidList = new ArrayList<OID>(oids.length); | ||
| for (Oid oid : oids) { | ||
| OID oid4j = new OID(oid.getOids()); | ||
| pdu.add(new VariableBinding(oid4j)); | ||
| oidList.add(oid4j); | ||
| } | ||
| try { | ||
| ResponseEvent responseEvent = snmp.getNext(pdu, target); | ||
| PDU response = responseEvent.getResponse(); | ||
| for (int i = 0; i < response.size(); i++) { | ||
| VariableBinding variableBinding = response.get(i); | ||
| Variable variable = variableBinding.getVariable(); | ||
| if (variableBinding.getOid().startsWith(oidList.get(i))) { | ||
| oids[i].setNext(true); | ||
| oids[i].setOids(variableBinding.getOid().getValue()); | ||
| } | ||
| setValueAndType(oids[i], variable); | ||
| } | ||
| } catch (IOException e) { | ||
| for (Oid oid : oids) { | ||
| oid.setException(e); | ||
| oid.setValueType(OIDValueType.ERROR); | ||
| } | ||
| } | ||
| return oids; | ||
| } | ||
|
|
||
| private void setValueAndType(Oid oid, Variable variable) { | ||
| switch (variable.getSyntax()) { | ||
| case SMIConstants.SYNTAX_COUNTER64: | ||
| oid.setValueType(OIDValueType.Counter64); | ||
| break; | ||
| case SMIConstants.SYNTAX_COUNTER32: | ||
| oid.setValueType(OIDValueType.Counter32); | ||
| break; | ||
| case SMIConstants.SYNTAX_GAUGE32: | ||
| oid.setValueType(OIDValueType.Gauge32); | ||
| break; | ||
| case SMIConstants.SYNTAX_INTEGER: | ||
| oid.setValueType(OIDValueType.INTEGER); | ||
| break; | ||
| case SMIConstants.SYNTAX_IPADDRESS: | ||
| oid.setValueType(OIDValueType.NetworkAddress); | ||
| break; | ||
| case SMIConstants.SYNTAX_TIMETICKS: | ||
| oid.setValueType(OIDValueType.TimeTicks); | ||
| break; | ||
| case SMIConstants.SYNTAX_OCTET_STRING: | ||
| oid.setValueType(OIDValueType.String); | ||
| oid.setOidValue(((OctetString) variable).toASCII(' ')); | ||
| return; | ||
| default: | ||
| oid.setValueType(OIDValueType.String); | ||
| } | ||
| oid.setOidValue(variable.toString()); | ||
| } | ||
|
|
||
| private void setTableColumnValueType(OID index, TableColumnOid oid, Variable variable) { | ||
| switch (variable.getSyntax()) { | ||
| case SMIConstants.SYNTAX_COUNTER64: | ||
| oid.setValueType(OIDValueType.Counter64); | ||
| break; | ||
| case SMIConstants.SYNTAX_COUNTER32: | ||
| oid.setValueType(OIDValueType.Counter32); | ||
| break; | ||
| case SMIConstants.SYNTAX_GAUGE32: | ||
| oid.setValueType(OIDValueType.Gauge32); | ||
| break; | ||
| case SMIConstants.SYNTAX_INTEGER: | ||
| oid.setValueType(OIDValueType.INTEGER); | ||
| break; | ||
| case SMIConstants.SYNTAX_IPADDRESS: | ||
| oid.setValueType(OIDValueType.NetworkAddress); | ||
| break; | ||
| case SMIConstants.SYNTAX_TIMETICKS: | ||
| oid.setValueType(OIDValueType.TimeTicks); | ||
| oid.setOidValue(index.toDottedString(), ((TimeTicks) variable).toMilliseconds() + ""); | ||
| return; | ||
| case SMIConstants.SYNTAX_OCTET_STRING: | ||
| oid.setValueType(OIDValueType.String); | ||
| oid.setOidValue(index.toDottedString(), ((OctetString) variable).toASCII(' ')); | ||
| return; | ||
| default: | ||
| oid.setValueType(OIDValueType.String); | ||
| } | ||
| oid.setOidValue(index.toString(), variable.toString()); | ||
| } | ||
| } |
| @@ -0,0 +1,105 @@ | ||
| package test; | ||
|
|
||
| import org.snmp4j.*; | ||
| import org.snmp4j.mp.MPv1; | ||
| import org.snmp4j.mp.MPv2c; | ||
| import org.snmp4j.mp.MPv3; | ||
| import org.snmp4j.security.SecurityModels; | ||
| import org.snmp4j.security.SecurityProtocols; | ||
| import org.snmp4j.security.USM; | ||
| import org.snmp4j.security.UsmUser; | ||
| import org.snmp4j.security.UsmUserEntry; | ||
| import org.snmp4j.smi.Address; | ||
| import org.snmp4j.smi.GenericAddress; | ||
| import org.snmp4j.smi.OctetString; | ||
| import org.snmp4j.smi.TcpAddress; | ||
| import org.snmp4j.smi.UdpAddress; | ||
| import org.snmp4j.smi.VariableBinding; | ||
| import org.snmp4j.transport.DefaultTcpTransportMapping; | ||
| import org.snmp4j.transport.DefaultUdpTransportMapping; | ||
| import org.snmp4j.util.MultiThreadedMessageDispatcher; | ||
| import org.snmp4j.util.ThreadPool; | ||
| import java.io.IOException; | ||
| import java.util.Vector; | ||
|
|
||
| /** | ||
| * 本类用于监听发送到本机的Trap信息 | ||
| * | ||
| * @author luoyuan | ||
| */ | ||
| public class LocalTrapReceiver implements CommandResponder { | ||
|
|
||
| private MultiThreadedMessageDispatcher dispatcher; | ||
| private Snmp snmp = null; | ||
|
|
||
| private LocalTrapReceiver() throws IOException { | ||
| dispatcher = new MultiThreadedMessageDispatcher(ThreadPool.create("snmp trap", 2), | ||
| new MessageDispatcherImpl()); | ||
| Address listenUdpAddress = GenericAddress.parse("udp:0.0.0.0/162"); // udp监听端口 | ||
| Address listenTCPAddress = GenericAddress.parse("tcp:0.0.0.0/162"); // tcp监听端口 | ||
| TransportMapping transport; | ||
| // 对TCP与UDP协议进行处理 | ||
| DefaultUdpTransportMapping udpTransport = new DefaultUdpTransportMapping( | ||
| (UdpAddress) listenUdpAddress); | ||
| DefaultTcpTransportMapping tcpTransport = new DefaultTcpTransportMapping( | ||
| (TcpAddress) listenTCPAddress); | ||
|
|
||
| snmp = new Snmp(dispatcher, udpTransport); | ||
| snmp.addTransportMapping(tcpTransport); | ||
|
|
||
| //配置engine | ||
| OctetString localEngineID = new OctetString(MPv3.createLocalEngineID()); | ||
| //配置USM 和user,需要和发送trap的配置一样才可以成功接收trap | ||
| USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0); | ||
| usm.updateUser(new UsmUserEntry(new OctetString("123"), new UsmUser(new OctetString("123"), | ||
| null, | ||
| null, | ||
| null, | ||
| null))); | ||
| // SecurityModels.getInstance().addSecurityModel(usm); | ||
| snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1()); | ||
| snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c()); | ||
| snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3(usm)); | ||
| snmp.listen(); | ||
| } | ||
|
|
||
|
|
||
| public void run() { | ||
| try { | ||
| snmp.addCommandResponder(this); | ||
| System.out.println("开始监听Trap信息!"); | ||
| } catch (Exception ex) { | ||
| ex.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * 当接收到trap时,会自动进入这个方法 | ||
| * | ||
| * @param respEvnt | ||
| */ | ||
| public void processPdu(CommandResponderEvent respEvnt) { | ||
| // 解析Response并且直接打印出来 | ||
| if (respEvnt != null && respEvnt.getPDU() != null) { | ||
| System.out.println("security name = " + new OctetString(respEvnt.getSecurityName())); | ||
| PDU pdu = respEvnt.getPDU(); | ||
| System.out.println("PDU type = " + respEvnt.getPDU().getClass().getSimpleName()); | ||
| System.out.println("PDU = " + respEvnt.getPDU().toString()); | ||
| if(pdu instanceof ScopedPDU){ | ||
| ScopedPDU scopedPDU = (ScopedPDU) pdu; | ||
| System.out.println("Engine Id = " + scopedPDU.getContextEngineID().getSyntaxString()); | ||
| } | ||
| Vector<? extends VariableBinding> recVBs = respEvnt.getPDU().getVariableBindings(); | ||
| for (int i = 0; i < recVBs.size(); i++) { | ||
| VariableBinding recVB = recVBs.elementAt(i); | ||
| System.out.println(recVB.getOid() + " : " + recVB.getVariable()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| LocalTrapReceiver localTrapReceiver = new LocalTrapReceiver(); | ||
| localTrapReceiver.run(); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,106 @@ | ||
| package test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.UnknownHostException; | ||
| import java.util.Vector; | ||
|
|
||
| import org.snmp4j.CommandResponder; | ||
| import org.snmp4j.CommandResponderEvent; | ||
| import org.snmp4j.MessageDispatcherImpl; | ||
| import org.snmp4j.Snmp; | ||
| import org.snmp4j.TransportMapping; | ||
| import org.snmp4j.mp.MPv1; | ||
| import org.snmp4j.mp.MPv2c; | ||
| import org.snmp4j.mp.MPv3; | ||
| import org.snmp4j.security.SecurityModels; | ||
| import org.snmp4j.security.SecurityProtocols; | ||
| import org.snmp4j.security.USM; | ||
| import org.snmp4j.smi.Address; | ||
| import org.snmp4j.smi.GenericAddress; | ||
| import org.snmp4j.smi.OctetString; | ||
| import org.snmp4j.smi.TcpAddress; | ||
| import org.snmp4j.smi.UdpAddress; | ||
| import org.snmp4j.smi.VariableBinding; | ||
| import org.snmp4j.transport.DefaultTcpTransportMapping; | ||
| import org.snmp4j.transport.DefaultUdpTransportMapping; | ||
| import org.snmp4j.util.MultiThreadedMessageDispatcher; | ||
| import org.snmp4j.util.ThreadPool; | ||
|
|
||
| /** | ||
| * 本类用于监听代理进程的Trap信息 | ||
| * | ||
| * @author zhanjia | ||
| * | ||
| */ | ||
| public class MultiThreadedTrapReceiver implements CommandResponder { | ||
|
|
||
| private MultiThreadedMessageDispatcher dispatcher; | ||
| private Snmp snmp = null; | ||
| private Address listenAddress; | ||
| private ThreadPool threadPool; | ||
|
|
||
| public MultiThreadedTrapReceiver() { | ||
| // BasicConfigurator.configure(); | ||
| } | ||
|
|
||
| private void init() throws UnknownHostException, IOException { | ||
| threadPool = ThreadPool.create("Trap", 2); | ||
| dispatcher = new MultiThreadedMessageDispatcher(threadPool, | ||
| new MessageDispatcherImpl()); | ||
| listenAddress = GenericAddress.parse(System.getProperty( | ||
| "snmp4j.listenAddress", "udp:0.0.0.0/162")); // 本地IP与监听端口 | ||
| TransportMapping transport; | ||
| // 对TCP与UDP协议进行处理 | ||
| if (listenAddress instanceof UdpAddress) { | ||
| transport = new DefaultUdpTransportMapping( | ||
| (UdpAddress) listenAddress); | ||
| } else { | ||
| transport = new DefaultTcpTransportMapping( | ||
| (TcpAddress) listenAddress); | ||
| } | ||
| snmp = new Snmp(dispatcher, transport); | ||
| snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1()); | ||
| snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c()); | ||
| snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3()); | ||
| USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3 | ||
| .createLocalEngineID()), 0); | ||
| SecurityModels.getInstance().addSecurityModel(usm); | ||
| snmp.listen(); | ||
| } | ||
|
|
||
|
|
||
| public void run() { | ||
| try { | ||
| init(); | ||
| snmp.addCommandResponder(this); | ||
| System.out.println("开始监听Trap信息!"); | ||
| } catch (Exception ex) { | ||
| ex.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * 实现CommandResponder的processPdu方法, 用于处理传入的请求、PDU等信息 | ||
| * 当接收到trap时,会自动进入这个方法 | ||
| * | ||
| * @param respEvnt | ||
| */ | ||
| public void processPdu(CommandResponderEvent respEvnt) { | ||
| // 解析Response | ||
| if (respEvnt != null && respEvnt.getPDU() != null) { | ||
| System.out.println("type = " + respEvnt.getPDU().getType()); | ||
| System.out.println("security name = " + new OctetString(respEvnt.getSecurityName())); | ||
| Vector<? extends VariableBinding> recVBs = respEvnt.getPDU().getVariableBindings(); | ||
| for (int i = 0; i < recVBs.size(); i++) { | ||
| VariableBinding recVB = recVBs.elementAt(i); | ||
| System.out.println(recVB.getOid() + " : " + recVB.getVariable()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| MultiThreadedTrapReceiver multithreadedtrapreceiver = new MultiThreadedTrapReceiver(); | ||
| multithreadedtrapreceiver.run(); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,113 @@ | ||
| package test; | ||
|
|
||
| import org.snmp4j.*; | ||
| import org.snmp4j.mp.MPv1; | ||
| import org.snmp4j.mp.MPv3; | ||
| import org.snmp4j.mp.SnmpConstants; | ||
| import org.snmp4j.security.*; | ||
| import org.snmp4j.smi.Address; | ||
| import org.snmp4j.smi.GenericAddress; | ||
| import org.snmp4j.smi.OID; | ||
| import org.snmp4j.smi.OctetString; | ||
| import org.snmp4j.smi.VariableBinding; | ||
| import org.snmp4j.transport.DefaultUdpTransportMapping; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * 本类用于发送v3 Trap信息 | ||
| * | ||
| * @author luoyuan | ||
| */ | ||
| public class SnmpSendV3Trap { | ||
|
|
||
| private Snmp snmp = null; | ||
|
|
||
| private Address targetAddress = null; | ||
|
|
||
| public SnmpSendV3Trap(String target, int port) throws IOException { | ||
| //配置EngineID | ||
| OctetString localEngineID = new OctetString(MPv3.createLocalEngineID()); | ||
| // 设置目的地的IP和端口 | ||
| targetAddress = GenericAddress.parse(String.format("udp:%s/%s", target, port)); | ||
| TransportMapping transport = new DefaultUdpTransportMapping(); | ||
| //配置USM,传入 engine id | ||
| USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0); | ||
| //添加Usm user, 这里的配置的user, 目标接收端也正确认证才可以接受到这个trap | ||
| //这里创建User的是全部使用null是表示使用NOAUTH_NOPRIV的模式发送trap | ||
| //具体的Auth模式可以参考收集snmp数据,是一样配置的。 | ||
| usm.updateUser(new UsmUserEntry(new OctetString("123"), new UsmUser(new OctetString("123"), | ||
| AuthMD5.ID, | ||
| new OctetString("12345678"), | ||
| Priv3DES.ID, | ||
| new OctetString("12345678")))); | ||
| //添加USM到Security Models中 | ||
| SecurityModels.getInstance().addSecurityModel(usm); | ||
| //构建SNMP对象, 并且添加v3模式到其中 | ||
| snmp = new Snmp(transport); | ||
| snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3(usm)); | ||
| transport.listen(); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * 向管理进程发送Trap报文 | ||
| * | ||
| * @throws IOException | ||
| */ | ||
| public void sendV3PDU() throws IOException { | ||
|
|
||
| // 设置 target, v3trap 一定要使用UserTarget | ||
| UserTarget target = new UserTarget(); | ||
| target.setAddress(targetAddress); | ||
| target.setVersion(SnmpConstants.version3); | ||
| //设置用户认证信息 | ||
| target.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV); | ||
| target.setSecurityName(new OctetString("123")); | ||
| target.setAuthoritativeEngineID(MPv3.createLocalEngineID()); | ||
|
|
||
| // 创建 PDU, 注意这里要使用ScopedPDU | ||
| ScopedPDU pdu = new ScopedPDU(); | ||
| pdu.add(new VariableBinding(new OID(".1.3.6.1.2.4407.11.1.1.1.1"), | ||
| new OctetString("SnmpTrap"))); | ||
| pdu.add(new VariableBinding(new OID(".1.3.6.1.2.4407.11.1.1.1.2"), | ||
| new OctetString("v3"))); | ||
| pdu.setType(PDU.TRAP); | ||
|
|
||
| // 发送trap | ||
| snmp.send(pdu, target); | ||
| } | ||
|
|
||
| /** | ||
| * 向管理进程发送Trap报文 | ||
| * | ||
| * @throws IOException | ||
| */ | ||
| public void sendV1PDU() throws IOException { | ||
|
|
||
| CommunityTarget target = new CommunityTarget(targetAddress, new OctetString("luo")); | ||
| target.setAddress(targetAddress); | ||
| target.setVersion(SnmpConstants.version1); | ||
|
|
||
| PDU pdu = new PDU(); | ||
| pdu.add(new VariableBinding(new OID(".1.3.6.1.2.4407.11.1.1.1.1"), | ||
| new OctetString("SnmpTrap"))); | ||
| pdu.add(new VariableBinding(new OID(".1.3.6.1.2.4407.11.1.1.1.2"), | ||
| new OctetString("v1"))); | ||
| pdu.setType(PDU.V1TRAP); | ||
|
|
||
| // 发送trap | ||
| snmp.send(pdu, target); | ||
| } | ||
|
|
||
|
|
||
| public static void main(String[] args) { | ||
| try { | ||
| SnmpSendV3Trap trapSender = new SnmpSendV3Trap("10.154.10.11", 162); | ||
| trapSender.sendV3PDU(); | ||
| // trapSender.sendV1PDU(); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,91 @@ | ||
| package test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Vector; | ||
|
|
||
| import org.snmp4j.CommunityTarget; | ||
| import org.snmp4j.PDU; | ||
| import org.snmp4j.Snmp; | ||
| import org.snmp4j.TransportMapping; | ||
| import org.snmp4j.event.ResponseEvent; | ||
| import org.snmp4j.mp.SnmpConstants; | ||
| import org.snmp4j.smi.Address; | ||
| import org.snmp4j.smi.GenericAddress; | ||
| import org.snmp4j.smi.OID; | ||
| import org.snmp4j.smi.OctetString; | ||
| import org.snmp4j.smi.VariableBinding; | ||
| import org.snmp4j.transport.DefaultUdpTransportMapping; | ||
|
|
||
| /** | ||
| * 本类用于向管理进程发送Trap信息 | ||
| * | ||
| * @author zhanjia | ||
| * | ||
| */ | ||
| public class SnmpUtilSendTrap { | ||
|
|
||
| private Snmp snmp = null; | ||
|
|
||
| private Address targetAddress = null; | ||
|
|
||
| public void initComm() throws IOException { | ||
|
|
||
| // 设置管理进程的IP和端口 | ||
| targetAddress = GenericAddress.parse("udp:10.154.10.11/162"); | ||
| TransportMapping transport = new DefaultUdpTransportMapping(); | ||
| snmp = new Snmp(transport); | ||
| transport.listen(); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * 向管理进程发送Trap报文 | ||
| * | ||
| * @throws IOException | ||
| */ | ||
| public void sendPDU() throws IOException { | ||
|
|
||
| // 设置 target | ||
| CommunityTarget target = new CommunityTarget(); | ||
| target.setAddress(targetAddress); | ||
| // target.setCommunity(new OctetString("111")); | ||
| // 通信不成功时的重试次数 | ||
| target.setRetries(2); | ||
| // 超时时间 | ||
| target.setTimeout(1500); | ||
| // snmp版本 | ||
| target.setVersion(SnmpConstants.version2c); | ||
|
|
||
| // 创建 PDU | ||
| PDU pdu = new PDU(); | ||
| pdu.add(new VariableBinding(new OID(".1.3.6.1.2.3377.10.1.1.1.1"), | ||
| new OctetString("SnmpTrap"))); | ||
| pdu.add(new VariableBinding(new OID(".1.3.6.1.2.3377.10.1.1.1.2"), | ||
| new OctetString("JavaEE"))); | ||
| pdu.setType(PDU.TRAP); | ||
|
|
||
| // 向Agent发送PDU,并接收Response | ||
| ResponseEvent respEvnt = snmp.send(pdu, target); | ||
|
|
||
| // 解析Response | ||
| if (respEvnt != null && respEvnt.getResponse() != null) { | ||
| Vector<? extends VariableBinding> recVBs = respEvnt.getResponse() | ||
| .getVariableBindings(); | ||
| for (int i = 0; i < recVBs.size(); i++) { | ||
| VariableBinding recVB = recVBs.elementAt(i); | ||
| System.out.println(recVB.getOid() + " : " + recVB.getVariable()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| try { | ||
| SnmpUtilSendTrap util = new SnmpUtilSendTrap(); | ||
| util.initComm(); | ||
| util.sendPDU(); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,12 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <classpath> | ||
| <classpathentry kind="src" path="src/main/java"/> | ||
| <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
| <classpathentry exported="true" kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> | ||
| <classpathentry kind="lib" path="L:/SNMP/SNMPCore/build/libs/SNMPCore-1.0.0.jar"/> | ||
| <classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/servlet-api-2.4.jar"/> | ||
| <classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/snmp4j-2.3.3.jar"/> | ||
| <classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/SNMPCore-1.0.0.jar"/> | ||
| <classpathentry combineaccessrules="false" kind="src" path="/SNMPCore"/> | ||
| <classpathentry kind="output" path="bin"/> | ||
| </classpath> |
| @@ -0,0 +1,27 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <projectDescription> | ||
| <name>SNMPUI</name> | ||
| <comment/> | ||
| <projects/> | ||
| <natures> | ||
| <nature>org.eclipse.jdt.core.javanature</nature> | ||
| <nature>org.eclipse.wst.common.project.facet.core.nature</nature> | ||
| <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> | ||
| <nature>org.eclipse.jem.workbench.JavaEMFNature</nature> | ||
| </natures> | ||
| <buildSpec> | ||
| <buildCommand> | ||
| <name>org.eclipse.jdt.core.javabuilder</name> | ||
| <arguments/> | ||
| </buildCommand> | ||
| <buildCommand> | ||
| <name>org.eclipse.wst.common.project.facet.core.builder</name> | ||
| <arguments/> | ||
| </buildCommand> | ||
| <buildCommand> | ||
| <name>org.eclipse.wst.validation.validationbuilder</name> | ||
| <arguments/> | ||
| </buildCommand> | ||
| </buildSpec> | ||
| <linkedResources/> | ||
| </projectDescription> |
| @@ -0,0 +1,29 @@ | ||
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> | ||
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
| <html> | ||
| <head> | ||
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | ||
| <title>Lexical Analysis and Edit Distance</title> | ||
| <style> | ||
| fieldset | ||
| { | ||
| display: block; | ||
| border: bold; | ||
| width: 30%; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h1></h1> | ||
| <form name="myform" action="LexerDistanceServlet" method="post"> | ||
| <fieldset> | ||
| <legend></legend> | ||
| Input 1: <br><textarea rows="5" cols="30" name="s2a"></textarea> | ||
| <br> | ||
| Input 2: <br><textarea rows="5" cols="30" name="s2b"></textarea> | ||
| <br><br> | ||
| <input type="submit" value="Submit!"> | ||
| </fieldset> | ||
| </form> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,3 @@ | ||
| Manifest-Version: 1.0 | ||
| Class-Path: | ||
|
|
| @@ -0,0 +1,282 @@ | ||
| import java.io.IOException; | ||
| import java.io.PrintWriter; | ||
| import java.util.ArrayList; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import javax.servlet.ServletException; | ||
| import javax.servlet.annotation.WebServlet; | ||
| import javax.servlet.http.HttpServlet; | ||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
|
|
||
| @WebServlet("/LexerDistanceServlet") | ||
| public class LexerDistanceServlet extends HttpServlet { | ||
| private static final long serialVersionUID = 1L; | ||
| //declare variables | ||
| public static String s2a; | ||
| public static String s2b; | ||
| //Start of Lexer (part1) codes// | ||
| public static enum TokenType | ||
| { | ||
| NUMBER("-?[0-9]+"), | ||
| BINARYOP("[*|/|+|-|=]"), | ||
| KEYWORD("[abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|extends|false|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|native|new|null|package|private|protected|public|return|short|static|strictfp|super|switch|synchronized|'String'|this|throw|throws|true|transient|try|void|volatile|while]+"), | ||
| STRINGLITERAL("\"([^\\\"]|\\.)*\""), | ||
| IDENTIFIER("[a-zA-Z][a-zA-Z0-9]*"), | ||
| WHITESPACE("[ \t\f\r\n]+"), | ||
| OPERATOR("[~|`|!|@|#|$|%|^|&|(|)|_|{|[|}|]|||\"|:|;|'|<|>|?|,|.|<%|%>|<?|?>]"); | ||
|
|
||
| public final String pattern; | ||
| private TokenType(String pattern) | ||
| { | ||
| this.pattern = pattern; | ||
| } | ||
| } | ||
| //token class | ||
| public static class Token | ||
| { | ||
| public TokenType type; | ||
| public String input; | ||
|
|
||
| public Token(TokenType type, String input) | ||
| { | ||
| this.type = type; | ||
| this.input = input; | ||
| } | ||
|
|
||
| @Override | ||
| //output format: tokentype input | ||
| public String toString() | ||
| { | ||
| return String.format("(%s %s)", type.name(), input); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| //store all input in an arraylist | ||
| public static ArrayList<Token> lex(String input) { | ||
| // The tokens to return | ||
| ArrayList<Token> tokens = new ArrayList<Token>(); | ||
| // Lexer logic begins here | ||
| StringBuffer tokenPatternsBuffer = new StringBuffer(); | ||
| for (TokenType tokenType : TokenType.values()) | ||
| tokenPatternsBuffer.append(String.format("|(?<%s>%s)", tokenType.name(), tokenType.pattern)); | ||
| Pattern tokenPatterns = Pattern.compile(new String(tokenPatternsBuffer.substring(1))); | ||
| // Begin matching tokens | ||
| Matcher matcher = tokenPatterns.matcher(input); | ||
| while (matcher.find()) { | ||
| if (matcher.group(TokenType.NUMBER.name()) != null) | ||
| { | ||
| tokens.add(new Token(TokenType.NUMBER, matcher.group(TokenType.NUMBER.name()))); | ||
| continue; | ||
| } | ||
| else if (matcher.group(TokenType.BINARYOP.name()) != null) | ||
| { | ||
| tokens.add(new Token(TokenType.BINARYOP, matcher.group(TokenType.BINARYOP.name()))); | ||
| continue; | ||
| } | ||
| else if (matcher.group(TokenType.IDENTIFIER.name()) != null) | ||
| { | ||
| tokens.add(new Token(TokenType.IDENTIFIER, matcher.group(TokenType.IDENTIFIER.name()))); | ||
| continue; | ||
| } | ||
| else if (matcher.group(TokenType.STRINGLITERAL.name()) != null) | ||
| { | ||
| tokens.add(new Token(TokenType.STRINGLITERAL, matcher.group(TokenType.STRINGLITERAL.name()))); | ||
| continue; | ||
| } | ||
| else if (matcher.group(TokenType.KEYWORD.name()) != null) | ||
| { | ||
| tokens.add(new Token(TokenType.KEYWORD, matcher.group(TokenType.KEYWORD.name()))); | ||
| continue; | ||
| } | ||
| else if (matcher.group(TokenType.OPERATOR.name()) != null) | ||
| { | ||
| tokens.add(new Token(TokenType.OPERATOR, matcher.group(TokenType.OPERATOR.name()))); | ||
| continue; | ||
| } | ||
| else if (matcher.group(TokenType.WHITESPACE.name()) != null) | ||
| continue; | ||
| } | ||
| return tokens; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /* This method calculates the levenshtein distance given 2 arrays of code tokens | ||
| ** subTokens: the code submitted by students tokenized into an array of code tokens. | ||
| ** intendedTokens: the 'correct' code to be matched, tokenized into an array of code tokens. | ||
| ** returns the levenshtein distance | ||
| ** ----------------------------------------------------*/ | ||
| public int LevenshteinDistance (ArrayList<Token> input1, ArrayList<Token> input2) { | ||
| //convert arraylist into array | ||
| Token subTokens[] = input1.toArray(new Token[input1.size()]); | ||
| Token intendedTokens[] = input2.toArray(new Token[input2.size()]); | ||
|
|
||
| //System.out.println("sub tokens = " + subTokens.length); | ||
| //System.out.println("intended tokens = " + intendedTokens.length); | ||
|
|
||
| int len0 = subTokens.length+1; | ||
| int len1 = intendedTokens.length+1; | ||
|
|
||
|
|
||
| // the array of distances | ||
| int[] cost = new int[len0]; | ||
| int[] newcost = new int[len0]; | ||
| int[][] op = new int[len0][len1]; //to store the operation to be performed ie insert, delete or replace | ||
| int[] minCostIdx = new int[len1]; | ||
| // initial cost of skipping prefix in String s0 | ||
| for (int i = 0; i < len0; i++) cost[i] = i; | ||
|
|
||
| // dynamically computing the array of distances | ||
|
|
||
| // transformation cost for each letter in s1 | ||
|
|
||
| for (int j = 1; j < len1; j++) { | ||
| // initial cost of skipping prefix in String s1 | ||
| newcost[0] = j; | ||
| //int i = j; | ||
|
|
||
| // transformation cost for each letter in s0 | ||
| for(int i = 1; i < len0; i++) { | ||
| // matching current letters in both strings | ||
| System.out.println(" "); | ||
| //System.out.println(" "); | ||
| //System.out.println("SubToken " + subTokens[i-1]); | ||
| //System.out.println("IntendedTokens " + intendedTokens[j-1]); | ||
|
|
||
|
|
||
| int match = (subTokens[i-1].toString().equals(intendedTokens[j-1].toString())) ? 0 : 1; | ||
| //System.out.println("Match " + match); | ||
| // computing cost for each transformation | ||
| int cost_replace = cost[i - 1] + match; | ||
| int cost_insert = cost[i] + 1; | ||
| int cost_delete = newcost[i - 1] + 1; | ||
|
|
||
| // keep minimum cost | ||
| newcost[i] = Math.min(Math.min(cost_insert, cost_delete), cost_replace); | ||
| //System.out.format("row %d col %d cost:%d\n",i,j,newcost[i]); | ||
| if (match==0){ | ||
| op[i][j]=0; | ||
| if (j==i){ | ||
| System.out.println("SubToken " + subTokens[i-1]); | ||
| System.out.println("IntendedTokens " + intendedTokens[j-1]); | ||
| System.out.println("match " + subTokens[i-1] + " " + intendedTokens[j-1] ); | ||
| } | ||
| } | ||
| else { | ||
|
|
||
| if (newcost[i]==cost_insert) | ||
| { | ||
| op[i][j]=1; | ||
| //if (j==i || j==i-1) | ||
| //if (subTokens.length > intendedTokens.length) | ||
| if (j - 1 == subTokens.length) | ||
| { | ||
| System.out.println("SubToken " + subTokens[i-1]); | ||
| System.out.println("IntendedTokens " + intendedTokens[j-1]); | ||
| System.out.println("insert " + intendedTokens[j-1]); | ||
| break; | ||
| } | ||
| } | ||
| else if (newcost[i]==cost_delete) | ||
| { | ||
| op[i][j]=2; | ||
| //if (j==i || j==i+1) | ||
| //if (subTokens.length > intendedTokens.length) | ||
| if (i - 1 == intendedTokens.length) | ||
| { | ||
| System.out.println("SubToken " + subTokens[i-1]); | ||
| System.out.println("IntendedTokens " + intendedTokens[j-1]); | ||
| System.out.println("delete " + subTokens[i-1]); | ||
| break; | ||
| } | ||
| } | ||
| else if (newcost[i]==cost_replace) | ||
| { | ||
| op[i][j]=3; | ||
| if (j==i) | ||
| { | ||
| System.out.println("SubToken " + subTokens[i-1]); | ||
| System.out.println("IntendedTokens " + intendedTokens[j-1]); | ||
| System.out.println("replace " + subTokens[i-1] + " to " + intendedTokens[j-1]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| minCostIdx[j] = findMinimumCostIdx(newcost); | ||
|
|
||
| // swap cost/newcost arrays | ||
| int[] swap = cost; cost = newcost; newcost = swap; | ||
| } | ||
|
|
||
| // the distance is the cost for transforming all letters in both strings | ||
| return cost[len0 - 1]; | ||
| } | ||
|
|
||
| private int findMinimumCostIdx(int[] newcost) { | ||
| int minCost = newcost[1]; | ||
| int minCostIdx=1; | ||
| for (int ii=1; ii<newcost.length;ii++) { | ||
| if (newcost[ii]<=minCost) { | ||
| minCost=newcost[ii]; | ||
| minCostIdx = ii; | ||
| } | ||
| } | ||
| return minCostIdx; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| @Override | ||
| protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException | ||
| { | ||
| //get input from fields in FinalForm.jsp | ||
| s2a = request.getParameter("s2a"); | ||
| s2b = request.getParameter("s2b"); | ||
|
|
||
| //Start of Lexer (part2) codes// | ||
| //Create tokens, count no. of tokens and print them | ||
| //print token at console | ||
| ArrayList<Token> tokens1 = lex(s2a); | ||
| for (Token token1 : tokens1) | ||
| System.out.println(token1); | ||
| System.out.println("There are " + tokens1.size() + " tokens"); | ||
|
|
||
| ArrayList<Token> tokens2 = lex(s2b); | ||
| for (Token token2 : tokens2) | ||
| System.out.println(token2); | ||
| System.out.println("There are " + tokens2.size() + " tokens"); | ||
|
|
||
| //print in the webpage | ||
| for (Token token1 : tokens1) | ||
| { | ||
| PrintWriter writer = response.getWriter(); | ||
| String htmlRespone = "<html>"; | ||
| htmlRespone += "Token1: " + (token1) + "<br>"; | ||
| htmlRespone += "</html>"; | ||
| writer.println(htmlRespone); | ||
| } | ||
| for (Token token2 : tokens2) | ||
| { | ||
| PrintWriter writer = response.getWriter(); | ||
| String htmlRespone = "<html>"; | ||
| htmlRespone += "Token2: " + (token2) + "<br>"; | ||
| htmlRespone += "</html>"; | ||
| writer.println(htmlRespone); | ||
| } | ||
| //End of Lexer (part2) codes | ||
| //Start Levenshtein (part 2) codes here | ||
| //System.out.println("distance = " + LevenshteinDistance(tokens1, tokens2)); | ||
|
|
||
| //appears in the webpage | ||
| PrintWriter writer = response.getWriter(); | ||
| String htmlRespone = "<html>"; | ||
| htmlRespone += "<hr><br>"; | ||
| htmlRespone += "Levenshtein Distance = " + LevenshteinDistance(tokens1, tokens2); | ||
| htmlRespone += "</html>"; | ||
| writer.println(htmlRespone); | ||
| //End Levenshtein (part 2) codes here// | ||
| } | ||
| } |
| @@ -0,0 +1,5 @@ | ||
| Manifest-Version: 1.0 | ||
| Title: SNMPFrameworkUI | ||
| Version: 1.0 | ||
| Author: LuoYuan | ||
|
|
| @@ -0,0 +1,18 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>AJAX Content</title> | ||
| </head> | ||
| <body> | ||
| <p style="font-size:14px">Here is the content loaded via AJAX.</p> | ||
| <ul> | ||
| <li>easyui is a collection of user-interface plugin based on jQuery.</li> | ||
| <li>easyui provides essential functionality for building modern, interactive, javascript applications.</li> | ||
| <li>using easyui you don't need to write many javascript code, you usually defines user-interface by writing some HTML markup.</li> | ||
| <li>complete framework for HTML5 web page.</li> | ||
| <li>easyui save your time and scales while developing your products.</li> | ||
| <li>easyui is very easy but powerful.</li> | ||
| </ul> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,51 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Accordion Actions - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Accordion Actions</h2> | ||
| <p>Click the buttons below to add or remove accordion items.</p> | ||
| <div style="margin:20px 0 10px 0;"> | ||
| <a href="javascript:void(0)" class="easyui-linkbutton" onclick="selectPanel()">Select</a> | ||
| <a href="javascript:void(0)" class="easyui-linkbutton" onclick="addPanel()">Add</a> | ||
| <a href="javascript:void(0)" class="easyui-linkbutton" onclick="removePanel()">Remove</a> | ||
| </div> | ||
| <div id="aa" class="easyui-accordion" style="width:500px;height:300px;"> | ||
| <div title="About" data-options="iconCls:'icon-ok'" style="overflow:auto;padding:10px;"> | ||
| <h3 style="color:#0099FF;">Accordion for jQuery</h3> | ||
| <p>Accordion is a part of easyui framework for jQuery. It lets you define your accordion component on web page more easily.</p> | ||
| </div> | ||
| </div> | ||
| <script type="text/javascript"> | ||
| function selectPanel(){ | ||
| $.messager.prompt('Prompt','Please enter the panel title:',function(s){ | ||
| if (s){ | ||
| $('#aa').accordion('select',s); | ||
| } | ||
| }); | ||
| } | ||
| var idx = 1; | ||
| function addPanel(){ | ||
| $('#aa').accordion('add',{ | ||
| title:'Title'+idx, | ||
| content:'<div style="padding:10px">Content'+idx+'</div>' | ||
| }); | ||
| idx++; | ||
| } | ||
| function removePanel(){ | ||
| var pp = $('#aa').accordion('getSelected'); | ||
| if (pp){ | ||
| var index = $('#aa').accordion('getPanelIndex',pp); | ||
| $('#aa').accordion('remove',index); | ||
| } | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,28 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Loading Accordion Content with AJAX - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Loading Accordion Content with AJAX</h2> | ||
| <p>Click AJAX panel header to load content via AJAX.</p> | ||
| <div style="margin:20px 0 10px 0;"></div> | ||
| <div class="easyui-accordion" style="width:500px;height:300px;"> | ||
| <div title="About" data-options="iconCls:'icon-ok'" style="overflow:auto;padding:10px;"> | ||
| <h3 style="color:#0099FF;">Accordion for jQuery</h3> | ||
| <p>Accordion is a part of easyui framework for jQuery. It lets you define your accordion component on web page more easily.</p> | ||
| </div> | ||
| <div title="Help" data-options="iconCls:'icon-help'" style="padding:10px;"> | ||
| <p>The accordion allows you to provide multiple panels and display one or more at a time. Each panel has built-in support for expanding and collapsing. Clicking on a panel header to expand or collapse that panel body. The panel content can be loaded via ajax by specifying a 'href' property. Users can define a panel to be selected. If it is not specified, then the first panel is taken by default.</p> | ||
| </div> | ||
| <div title="Ajax" data-options="href:'_content.html'" style="padding:10px"> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,52 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Basic Accordion - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Basic Accordion</h2> | ||
| <p>Click on panel header to show its content.</p> | ||
| <div style="margin:20px 0 10px 0;"></div> | ||
| <div class="easyui-accordion" style="width:500px;height:300px;"> | ||
| <div title="About" data-options="iconCls:'icon-ok'" style="overflow:auto;padding:10px;"> | ||
| <h3 style="color:#0099FF;">Accordion for jQuery</h3> | ||
| <p>Accordion is a part of easyui framework for jQuery. It lets you define your accordion component on web page more easily.</p> | ||
| </div> | ||
| <div title="Help" data-options="iconCls:'icon-help'" style="padding:10px;"> | ||
| <p>The accordion allows you to provide multiple panels and display one or more at a time. Each panel has built-in support for expanding and collapsing. Clicking on a panel header to expand or collapse that panel body. The panel content can be loaded via ajax by specifying a 'href' property. Users can define a panel to be selected. If it is not specified, then the first panel is taken by default.</p> | ||
| </div> | ||
| <div title="TreeMenu" data-options="iconCls:'icon-search'" style="padding:10px;"> | ||
| <ul class="easyui-tree"> | ||
| <li> | ||
| <span>Foods</span> | ||
| <ul> | ||
| <li> | ||
| <span>Fruits</span> | ||
| <ul> | ||
| <li>apple</li> | ||
| <li>orange</li> | ||
| </ul> | ||
| </li> | ||
| <li> | ||
| <span>Vegetables</span> | ||
| <ul> | ||
| <li>tomato</li> | ||
| <li>carrot</li> | ||
| <li>cabbage</li> | ||
| <li>potato</li> | ||
| <li>lettuce</li> | ||
| </ul> | ||
| </li> | ||
| </ul> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,12 @@ | ||
| {"total":28,"rows":[ | ||
| {"productid":"FI-SW-01","productname":"Koi","unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"}, | ||
| {"productid":"K9-DL-01","productname":"Dalmation","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"}, | ||
| {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":38.50,"attr1":"Venomless","itemid":"EST-11"}, | ||
| {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"}, | ||
| {"productid":"RP-LI-02","productname":"Iguana","unitcost":12.00,"status":"P","listprice":35.50,"attr1":"Green Adult","itemid":"EST-13"}, | ||
| {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":158.50,"attr1":"Tailless","itemid":"EST-14"}, | ||
| {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":83.50,"attr1":"With tail","itemid":"EST-15"}, | ||
| {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":23.50,"attr1":"Adult Female","itemid":"EST-16"}, | ||
| {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":89.50,"attr1":"Adult Male","itemid":"EST-17"}, | ||
| {"productid":"AV-CB-01","productname":"Amazon Parrot","unitcost":92.00,"status":"P","listprice":63.50,"attr1":"Adult Male","itemid":"EST-18"} | ||
| ]} |
| @@ -0,0 +1,33 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Keep Expandable Panel in Accordion - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Keep Expandable Panel in Accordion</h2> | ||
| <p>Keep a expandable panel and prevent it from collapsing.</p> | ||
| <div style="margin:20px 0 10px 0;"></div> | ||
| <div class="easyui-accordion" style="width:500px;height:300px;"> | ||
| <div title="Top Panel" data-options="iconCls:'icon-search',collapsed:false,collapsible:false" style="padding:10px;"> | ||
| <input class="easyui-searchbox" prompt="Enter something here" style="width:300px;height:25px;"> | ||
| </div> | ||
| <div title="About" data-options="selected:true" style="padding:10px;"> | ||
| <h3 style="color:#0099FF;">Accordion for jQuery</h3> | ||
| <p>Accordion is a part of easyui framework for jQuery. It lets you define your accordion component on web page more easily.</p> | ||
| </div> | ||
| <div title="Title1" style="padding:10px"> | ||
| <p>Content1</p> | ||
| </div> | ||
| <div title="Title2" style="padding:10px"> | ||
| <p>Content2</p> | ||
| </div> | ||
| </div> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -0,0 +1,33 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Fluid Accordion - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Fluid Accordion</h2> | ||
| <p>This example shows how to set the width of accordion to a percentage of its parent container.</p> | ||
| <div style="margin:20px 0 10px 0;"></div> | ||
| <div class="easyui-accordion" style="width:100%;height:180px;"> | ||
| <div title="About" data-options="iconCls:'icon-ok'" style="overflow:auto;padding:10px;"> | ||
| <p>width: 100%</p> | ||
| </div> | ||
| <div title="Help" data-options="iconCls:'icon-help',href:'_content.html'" style="padding:10px;"> | ||
| </div> | ||
| </div> | ||
| <div style="margin:20px 0 10px 0;"></div> | ||
|
|
||
| <div class="easyui-accordion" style="width:50%;height:180px;"> | ||
| <div title="About" data-options="iconCls:'icon-ok'" style="overflow:auto;padding:10px;"> | ||
| <p>width: 50%</p> | ||
| </div> | ||
| <div title="Help" data-options="iconCls:'icon-help',href:'_content.html'" style="padding:10px;"> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,34 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Multiple Accordion Panels - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Multiple Accordion Panels</h2> | ||
| <p>Enable 'multiple' mode to expand multiple panels at one time.</p> | ||
| <div style="margin:20px 0 10px 0;"></div> | ||
| <div class="easyui-accordion" data-options="multiple:true" style="width:500px;height1:300px;"> | ||
| <div title="Language" data-options="iconCls:'icon-ok'" style="overflow:auto;padding:10px;"> | ||
| <p>A programming language is a formal language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely.</p> | ||
| </div> | ||
| <div title="Java" style="padding:10px;"> | ||
| <p>Java (Indonesian: Jawa) is an island of Indonesia. With a population of 135 million (excluding the 3.6 million on the island of Madura which is administered as part of the provinces of Java), Java is the world's most populous island, and one of the most densely populated places in the world.</p> | ||
| </div> | ||
| <div title="C#" style="padding:10px;"> | ||
| <p>C# is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines.</p> | ||
| </div> | ||
| <div title="Ruby" style="padding:10px;"> | ||
| <p>A dynamic, reflective, general-purpose object-oriented programming language.</p> | ||
| </div> | ||
| <div title="Fortran" style="padding:10px;"> | ||
| <p>Fortran (previously FORTRAN) is a general-purpose, imperative programming language that is especially suited to numeric computation and scientific computing.</p> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,48 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Accordion Tools - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Accordion Tools</h2> | ||
| <p>Click the tools on top right of panel to perform actions.</p> | ||
| <div style="margin:20px 0 10px 0;"></div> | ||
| <div class="easyui-accordion" style="width:500px;height:300px;"> | ||
| <div title="About" data-options="iconCls:'icon-ok'" style="overflow:auto;padding:10px;"> | ||
| <h3 style="color:#0099FF;">Accordion for jQuery</h3> | ||
| <p>Accordion is a part of easyui framework for jQuery. It lets you define your accordion component on web page more easily.</p> | ||
| </div> | ||
| <div title="Help" data-options="iconCls:'icon-help'" style="padding:10px;"> | ||
| <p>The accordion allows you to provide multiple panels and display one ore more at a time. Each panel has built-in support for expanding and collapsing. Clicking on a panel header to expand or collapse that panel body. The panel content can be loaded via ajax by specifying a 'href' property. Users can define a panel to be selected. If it is not specified, then the first panel is taken by default.</p> | ||
| </div> | ||
| <div title="DataGrid" style="padding:10px" data-options=" | ||
| selected:true, | ||
| tools:[{ | ||
| iconCls:'icon-reload', | ||
| handler:function(){ | ||
| $('#dg').datagrid('reload'); | ||
| } | ||
| }]"> | ||
| <table id="dg" class="easyui-datagrid" | ||
| data-options="url:'datagrid_data1.json',method:'get',fit:true,fitColumns:true,singleSelect:true"> | ||
| <thead> | ||
| <tr> | ||
| <th data-options="field:'itemid',width:80">Item ID</th> | ||
| <th data-options="field:'productid',width:100">Product ID</th> | ||
| <th data-options="field:'listprice',width:80,align:'right'">List Price</th> | ||
| <th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th> | ||
| <th data-options="field:'attr1',width:150">Attribute</th> | ||
| <th data-options="field:'status',width:50,align:'center'">Status</th> | ||
| </tr> | ||
| </thead> | ||
| </table> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,19 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Basic Calendar - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Basic Calendar</h2> | ||
| <p>Click to select date.</p> | ||
| <div style="margin:20px 0"></div> | ||
| <div class="easyui-calendar" style="width:250px;height:250px;"></div> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -0,0 +1,46 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Custom Calendar - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Custom Calendar</h2> | ||
| <p>This example shows how to custom the calendar date by using 'formatter' function.</p> | ||
| <div style="margin:20px 0"></div> | ||
|
|
||
| <div class="easyui-calendar" style="width:250px;height:250px;" data-options="formatter:formatDay"></div> | ||
|
|
||
| <script> | ||
| var d1 = Math.floor((Math.random()*30)+1); | ||
| var d2 = Math.floor((Math.random()*30)+1); | ||
| function formatDay(date){ | ||
| var m = date.getMonth()+1; | ||
| var d = date.getDate(); | ||
| var opts = $(this).calendar('options'); | ||
| if (opts.month == m && d == d1){ | ||
| return '<div class="icon-ok md">' + d + '</div>'; | ||
| } else if (opts.month == m && d == d2){ | ||
| return '<div class="icon-search md">' + d + '</div>'; | ||
| } | ||
| return d; | ||
| } | ||
| </script> | ||
| <style scoped="scoped"> | ||
| .md{ | ||
| height:16px; | ||
| line-height:16px; | ||
| background-position:2px center; | ||
| text-align:right; | ||
| font-weight:bold; | ||
| padding:0 2px; | ||
| color:red; | ||
| } | ||
| </style> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,28 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Disable Calendar Date - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Disable Calendar Date</h2> | ||
| <p>This example shows how to disable specified dates, only allows the user to select Mondays.</p> | ||
| <div style="margin:20px 0"></div> | ||
|
|
||
| <div class="easyui-calendar" style="width:250px;height:250px;" data-options=" | ||
| validator: function(date){ | ||
| if (date.getDay() == 1){ | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
| "></div> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -0,0 +1,30 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>First Day of Week - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>First Day of Week</h2> | ||
| <p>Choose the first day of the week.</p> | ||
|
|
||
| <div style="margin:20px 0"> | ||
| <select onchange="$('#cc').calendar({firstDay:this.value})"> | ||
| <option value="0">Sunday</option> | ||
| <option value="1">Monday</option> | ||
| <option value="2">Tuesday</option> | ||
| <option value="3">Wednesday</option> | ||
| <option value="4">Thursday</option> | ||
| <option value="5">Friday</option> | ||
| <option value="6">Saturday</option> | ||
| </select> | ||
| </div> | ||
|
|
||
| <div id="cc" class="easyui-calendar" style="width:250px;height:250px;"></div> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,23 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Fluid Calendar - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Fluid Calendar</h2> | ||
| <p>This example shows how to set the width of calendar to a percentage of its parent container.</p> | ||
| <div style="margin:20px 0"></div> | ||
| <div class="easyui-panel" style="width:700px;padding:10px"> | ||
| <p>width: 50%, height: 250px</p> | ||
| <div class="easyui-calendar" style="width:50%;height:250px;"></div> | ||
| <p>width: 30%, height: 40%</p> | ||
| <div class="easyui-calendar" style="width:30%;height:40%;"></div> | ||
| </div> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,36 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Combo Animation - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Combo Animation</h2> | ||
| <p>Change the animation type when open & close the drop-down panel.</p> | ||
| <div style="margin:20px 0"> | ||
| <span>Animation Type:</span> | ||
| <select onchange="changeAnimation(this.value)"> | ||
| <option>slide</option> | ||
| <option>fade</option> | ||
| <option>show</option> | ||
| </select> | ||
| </div> | ||
| <select id="cc" class="easyui-combo" style="width:150px"></select> | ||
| <script type="text/javascript"> | ||
| $(function(){ | ||
| changeAnimation('slide'); | ||
| }); | ||
| function changeAnimation(atype){ | ||
| $('#cc').combo('panel').panel({ | ||
| openAnimation:atype, | ||
| closeAnimation:(atype=='show'?'hide':atype) | ||
| }); | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,42 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Basic Combo - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Basic Combo</h2> | ||
| <p>Click the right arrow button to show drop down panel that can be filled with any content.</p> | ||
| <div style="margin:20px 0"></div> | ||
| <select id="cc" style="width:150px"></select> | ||
| <div id="sp"> | ||
| <div style="color:#99BBE8;background:#fafafa;padding:5px;">Select a language</div> | ||
| <div style="padding:10px"> | ||
| <input type="radio" name="lang" value="01"><span>Java</span><br/> | ||
| <input type="radio" name="lang" value="02"><span>C#</span><br/> | ||
| <input type="radio" name="lang" value="03"><span>Ruby</span><br/> | ||
| <input type="radio" name="lang" value="04"><span>Basic</span><br/> | ||
| <input type="radio" name="lang" value="05"><span>Fortran</span> | ||
| </div> | ||
| </div> | ||
| <script type="text/javascript"> | ||
| $(function(){ | ||
| $('#cc').combo({ | ||
| required:true, | ||
| editable:false | ||
| }); | ||
| $('#sp').appendTo($('#cc').combo('panel')); | ||
| $('#sp input').click(function(){ | ||
| var v = $(this).val(); | ||
| var s = $(this).next('span').text(); | ||
| $('#cc').combo('setValue', v).combo('setText', s).combo('hidePanel'); | ||
| }); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,86 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>ComboBox Actions - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>ComboBox</h2> | ||
| <p>Click the buttons below to perform actions.</p> | ||
|
|
||
| <div style="margin:20px 0;"> | ||
| <a href="javascript:void(0)" class="easyui-linkbutton" onclick="setvalue()">SetValue</a> | ||
| <a href="javascript:void(0)" class="easyui-linkbutton" onclick="alert($('#state').combobox('getValue'))">GetValue</a> | ||
| <a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#state').combobox('disable')">Disable</a> | ||
| <a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#state').combobox('enable')">Enable</a> | ||
| </div> | ||
| <script type="text/javascript"> | ||
| function setvalue(){ | ||
| $.messager.prompt('SetValue','Please input the value(CO,NV,UT,etc):',function(v){ | ||
| if (v){ | ||
| $('#state').combobox('setValue',v); | ||
| } | ||
| }); | ||
| } | ||
| </script> | ||
|
|
||
| <select id="state" class="easyui-combobox" name="state" style="width:200px;"> | ||
| <option value="AL">Alabama</option> | ||
| <option value="AK">Alaska</option> | ||
| <option value="AZ">Arizona</option> | ||
| <option value="AR">Arkansas</option> | ||
| <option value="CA">California</option> | ||
| <option value="CO">Colorado</option> | ||
| <option value="CT">Connecticut</option> | ||
| <option value="DE">Delaware</option> | ||
| <option value="FL">Florida</option> | ||
| <option value="GA">Georgia</option> | ||
| <option value="HI">Hawaii</option> | ||
| <option value="ID">Idaho</option> | ||
| <option value="IL">Illinois</option> | ||
| <option value="IN">Indiana</option> | ||
| <option value="IA">Iowa</option> | ||
| <option value="KS">Kansas</option> | ||
| <option value="KY">Kentucky</option> | ||
| <option value="LA">Louisiana</option> | ||
| <option value="ME">Maine</option> | ||
| <option value="MD">Maryland</option> | ||
| <option value="MA">Massachusetts</option> | ||
| <option value="MI">Michigan</option> | ||
| <option value="MN">Minnesota</option> | ||
| <option value="MS">Mississippi</option> | ||
| <option value="MO">Missouri</option> | ||
| <option value="MT">Montana</option> | ||
| <option value="NE">Nebraska</option> | ||
| <option value="NV">Nevada</option> | ||
| <option value="NH">New Hampshire</option> | ||
| <option value="NJ">New Jersey</option> | ||
| <option value="NM">New Mexico</option> | ||
| <option value="NY">New York</option> | ||
| <option value="NC">North Carolina</option> | ||
| <option value="ND">North Dakota</option> | ||
| <option value="OH" selected>Ohio</option> | ||
| <option value="OK">Oklahoma</option> | ||
| <option value="OR">Oregon</option> | ||
| <option value="PA">Pennsylvania</option> | ||
| <option value="RI">Rhode Island</option> | ||
| <option value="SC">South Carolina</option> | ||
| <option value="SD">South Dakota</option> | ||
| <option value="TN">Tennessee</option> | ||
| <option value="TX">Texas</option> | ||
| <option value="UT">Utah</option> | ||
| <option value="VT">Vermont</option> | ||
| <option value="VA">Virginia</option> | ||
| <option value="WA">Washington</option> | ||
| <option value="WV">West Virginia</option> | ||
| <option value="WI">Wisconsin</option> | ||
| <option value="WY">Wyoming</option> | ||
| </select> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -0,0 +1,71 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Basic ComboBox - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Basic ComboBox</h2> | ||
| <p>Type in ComboBox to try auto complete.</p> | ||
| <div style="margin:20px 0"></div> | ||
|
|
||
| <select class="easyui-combobox" name="state" style="width:200px;"> | ||
| <option value="AL">Alabama</option> | ||
| <option value="AK">Alaska</option> | ||
| <option value="AZ">Arizona</option> | ||
| <option value="AR">Arkansas</option> | ||
| <option value="CA">California</option> | ||
| <option value="CO">Colorado</option> | ||
| <option value="CT">Connecticut</option> | ||
| <option value="DE">Delaware</option> | ||
| <option value="FL">Florida</option> | ||
| <option value="GA">Georgia</option> | ||
| <option value="HI">Hawaii</option> | ||
| <option value="ID">Idaho</option> | ||
| <option value="IL">Illinois</option> | ||
| <option value="IN">Indiana</option> | ||
| <option value="IA">Iowa</option> | ||
| <option value="KS">Kansas</option> | ||
| <option value="KY">Kentucky</option> | ||
| <option value="LA">Louisiana</option> | ||
| <option value="ME">Maine</option> | ||
| <option value="MD">Maryland</option> | ||
| <option value="MA">Massachusetts</option> | ||
| <option value="MI">Michigan</option> | ||
| <option value="MN">Minnesota</option> | ||
| <option value="MS">Mississippi</option> | ||
| <option value="MO">Missouri</option> | ||
| <option value="MT">Montana</option> | ||
| <option value="NE">Nebraska</option> | ||
| <option value="NV">Nevada</option> | ||
| <option value="NH">New Hampshire</option> | ||
| <option value="NJ">New Jersey</option> | ||
| <option value="NM">New Mexico</option> | ||
| <option value="NY">New York</option> | ||
| <option value="NC">North Carolina</option> | ||
| <option value="ND">North Dakota</option> | ||
| <option value="OH" selected>Ohio</option> | ||
| <option value="OK">Oklahoma</option> | ||
| <option value="OR">Oregon</option> | ||
| <option value="PA">Pennsylvania</option> | ||
| <option value="RI">Rhode Island</option> | ||
| <option value="SC">South Carolina</option> | ||
| <option value="SD">South Dakota</option> | ||
| <option value="TN">Tennessee</option> | ||
| <option value="TX">Texas</option> | ||
| <option value="UT">Utah</option> | ||
| <option value="VT">Vermont</option> | ||
| <option value="VA">Virginia</option> | ||
| <option value="WA">Washington</option> | ||
| <option value="WV">West Virginia</option> | ||
| <option value="WI">Wisconsin</option> | ||
| <option value="WY">Wyoming</option> | ||
| </select> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -0,0 +1,22 @@ | ||
| [{ | ||
| "id":1, | ||
| "text":"Java", | ||
| "desc":"Write once, run anywhere" | ||
| },{ | ||
| "id":2, | ||
| "text":"C#", | ||
| "desc":"One of the programming languages designed for the Common Language Infrastructure" | ||
| },{ | ||
| "id":3, | ||
| "text":"Ruby", | ||
| "selected":true, | ||
| "desc":"A dynamic, reflective, general-purpose object-oriented programming language" | ||
| },{ | ||
| "id":4, | ||
| "text":"Perl", | ||
| "desc":"A high-level, general-purpose, interpreted, dynamic programming language" | ||
| },{ | ||
| "id":5, | ||
| "text":"Basic", | ||
| "desc":"A family of general-purpose, high-level programming languages" | ||
| }] |
| @@ -0,0 +1,47 @@ | ||
| [{ | ||
| "value":"f20", | ||
| "text":"Firefox 2.0 or higher", | ||
| "group":"Firefox" | ||
| },{ | ||
| "value":"f15", | ||
| "text":"Firefox 1.5.x", | ||
| "group":"Firefox" | ||
| },{ | ||
| "value":"f10", | ||
| "text":"Firefox 1.0.x", | ||
| "group":"Firefox" | ||
| },{ | ||
| "value":"ie7", | ||
| "text":"Microsoft Internet Explorer 7.0 or higher", | ||
| "group":"Microsoft Internet Explorer" | ||
| },{ | ||
| "value":"ie6", | ||
| "text":"Microsoft Internet Explorer 6.x", | ||
| "group":"Microsoft Internet Explorer" | ||
| },{ | ||
| "value":"ie5", | ||
| "text":"Microsoft Internet Explorer 5.x", | ||
| "group":"Microsoft Internet Explorer" | ||
| },{ | ||
| "value":"ie4", | ||
| "text":"Microsoft Internet Explorer 4.x", | ||
| "group":"Microsoft Internet Explorer" | ||
| },{ | ||
| "value":"op9", | ||
| "text":"Opera 9.0 or higher", | ||
| "group":"Opera" | ||
| },{ | ||
| "value":"op8", | ||
| "text":"Opera 8.x", | ||
| "group":"Opera" | ||
| },{ | ||
| "value":"op7", | ||
| "text":"Opera 7.x", | ||
| "group":"Opera" | ||
| },{ | ||
| "value":"Safari", | ||
| "text":"Safari" | ||
| },{ | ||
| "value":"Other", | ||
| "text":"Other" | ||
| }] |
| @@ -0,0 +1,33 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Custom Format in ComboBox - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Custom Format in ComboBox</h2> | ||
| <p>This sample shows how to custom the format of list item.</p> | ||
| <div style="margin:20px 0"></div> | ||
| <input class="easyui-combobox" name="language" data-options=" | ||
| url: 'combobox_data1.json', | ||
| method: 'get', | ||
| valueField: 'id', | ||
| textField: 'text', | ||
| panelWidth: 350, | ||
| panelHeight: 'auto', | ||
| formatter: formatItem | ||
| "> | ||
| <script type="text/javascript"> | ||
| function formatItem(row){ | ||
| var s = '<span style="font-weight:bold">' + row.text + '</span><br/>' + | ||
| '<span style="color:#888">' + row.desc + '</span>'; | ||
| return s; | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,23 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Load Dynamic ComboBox Data - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Load Dynamic ComboBox Data</h2> | ||
| <p>Click the button below to load data.</p> | ||
|
|
||
| <div style="margin:20px 0;"> | ||
| <a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#language').combobox('reload', 'combobox_data1.json')">LoadData</a> | ||
| </div> | ||
|
|
||
| <input class="easyui-combobox" id="language" name="language" | ||
| data-options="valueField:'id',textField:'text'"> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,36 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Fluid ComboBox - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Fluid ComboBox</h2> | ||
| <p>This example shows how to set the width of combobox to a percentage of its parent container.</p> | ||
| <div style="margin:20px 0"></div> | ||
| <p>width: 50%</p> | ||
| <input class="easyui-combobox" name="language" style="width:50%" | ||
| data-options=" | ||
| url: 'combobox_data2.json', | ||
| method: 'get', | ||
| valueField:'value', | ||
| textField:'text', | ||
| groupField:'group' | ||
| "> | ||
| <p>width: 30%</p> | ||
| <input class="easyui-combobox" name="language" style="width:30%" | ||
| data-options=" | ||
| url:'combobox_data1.json', | ||
| method:'get', | ||
| valueField:'id', | ||
| textField:'text', | ||
| panelHeight:'auto' | ||
| "> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -0,0 +1,26 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Group ComboBox - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Group ComboBox</h2> | ||
| <p>This example shows how to display combobox items in groups.</p> | ||
| <div style="margin:20px 0"></div> | ||
|
|
||
| <input class="easyui-combobox" name="browser" style="width:280px;" data-options=" | ||
| url: 'combobox_data2.json', | ||
| method: 'get', | ||
| valueField:'value', | ||
| textField:'text', | ||
| groupField:'group' | ||
| "> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -0,0 +1,32 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>ComboBox with Extra Icons- jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>ComboBox with Extra Icons</h2> | ||
| <p>The user can attach extra icons to the ComboBox.</p> | ||
| <div style="margin:20px 0"></div> | ||
| <input class="easyui-combobox" | ||
| name="language" | ||
| data-options=" | ||
| url:'combobox_data1.json', | ||
| method:'get', | ||
| valueField:'id', | ||
| textField:'text', | ||
| panelHeight:'auto', | ||
| icons:[{ | ||
| iconCls:'icon-add' | ||
| },{ | ||
| iconCls:'icon-cut' | ||
| }] | ||
| "> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -0,0 +1,71 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Multiline ComboBox - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Multiline ComboBox</h2> | ||
| <p>This example shows how to create a multiline ComboBox.</p> | ||
| <div style="margin:20px 0"></div> | ||
|
|
||
| <select class="easyui-combobox" name="state" data-options="multiple:true,multiline:true" style="width:200px;height:50px"> | ||
| <option value="AL">Alabama</option> | ||
| <option value="AK">Alaska</option> | ||
| <option value="AZ">Arizona</option> | ||
| <option value="AR">Arkansas</option> | ||
| <option value="CA">California</option> | ||
| <option value="CO">Colorado</option> | ||
| <option value="CT">Connecticut</option> | ||
| <option value="DE">Delaware</option> | ||
| <option value="FL">Florida</option> | ||
| <option value="GA">Georgia</option> | ||
| <option value="HI">Hawaii</option> | ||
| <option value="ID">Idaho</option> | ||
| <option value="IL">Illinois</option> | ||
| <option value="IN">Indiana</option> | ||
| <option value="IA">Iowa</option> | ||
| <option value="KS">Kansas</option> | ||
| <option value="KY">Kentucky</option> | ||
| <option value="LA">Louisiana</option> | ||
| <option value="ME">Maine</option> | ||
| <option value="MD">Maryland</option> | ||
| <option value="MA">Massachusetts</option> | ||
| <option value="MI">Michigan</option> | ||
| <option value="MN">Minnesota</option> | ||
| <option value="MS">Mississippi</option> | ||
| <option value="MO">Missouri</option> | ||
| <option value="MT">Montana</option> | ||
| <option value="NE">Nebraska</option> | ||
| <option value="NV">Nevada</option> | ||
| <option value="NH">New Hampshire</option> | ||
| <option value="NJ">New Jersey</option> | ||
| <option value="NM">New Mexico</option> | ||
| <option value="NY">New York</option> | ||
| <option value="NC">North Carolina</option> | ||
| <option value="ND">North Dakota</option> | ||
| <option value="OH" selected>Ohio</option> | ||
| <option value="OK">Oklahoma</option> | ||
| <option value="OR">Oregon</option> | ||
| <option value="PA">Pennsylvania</option> | ||
| <option value="RI">Rhode Island</option> | ||
| <option value="SC">South Carolina</option> | ||
| <option value="SD">South Dakota</option> | ||
| <option value="TN">Tennessee</option> | ||
| <option value="TX">Texas</option> | ||
| <option value="UT">Utah</option> | ||
| <option value="VT">Vermont</option> | ||
| <option value="VA">Virginia</option> | ||
| <option value="WA">Washington</option> | ||
| <option value="WV">West Virginia</option> | ||
| <option value="WI">Wisconsin</option> | ||
| <option value="WY">Wyoming</option> | ||
| </select> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -0,0 +1,29 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Multiple Select - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Load Dynamic ComboBox Data</h2> | ||
| <p>Drop down the panel and select multiple items.</p> | ||
| <div style="margin:20px 0"></div> | ||
|
|
||
| <input class="easyui-combobox" | ||
| name="language" | ||
| data-options=" | ||
| url:'combobox_data1.json', | ||
| method:'get', | ||
| valueField:'id', | ||
| textField:'text', | ||
| multiple:true, | ||
| panelHeight:'auto' | ||
| "> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -0,0 +1,73 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Navigate ComboBox - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Navigate ComboBox</h2> | ||
| <p>Navigate through combobox items width keyboard to select an item.</p> | ||
| <div style="margin:20px 0;"> | ||
| <input type="checkbox" checked onchange="$('#cc').combobox({selectOnNavigation:$(this).is(':checked')})"> | ||
| <span>SelectOnNavigation</span> | ||
| </div> | ||
|
|
||
| <select id="cc" class="easyui-combobox" name="state" style="width:200px;"> | ||
| <option value="AL">Alabama</option> | ||
| <option value="AK">Alaska</option> | ||
| <option value="AZ">Arizona</option> | ||
| <option value="AR">Arkansas</option> | ||
| <option value="CA">California</option> | ||
| <option value="CO">Colorado</option> | ||
| <option value="CT">Connecticut</option> | ||
| <option value="DE">Delaware</option> | ||
| <option value="FL">Florida</option> | ||
| <option value="GA">Georgia</option> | ||
| <option value="HI">Hawaii</option> | ||
| <option value="ID">Idaho</option> | ||
| <option value="IL">Illinois</option> | ||
| <option value="IN">Indiana</option> | ||
| <option value="IA">Iowa</option> | ||
| <option value="KS">Kansas</option> | ||
| <option value="KY">Kentucky</option> | ||
| <option value="LA">Louisiana</option> | ||
| <option value="ME">Maine</option> | ||
| <option value="MD">Maryland</option> | ||
| <option value="MA">Massachusetts</option> | ||
| <option value="MI">Michigan</option> | ||
| <option value="MN">Minnesota</option> | ||
| <option value="MS">Mississippi</option> | ||
| <option value="MO">Missouri</option> | ||
| <option value="MT">Montana</option> | ||
| <option value="NE">Nebraska</option> | ||
| <option value="NV">Nevada</option> | ||
| <option value="NH">New Hampshire</option> | ||
| <option value="NJ">New Jersey</option> | ||
| <option value="NM">New Mexico</option> | ||
| <option value="NY">New York</option> | ||
| <option value="NC">North Carolina</option> | ||
| <option value="ND">North Dakota</option> | ||
| <option value="OK">Oklahoma</option> | ||
| <option value="OR">Oregon</option> | ||
| <option value="PA">Pennsylvania</option> | ||
| <option value="RI">Rhode Island</option> | ||
| <option value="SC">South Carolina</option> | ||
| <option value="SD">South Dakota</option> | ||
| <option value="TN">Tennessee</option> | ||
| <option value="TX">Texas</option> | ||
| <option value="UT">Utah</option> | ||
| <option value="VT">Vermont</option> | ||
| <option value="VA">Virginia</option> | ||
| <option value="WA">Washington</option> | ||
| <option value="WV">West Virginia</option> | ||
| <option value="WI">Wisconsin</option> | ||
| <option value="WY">Wyoming</option> | ||
| </select> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -0,0 +1,27 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Binding to Remote Data - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Binding to Remote Data</h2> | ||
| <p>The ComboBox is bound to a remote data.</p> | ||
| <div style="margin:20px 0"></div> | ||
| <input class="easyui-combobox" | ||
| name="language" | ||
| data-options=" | ||
| url:'combobox_data1.json', | ||
| method:'get', | ||
| valueField:'id', | ||
| textField:'text', | ||
| panelHeight:'auto' | ||
| "> | ||
|
|
||
| </body> | ||
| </html> |
| @@ -0,0 +1,51 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Remote JSONP - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Remote JSONP</h2> | ||
| <p>This sample shows how to use JSONP to retrieve data from a remote site.</p> | ||
| <div style="margin:20px 0"></div> | ||
| <input class="easyui-combobox" style="width:250px" data-options=" | ||
| loader: myloader, | ||
| mode: 'remote', | ||
| valueField: 'id', | ||
| textField: 'name' | ||
| "> | ||
| <script> | ||
| var myloader = function(param,success,error){ | ||
| var q = param.q || ''; | ||
| if (q.length <= 1){return false} | ||
| $.ajax({ | ||
| url: 'http://ws.geonames.org/searchJSON', | ||
| dataType: 'jsonp', | ||
| data: { | ||
| featureClass: "P", | ||
| style: "full", | ||
| maxRows: 20, | ||
| name_startsWith: q | ||
| }, | ||
| success: function(data){ | ||
| var items = $.map(data.geonames, function(item){ | ||
| return { | ||
| id: item.geonameId, | ||
| name: item.name + (item.adminName1 ? ', ' + item.adminName1 : '') + ', ' + item.countryName | ||
| }; | ||
| }); | ||
| success(items); | ||
| }, | ||
| error: function(){ | ||
| error.apply(this, arguments); | ||
| } | ||
| }); | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,53 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>ComboGrid Actions - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>ComboGrid Actions</h2> | ||
| <p>Click the buttons below to perform actions.</p> | ||
| <div style="margin:20px 0"> | ||
| <a href="javascript:void(0)" class="easyui-linkbutton" onclick="getValue()">GetValue</a> | ||
| <a href="javascript:void(0)" class="easyui-linkbutton" onclick="setValue()">SetValue</a> | ||
| <a href="javascript:void(0)" class="easyui-linkbutton" onclick="disable()">Disable</a> | ||
| <a href="javascript:void(0)" class="easyui-linkbutton" onclick="enable()">Enable</a> | ||
| </div> | ||
| <input id="cc" class="easyui-combogrid" style="width:250px" data-options=" | ||
| panelWidth: 500, | ||
| idField: 'itemid', | ||
| textField: 'productname', | ||
| url: 'datagrid_data1.json', | ||
| method: 'get', | ||
| columns: [[ | ||
| {field:'itemid',title:'Item ID',width:80}, | ||
| {field:'productname',title:'Product',width:120}, | ||
| {field:'listprice',title:'List Price',width:80,align:'right'}, | ||
| {field:'unitcost',title:'Unit Cost',width:80,align:'right'}, | ||
| {field:'attr1',title:'Attribute',width:200}, | ||
| {field:'status',title:'Status',width:60,align:'center'} | ||
| ]], | ||
| fitColumns: true | ||
| "> | ||
| <script type="text/javascript"> | ||
| function getValue(){ | ||
| var val = $('#cc').combogrid('getValue'); | ||
| alert(val); | ||
| } | ||
| function setValue(){ | ||
| $('#cc').combogrid('setValue', 'EST-13'); | ||
| } | ||
| function disable(){ | ||
| $('#cc').combogrid('disable'); | ||
| } | ||
| function enable(){ | ||
| $('#cc').combogrid('enable'); | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,34 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Basic ComboGrid - jQuery EasyUI Demo</title> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> | ||
| <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> | ||
| <link rel="stylesheet" type="text/css" href="../demo.css"> | ||
| <script type="text/javascript" src="../../jquery.min.js"></script> | ||
| <script type="text/javascript" src="../../jquery.easyui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h2>Basic ComboGrid</h2> | ||
| <p>Click the right arrow button to show the DataGrid.</p> | ||
| <div style="margin:20px 0"></div> | ||
| <select class="easyui-combogrid" style="width:250px" data-options=" | ||
| panelWidth: 500, | ||
| idField: 'itemid', | ||
| textField: 'productname', | ||
| url: 'datagrid_data1.json', | ||
| method: 'get', | ||
| columns: [[ | ||
| {field:'itemid',title:'Item ID',width:80}, | ||
| {field:'productname',title:'Product',width:120}, | ||
| {field:'listprice',title:'List Price',width:80,align:'right'}, | ||
| {field:'unitcost',title:'Unit Cost',width:80,align:'right'}, | ||
| {field:'attr1',title:'Attribute',width:200}, | ||
| {field:'status',title:'Status',width:60,align:'center'} | ||
| ]], | ||
| fitColumns: true | ||
| "> | ||
| </select> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,12 @@ | ||
| {"total":28,"rows":[ | ||
| {"productid":"FI-SW-01","productname":"Koi","unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"}, | ||
| {"productid":"K9-DL-01","productname":"Dalmation","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"}, | ||
| {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":38.50,"attr1":"Venomless","itemid":"EST-11"}, | ||
| {"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"}, | ||
| {"selected":true,"productid":"RP-LI-02","productname":"Iguana","unitcost":12.00,"status":"P","listprice":35.50,"attr1":"Green Adult","itemid":"EST-13"}, | ||
| {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":158.50,"attr1":"Tailless","itemid":"EST-14"}, | ||
| {"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":83.50,"attr1":"With tail","itemid":"EST-15"}, | ||
| {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":23.50,"attr1":"Adult Female","itemid":"EST-16"}, | ||
| {"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":89.50,"attr1":"Adult Male","itemid":"EST-17"}, | ||
| {"productid":"AV-CB-01","productname":"Amazon Parrot","unitcost":92.00,"status":"P","listprice":63.50,"attr1":"Adult Male","itemid":"EST-18"} | ||
| ]} |