Exemplo n.º 1
0
    /*
     * Test method for 'org.openxri.IRIUtils.URItoIRI(string)'
     */
    public void testURItoIRI()
    {
        string r;

        try {
            r = IRIUtils.URItoIRI("");
            assertTrue(r.Length == 0);

            r = IRIUtils.URItoIRI("http://xri.net/");
            assertTrue(r.Equals("http://xri.net/"));

            r = IRIUtils.URItoIRI("http://www.example.org/%44%c3%bCrst");
            assertTrue(r.Equals("http://www.example.org/D\u00FCrst"));

            r = IRIUtils.URItoIRI("http://r%C3%a9sum%c3%A9.example.org");
            assertTrue(r.Equals("http://r\u00E9sum\u00E9.example.org"));

            r = IRIUtils.URItoIRI("xri://@example*(http:%2F%2Fexample.org%2F)/");
            assertTrue(r.Equals("xri://@example*(http://example.org/)/"));

            // %-encoded BiDi - should not be converted
            r = IRIUtils.URItoIRI("http://example.org/%E2%80%AA-blah");
            assertTrue(r.Equals("http://example.org/%E2%80%AA-blah"));

            // non-IRI
            r = IRIUtils.URItoIRI("http://www.example.org/D%FCrst");
            assertTrue(r.Equals("http://www.example.org/D%FCrst"));

            // Han
            r = IRIUtils.XRItoIRI("http://xri.net/=\u8B19", false);
            assertTrue(r.Equals("http://xri.net/=\u8B19"));
            r = IRIUtils.IRItoURI(r);
            assertTrue(r.Equals("http://xri.net/=%E8%AC%99"));

            // XRI
            XRI xri = new XRI("=\u8B19");
            assertTrue(xri.toURINormalForm().Equals("xri://=%E8%AC%99"));

            // invalid Percent encoding
            try {
                r = IRIUtils.URItoIRI("http://www.example.org/D%Frst");
                assertTrue("Expected exception here", false);
            }
            catch (XRIParseException e) {
                // ok
            }
        }
        catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            assertTrue("exception caught!", false);
        }
    }
Exemplo n.º 2
0
	/**
	 * This is the recommended API to use for performing authority resolution an an XRI
	 * @param qxri
	 * @param flags - ResolverFlag
	 * @param state - ResolverState
	 * @return
	 * @throws PartialResolutionException
	 */
	public XRDS resolveAuthToXRDS(XRI qxri, ResolverFlags flags,
			ResolverState state) throws PartialResolutionException {
Exemplo n.º 3
0
		public ResolverStep(string qxri, string trust, string xrds, XRI _ref, Uri uri)
		{
			this.qxri  = qxri;
			this.trust = trust;
			this.xrds  = xrds;
			this._ref   = _ref;
			this.uri   = uri;
			this.timeCompleted = System.currentTimeMillis();
		}
Exemplo n.º 4
0
	public void pushFollowingRef(XRI _ref)
	{
		ResolverStep step = new ResolverStep(null, null, null, _ref, null);
		steps.add(step);
		numRefsFollowed++;
	}
Exemplo n.º 5
0
            //    throws XRIResolutionException
            protected InputStream getDataFromURI(URI oURI, string query, ResolverFlags flags, ResolverState state)
            {
                // the path better be empty
                if ((oURI.getPath() != null) && (oURI.getPath().Length > 0))
                return null;

                XRD oDesc = new XRD();
                XRI oExternal = new XRI("xri://@foo");
                oDesc.addRef(new Ref(oExternal.toString()));
                XRDS oDescs = new XRDS();
                oDescs.add(oDesc);

                state.pushResolved(oURI.toString(), flags.toString(), oDesc.toString(), oURI);

                return new ByteArrayInputStream(oDescs.toString().getBytes());
            }
Exemplo n.º 6
0
        public static Instruccion DescodificarInstruccion(byte codigo, ushort pos)
        {
            Instruccion instruccion       = null;
            ArgMemoria  argumentoMemoria  = Argumento.ConvertirEnArgumento((Main.ObtenerMemoria.ObtenerDireccion((ushort)(pos + 1)).Contenido * 256 + Main.ObtenerMemoria.ObtenerDireccion((ushort)(pos + 2)).Contenido).ToString("X4"), true) as ArgMemoria;
            ArgRegistro argumentoRegistro = Argumento.ConvertirEnArgumento(Main.ObtenerNombreRegistro(codigo % 4), false) as ArgRegistro;
            ArgLiteral  argumentoLiteral  = Argumento.ConvertirEnArgumento(Main.ObtenerMemoria.ObtenerDireccion((ushort)(pos + 1)).Contenido.ToString(), false) as ArgLiteral;

            switch (codigo / 8)
            {
            case 0:
                instruccion = new LD(argumentoRegistro);
                break;

            case 1:
                instruccion = new ST(argumentoRegistro);
                break;

            case 4:
            case 5:
                instruccion = new LDM(argumentoMemoria, argumentoRegistro);
                break;

            case 6:
            case 7:
                instruccion = new STM(argumentoRegistro, argumentoMemoria);
                break;

            case 2:
            case 3:
                instruccion = new LDI(argumentoLiteral, argumentoRegistro);
                break;

            case 8:
                instruccion = new ADD(argumentoRegistro);
                break;

            case 9:
                instruccion = new SUB(argumentoRegistro);
                break;

            case 10:
                instruccion = new CMP(argumentoRegistro);
                break;


            case 11:
                instruccion = new INC();
                break;

            case 12:
                instruccion = new ADI(argumentoLiteral);
                break;

            case 13:
                instruccion = new SUI(argumentoLiteral);
                break;

            case 14:
            case 15:
                instruccion = new CMI(argumentoLiteral);
                break;


            case 16:
                instruccion = new ANA(argumentoRegistro);
                break;

            case 17:
                instruccion = new ORA(argumentoRegistro);
                break;

            case 18:
                instruccion = new XRA(argumentoRegistro);
                break;


            case 19:
                instruccion = new CMA();
                break;

            case 20:
                instruccion = new ANI(argumentoLiteral);
                break;

            case 21:
                instruccion = new ORI(argumentoLiteral);
                break;

            case 22:
            case 23:
                instruccion = new XRI(argumentoLiteral);
                break;

            case 24:
            case 25:
                instruccion = new JMP(argumentoMemoria);
                break;

            case 26:
                instruccion = new BEQ(argumentoMemoria);
                break;

            case 27:
                instruccion = new BC(argumentoMemoria);
                break;

            case 28:
            case 29:
                instruccion = new LF();
                break;

            case 30:
                instruccion = new IN(argumentoMemoria, argumentoRegistro);
                break;

            case 31:
                instruccion = new OUT(argumentoRegistro, argumentoMemoria);
                break;
            }
            return(instruccion);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns a non-null XRIReference if an XRIReference is consumed from the 
        /// stream
        /// </summary>
        /// <param name="oStream"></param>
        /// <returns></returns>
        static XRIReference scanXRIReference(ParseStream oStream)
        {
            // make sure we have a valid XRI Value
            XRI oXRI = new XRI();
            if (oXRI.scan(oStream))
            {
                return oXRI;
            }

            // try parsing it as a relative XRI
            RelativeXRI oRelXRI = new RelativeXRI();
            if (oRelXRI.scan(oStream))
            {
                return oRelXRI;
            }

            return null;
        }
Exemplo n.º 8
0
		public ResolverStep(String qxri, String trust, String xrds, XRI ref, URI uri)
		{
			this.qxri  = qxri;
			this.trust = trust;
			this.xrds  = xrds;
			this.ref   = ref;
			this.uri   = uri;
			this.timeCompleted = System.currentTimeMillis();
		}
Exemplo n.º 9
0
        public bool StartsWith(XRI xri)
        {
            if (xri.Authority == null)
                return (true);
            if (xri.Authority != null && this.Authority == null)
                return (false);

            if (!this.Authority.Equals(xri.Authority))
                return (false);

            if (xri.Path == null)
                return (true);
            if (xri.Path != null && this.Path == null)
                return (false);

            IList<XRISegment> thisSegments = this.Path.Segments;
            IList<XRISegment> xriSegments = xri.Path.Segments;

            if (thisSegments.Count < xriSegments.Count)
                return (false);

            for (int i = 0; i < xriSegments.Count; i++)
            {
                if (!(thisSegments[i].Equals(xriSegments[i])))
                    return (false);
            }

            return (true);
        }
Exemplo n.º 10
0
        public XRI3(XRI xri, string xriPart)
        {
            StringBuilder buffer = new StringBuilder();

            buffer.Append(xri.ToString());
            buffer.Append(xriPart);

            this.rule = XRI3Util.getParser().parse("xri", buffer.ToString());
            this.read();
        }