Package com.hp.hpl.jena.rdf.model

Examples of com.hp.hpl.jena.rdf.model.Seq


    }
  }

  public void testSeqAdd()
  {
    final Seq seq = model.createSeq();
    Assert.assertEquals(0, seq.size());
    Assert.assertTrue(model.contains(seq, RDF.type, RDF.Seq));
    //
    seq.add(AbstractModelTestBase.tvBoolean);
    Assert.assertTrue(seq.contains(AbstractModelTestBase.tvBoolean));
    Assert.assertFalse(seq.contains(!AbstractModelTestBase.tvBoolean));
    //
    seq.add(AbstractModelTestBase.tvByte);
    Assert.assertTrue(seq.contains(AbstractModelTestBase.tvByte));
    Assert.assertFalse(seq.contains((byte) 101));
    //
    seq.add(AbstractModelTestBase.tvShort);
    Assert.assertTrue(seq.contains(AbstractModelTestBase.tvShort));
    Assert.assertFalse(seq.contains((short) 102));
    //
    seq.add(AbstractModelTestBase.tvInt);
    Assert.assertTrue(seq.contains(AbstractModelTestBase.tvInt));
    Assert.assertFalse(seq.contains(-101));
    //
    seq.add(AbstractModelTestBase.tvLong);
    Assert.assertTrue(seq.contains(AbstractModelTestBase.tvLong));
    Assert.assertFalse(seq.contains(-102));
    //
    seq.add(AbstractModelTestBase.tvChar);
    Assert.assertTrue(seq.contains(AbstractModelTestBase.tvChar));
    Assert.assertFalse(seq.contains('?'));
    //
    seq.add(123.456f);
    Assert.assertTrue(seq.contains(123.456f));
    Assert.assertFalse(seq.contains(456.123f));
    //
    seq.add(-123.456d);
    Assert.assertTrue(seq.contains(-123.456d));
    Assert.assertFalse(seq.contains(-456.123d));
    //
    seq.add("a string");
    Assert.assertTrue(seq.contains("a string"));
    Assert.assertFalse(seq.contains("a necklace"));
    //
    seq.add(model.createLiteral("another string"));
    Assert.assertTrue(seq.contains("another string"));
    Assert.assertFalse(seq.contains("another necklace"));
    //
    seq.add(new LitTestObj(12345));
    Assert.assertTrue(seq.contains(new LitTestObj(12345)));
    Assert.assertFalse(seq.contains(new LitTestObj(54321)));
    //
    // Resource present = model.createResource( new ResTestObjF() );
    // Resource absent = model.createResource( new ResTestObjF() );
    // seq.add( present );
    // assertTrue( seq.contains( present ) );
    // assertFalse( seq.contains( absent ) );
    //
    Assert.assertEquals(11, seq.size());
  }
View Full Code Here


  }

  public void testSeqAddInts()
  {
    final int num = 10;
    final Seq seq = model.createSeq();
    for (int i = 0; i < num; i += 1)
    {
      seq.add(i);
    }
    Assert.assertEquals(num, seq.size());
    final List<RDFNode> L = seq.iterator().toList();
    Assert.assertEquals(num, L.size());
    for (int i = 0; i < num; i += 1)
    {
      Assert.assertEquals(i, ((Literal) L.get(i)).getInt());
    }
View Full Code Here

    final Resource tvResource = model.createResource();
    // Resource tvResObj = model.createResource(new ResTestObjF());
    final Object tvLitObj = new LitTestObj(1234);
    final Bag tvBag = model.createBag();
    final Alt tvAlt = model.createAlt();
    final Seq tvSeq = model.createSeq();

    final Seq seq = model.createSeq();
    seq.add(model.createResource());
    seq.add(1, true);
    Assert.assertEquals(true, seq.getBoolean(1));
    seq.add(1, (byte) 1);
    Assert.assertEquals((byte) 1, seq.getByte(1));
    seq.add(1, (short) 2);
    Assert.assertEquals((short) 2, seq.getShort(1));
    seq.add(1, -1);
    Assert.assertEquals(-1, seq.getInt(1));
    seq.add(1, -2);
    Assert.assertEquals(-2, seq.getLong(1));
    seq.add(1, '!');
    Assert.assertEquals('!', seq.getChar(1));
    seq.add(1, 123.456f);
    Assert.assertEquals(123.456f, seq.getFloat(1), 0.00005);
    seq.add(1, 12345.67890);
    Assert.assertEquals(12345.67890, seq.getDouble(1), 0.00000005);
    seq.add(1, "some string");
    Assert.assertEquals("some string", seq.getString(1));
    seq.add(1, tvLitObj);
    // assertEquals( tvLitObj, seq.getObject( 1, new LitTestObjF() ) );
    seq.add(1, tvResource);
    Assert.assertEquals(tvResource, seq.getResource(1));
    // seq.add( 1, tvResObj );
    // assertEquals( tvResObj, seq.getResource( 1, new ResTestObjF() ) );
    seq.add(1, tvLiteral);
    Assert.assertEquals(tvLiteral, seq.getLiteral(1));
    seq.add(1, tvBag);
    Assert.assertEquals(tvBag, seq.getBag(1));
    seq.add(1, tvAlt);
    Assert.assertEquals(tvAlt, seq.getAlt(1));
    seq.add(1, tvSeq);
    Assert.assertEquals(tvSeq, seq.getSeq(1));
    //
    Assert.assertEquals(0, seq.indexOf(1234543));
    Assert.assertEquals(1, seq.indexOf(tvSeq));
    Assert.assertEquals(2, seq.indexOf(tvAlt));
    Assert.assertEquals(3, seq.indexOf(tvBag));
    Assert.assertEquals(4, seq.indexOf(tvLiteral));
    Assert.assertEquals(5, seq.indexOf(tvResource));
    Assert.assertEquals(6, seq.indexOf(tvLitObj));
    Assert.assertEquals(7, seq.indexOf("some string"));
    Assert.assertEquals(8, seq.indexOf(12345.67890));
    Assert.assertEquals(9, seq.indexOf(123.456f));
    Assert.assertEquals(10, seq.indexOf('!'));
    Assert.assertEquals(11, seq.indexOf(-2));
    Assert.assertEquals(12, seq.indexOf(-1));
    Assert.assertEquals(13, seq.indexOf((short) 2));
    Assert.assertEquals(14, seq.indexOf((byte) 1));
    Assert.assertEquals(15, seq.indexOf(true));
  }
View Full Code Here

    // Resource tvResObj = model.createResource(new ResTestObjF());
    // Bag tvBag = model.createBag();
    // Alt tvAlt = model.createAlt();
    // Seq tvSeq = model.createSeq();
    final int num = 10;
    final Seq seq = model.createSeq();

    for (int i = 0; i < num; i++)
    {
      seq.add(i);
    }

    seq.set(5, AbstractModelTestBase.tvBoolean);
    Assert.assertEquals(AbstractModelTestBase.tvBoolean, seq.getBoolean(5));
    Assert.assertEquals(3, seq.getInt(4));
    Assert.assertEquals(5, seq.getInt(6));
    Assert.assertEquals(num, seq.size());

    seq.set(5, AbstractModelTestBase.tvByte);
    Assert.assertEquals(AbstractModelTestBase.tvByte, seq.getByte(5));
    Assert.assertEquals(3, seq.getInt(4));
    Assert.assertEquals(5, seq.getInt(6));
    Assert.assertEquals(num, seq.size());

    seq.set(5, AbstractModelTestBase.tvShort);
    Assert.assertEquals(AbstractModelTestBase.tvShort, seq.getShort(5));
    Assert.assertEquals(3, seq.getInt(4));
    Assert.assertEquals(5, seq.getInt(6));
    Assert.assertEquals(num, seq.size());

    seq.set(5, AbstractModelTestBase.tvInt);
    Assert.assertEquals(AbstractModelTestBase.tvInt, seq.getInt(5));
    Assert.assertEquals(3, seq.getInt(4));
    Assert.assertEquals(5, seq.getInt(6));
    Assert.assertEquals(num, seq.size());

    seq.set(5, AbstractModelTestBase.tvLong);
    Assert.assertEquals(AbstractModelTestBase.tvLong, seq.getLong(5));
    Assert.assertEquals(3, seq.getInt(4));
    Assert.assertEquals(5, seq.getInt(6));
    Assert.assertEquals(num, seq.size());

    seq.set(5, AbstractModelTestBase.tvString);
    Assert.assertEquals(AbstractModelTestBase.tvString, seq.getString(5));
    Assert.assertEquals(3, seq.getInt(4));
    Assert.assertEquals(5, seq.getInt(6));
    Assert.assertEquals(num, seq.size());

    seq.set(5, AbstractModelTestBase.tvBoolean);
    Assert.assertEquals(AbstractModelTestBase.tvBoolean, seq.getBoolean(5));
    Assert.assertEquals(3, seq.getInt(4));
    Assert.assertEquals(5, seq.getInt(6));
    Assert.assertEquals(num, seq.size());

    seq.set(5, AbstractModelTestBase.tvFloat);
    Assert.assertEquals(AbstractModelTestBase.tvFloat, seq.getFloat(5),
        0.00005);
    Assert.assertEquals(3, seq.getInt(4));
    Assert.assertEquals(5, seq.getInt(6));
    Assert.assertEquals(num, seq.size());

    seq.set(5, AbstractModelTestBase.tvDouble);
    Assert.assertEquals(AbstractModelTestBase.tvDouble, seq.getDouble(5),
        0.000000005);
    Assert.assertEquals(3, seq.getInt(4));
    Assert.assertEquals(5, seq.getInt(6));
    Assert.assertEquals(num, seq.size());

    seq.set(5, tvLiteral);
    Assert.assertEquals(tvLiteral, seq.getLiteral(5));
    Assert.assertEquals(3, seq.getInt(4));
    Assert.assertEquals(5, seq.getInt(6));
    Assert.assertEquals(num, seq.size());

    seq.set(5, tvResource);
    Assert.assertEquals(tvResource, seq.getResource(5));
    Assert.assertEquals(3, seq.getInt(4));
    Assert.assertEquals(5, seq.getInt(6));
    Assert.assertEquals(num, seq.size());

    seq.set(5, AbstractModelTestBase.tvLitObj);
    // assertEquals( tvLitObj, seq.getObject( 5, new LitTestObjF() ) );
    Assert.assertEquals(3, seq.getInt(4));
    Assert.assertEquals(5, seq.getInt(6));
    Assert.assertEquals(num, seq.size());

    // seq.set( 5, tvResObj );
    // assertEquals( tvResObj, seq.getResource( 5, new ResTestObjF() ) );
    // assertEquals( 3, seq.getInt( 4 ) );
    // assertEquals( 5, seq.getInt( 6 ) );
View Full Code Here

    }
  }

  public void testSeq7()
  {
    final Seq seq7 = model.createSeq();
    final String test = "seq7";
    int n = 0;
    n = ((n / 100) * 100) + 100;
    for (int i = 0; i < TestSeqMethods.num; i++)
    {
      seq7.add(i);
    }
    n = ((n / 100) * 100) + 100;
    seq7.set(5, AbstractModelTestBase.tvBoolean);
    n++;
    if (!(seq7.getBoolean(5) == AbstractModelTestBase.tvBoolean))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
    n = ((n / 100) * 100) + 100;
    seq7.set(5, AbstractModelTestBase.tvByte);
    n++;
    if (!(seq7.getByte(5) == AbstractModelTestBase.tvByte))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
    n = ((n / 100) * 100) + 100;
    seq7.set(5, AbstractModelTestBase.tvShort);
    n++;
    if (!(seq7.getShort(5) == AbstractModelTestBase.tvShort))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
    n = ((n / 100) * 100) + 100;
    seq7.set(5, AbstractModelTestBase.tvInt);
    n++;
    if (!(seq7.getInt(5) == AbstractModelTestBase.tvInt))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
    n = ((n / 100) * 100) + 100;
    seq7.set(5, AbstractModelTestBase.tvLong);
    n++;
    if (!(seq7.getLong(5) == AbstractModelTestBase.tvLong))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
    n = ((n / 100) * 100) + 100;
    seq7.set(5, AbstractModelTestBase.tvChar);
    n++;
    if (!(seq7.getChar(5) == AbstractModelTestBase.tvChar))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
    n = ((n / 100) * 100) + 100;
    seq7.set(5, AbstractModelTestBase.tvFloat);
    n++;
    if (!(seq7.getFloat(5) == AbstractModelTestBase.tvFloat))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
    n = ((n / 100) * 100) + 100;
    seq7.set(5, AbstractModelTestBase.tvDouble);
    n++;
    if (!(seq7.getDouble(5) == AbstractModelTestBase.tvDouble))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
    n = ((n / 100) * 100) + 100;
    seq7.set(5, AbstractModelTestBase.tvString);
    n++;
    if (!(seq7.getString(5).equals(AbstractModelTestBase.tvString)))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getLanguage(5).equals("")))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
    seq7.set(5, AbstractModelTestBase.tvString, TestSeqMethods.lang);
    n++;
    if (!(seq7.getString(5).equals(AbstractModelTestBase.tvString)))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getLanguage(5).equals(TestSeqMethods.lang)))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
    n = ((n / 100) * 100) + 100;
    seq7.set(5, tvLiteral);
    n++;
    if (!(seq7.getLiteral(5).equals(tvLiteral)))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
    n = ((n / 100) * 100) + 100;
    seq7.set(5, tvResource);
    n++;
    if (!(seq7.getResource(5).equals(tvResource)))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
    n = ((n / 100) * 100) + 100;
    seq7.set(5, anObject);
    n++;
    // if (!(seq7.getObject( 5, new LitTestObjF() )).equals( anObject ))
    // error(
    // test, n );
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
    n = ((n / 100) * 100) + 100;
    // seq7.set( 5, tvResObj );
    // n++;
    // if (!(seq7.getResource( 5, new ResTestObjF() ).equals( tvResObj )))
    // error(
    // test, n );
    n++;
    if (!(seq7.getInt(4) == 3))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.getInt(6) == 5))
    {
      error(test, n);
    }
    n++;
    if (!(seq7.size() == TestSeqMethods.num))
    {
      error(test, n);
    }
  }
View Full Code Here

    final Resource tvResource = model.createResource();
    // Resource tvResObj = model.createResource(new ResTestObjF());
    final Object tvLitObj = new LitTestObj(1234);
    final Bag tvBag = model.createBag();
    final Alt tvAlt = model.createAlt();
    final Seq tvSeq = model.createSeq();
    //
    final Seq seq = model.createSeq();
    seq.add(true);
    Assert.assertEquals(true, seq.getBoolean(1));
    seq.add((byte) 1);
    Assert.assertEquals((byte) 1, seq.getByte(2));
    seq.add((short) 2);
    Assert.assertEquals((short) 2, seq.getShort(3));
    seq.add(-1);
    Assert.assertEquals(-1, seq.getInt(4));
    seq.add(-2);
    Assert.assertEquals(-2, seq.getLong(5));
    seq.add('!');
    Assert.assertEquals('!', seq.getChar(6));
    seq.add(123.456f);
    Assert.assertEquals(123.456f, seq.getFloat(7), 0.00005);
    seq.add(12345.67890);
    Assert.assertEquals(12345.67890, seq.getDouble(8), 0.00000005);
    seq.add("some string");
    Assert.assertEquals("some string", seq.getString(9));
    seq.add(tvLitObj);
    // assertEquals( tvLitObj, seq.getObject( 10, new LitTestObjF() ) );
    seq.add(tvResource);
    Assert.assertEquals(tvResource, seq.getResource(11));
    // seq.add( tvResObj );
    // assertEquals( tvResObj, seq.getResource( 12, new ResTestObjF() ) );
    seq.add(tvLiteral);
    Assert.assertEquals(tvLiteral, seq.getLiteral(12));
    seq.add(tvBag);
    Assert.assertEquals(tvBag, seq.getBag(13));
    seq.add(tvAlt);
    Assert.assertEquals(tvAlt, seq.getAlt(14));
    seq.add(tvSeq);
    Assert.assertEquals(tvSeq, seq.getSeq(15));
    //
    try
    {
      seq.getInt(16);
      Assert.fail("there is no element 16");
    }
    catch (final SeqIndexBoundsException e)
    {
      JenaTestBase.pass();
    }
    try
    {
      seq.getInt(0);
      Assert.fail("there is no element 0");
    }
    catch (final SeqIndexBoundsException e)
    {
      JenaTestBase.pass();
View Full Code Here

     * resultModel.createLiteral("Sprachwahl", "de")); result.addProperty(
     * RSS.description, resultModel.createLiteral( "Leider ist die
     * gew??nschte Ressource nur in folgender/folgenden Sprache(n)
     * verf??gbar:",
     */
    Seq linkSeq = resultModel.createSeq();
    URL requestURL = ehRequest.getFullRequestURL();
    /*
     * StringBuffer targetLinkBuffer = new
     * StringBuffer(ehRequest.getRootURL() .toString());
     * targetLinkBuffer.append("/languageSetter?go="); try {
     * targetLinkBuffer.append(URLEncoder.encode(go, "utf-8")); } catch
     * (UnsupportedEncodingException e) { throw new RuntimeException(e); }
     */
    StringBuffer targetLinkBuffer = new StringBuffer(go);
    if (targetLinkBuffer.indexOf("?") > -1) {
      targetLinkBuffer.append('&');
    } else {
      targetLinkBuffer.append('?');
    //targetLinkBuffer.append('.');
    }
    targetLinkBuffer.append("appendLang=");
    String targetLinkBase = targetLinkBuffer.toString();
    // String targetLinkBase = new URL(res
    for (int i = 0; i < available.length; i++) {
      Resource languageLink = resultModel.createResource(LINK.Language);
      // languageLink.addProperty(DC.language, available[i]);
      ResIterator languageResIter = model.listSubjectsWithProperty(
          LANGUAGE.abbreviation, available[i]);
      Resource language;
      if (languageResIter.hasNext()) {
        language = languageResIter.nextResource();
        resultModel.add(JenaUtil.getExpandedResource(language, 3));
        language = (Resource) language.inModel(model);
      } else {
        language = resultModel.createResource(LANGUAGE.Language);
        language.addProperty(LANGUAGE.abbreviation, available[i]);
      }
      languageResIter.close();
      languageLink.addProperty(LANGUAGE.available, language);
      Resource target = resultModel.createResource(targetLinkBase + available[i]);
      languageLink.addProperty(LINK.target, target);
      // result.addProperty(LINK.link, languageLink);
      linkSeq.add(languageLink);
    }
    main.addProperty(LINK.links, linkSeq);
    response.setHeader(HeaderName.CONTENT_TYPE,
        "application/java-instance;class=com.hp.hpl.jena.rdf.model.Model");
    Resource transaction = resultModel.createResource(TRANSACTION.Transaction);
View Full Code Here

      Resource languageResource = (Resource) iter.next();
      targetModel.add(JenaUtil.getExpandedResource(languageResource, 3));
      languageResource = (Resource) languageResource.inModel(targetModel);
      languageSelectionList.add(languageResource);
    }
    Seq languageSelectionSeq = targetModel.createSeq();
    for (Iterator iter = languageSelectionList.iterator(); iter.hasNext();) {
      Resource current = (Resource) iter.next();
      languageSelectionSeq.add(current);
    }
    languageSelectionSeq.addProperty(RDF.type,
        LANGUAGE.LanguageSelectionSeq);
  }
View Full Code Here

    }
    String language = attachment.getLanguage();
    if (language != null) {
      attachmentItem.addProperty(DC.language, language);
    }
    Seq attachmentSeq;
    if (item.hasProperty(ATTACH.attachments)) {
      attachmentSeq = item.getProperty(ATTACH.attachments).getSeq();
    } else {

      attachmentSeq = model.createSeq();
      item.addProperty(ATTACH.attachments, attachmentSeq);
    }
    attachmentSeq.add(attachmentItem);
    // done only for file-upload attachments in their constructor
    // addPermissions(attachedDocument, permissions);
  }
View Full Code Here

      // as value and their poisition-Integer as key.
      Map untouchedAttachments = new HashMap();

      Statement attachStmt = target.getProperty(ATTACH.attachments);
      if (attachStmt != null) {
        Seq attachSeq = attachStmt.getSeq();
        for (int i = 1; i <= attachSeq.size(); i++) {
          Resource currentAttachment;
          try {
            currentAttachment = attachSeq.getResource(i);
          } catch (PropertyNotFoundException ex) {
            log.warn("Inncosistent sequence of attachment");
            fixSeq(attachSeq);
            i--;
            continue;
          }
          Statement languageStmt = currentAttachment
              .getProperty(DC.language);
          if ((languageStmt == null)
              || (languageStmt.getString().equals(language))) {
            String currentDocumentURL = currentAttachment
                .getProperty(ATTACH.document).getResource()
                .getURI();
            if (originalUrlCol.contains(currentDocumentURL)) {
              StmtIterator labelStmts = currentAttachment
                  .listProperties(RDFS.label);
              Collection otherLangLabels = new ArrayList();
              while (labelStmts.hasNext()) {
                Statement current = labelStmts.nextStatement();
                Literal value = current.getLiteral();
                if (!language.equals(value.getLanguage())) {
                  otherLangLabels.add(value);
                }
              }
              originalLabelsMap
                  .put(
                      currentDocumentURL,
                      otherLangLabels
                          .toArray(new Literal[otherLangLabels
                              .size()]));
              // TODO put in map of attachments to update
            }
            currentAttachment.removeProperties();

          } else {
            // remove attachment from sequence anyway and re-insert
            // it at the end at the best position
            // best position: for the moment the same index if
            // available in the new seq.
            untouchedAttachments.put(new Integer(i),
                currentAttachment);
          }
          attachSeq.remove(i--);
        }
      }
      // for every attachment
      String[] attachmentPositions = requestBody
          .getParameterValues("attachment_position");
      String[] attachmentTypes = requestBody
          .getParameterValues("attachment_type");
      String[] attachmentLabels = requestBody
          .getParameterValues("attachment_label");
      String[] attachmentWidths = requestBody
          .getParameterValues("attachment_width");
      String[] attachmentHeights = requestBody
          .getParameterValues("attachment_height");
      String[] attachmentMode = requestBody
          .getParameterValues("attachment_mode");
      String[] languageSpecific = requestBody
          .getParameterValues("attachment_language_specific");
      String[] summmaryViews = requestBody
          .getParameterValues("attachment_summary_view");
      // for url-attachments
      String[] attachmentURLs = requestBody
          .getParameterValues("attachment_url");
      String[] urlAttachmentContentTypes = requestBody
          .getParameterValues("attachment_contenttype");
      // for upload-attachments
      byte[][] attachmentContent = requestBody
          .getFileContents("attachment_file");
      String[] fileNames = requestBody.getFileNames("attachment_file");
      MimeType[] fileContentTypes = requestBody
          .getFileContentTypes("attachment_file");

      // int urlIter = 0;
      // int fileIter = 0;
      SortedSet attachmentsSet = new TreeSet();
      // Attachment[] attachments = new
      // Attachment[attachmentTypes.length];
      for (int i = 0; i < attachmentTypes.length; i++) {
        int position = Integer.parseInt(attachmentPositions[i]);
        if (position == -1) {
          continue;
        }
        String currentType = attachmentTypes[i];
        int width, height;
        try {
          width = Integer.parseInt(attachmentWidths[i]);
          height = Integer.parseInt(attachmentHeights[i]);
        } catch (NumberFormatException ex) {
          width = -1;
          height = -1;
        }
        Literal[] existingLabel = (Literal[]) originalLabelsMap
            .get(originalUrls[i]);
        Literal[] labels;
        if (existingLabel != null) {
          labels = new Literal[existingLabel.length + 1];
          System.arraycopy(existingLabel, 0, labels, 0,
              existingLabel.length);
        } else {
          labels = new Literal[1];
        }
        labels[labels.length - 1] = model.createLiteral(
            attachmentLabels[i], language);
        String attachmentLanguage;
        if (languageSpecific[i].equals("true")) {
          attachmentLanguage = language;
        } else {
          attachmentLanguage = null;
        }

        if ((currentType != null) && (currentType.equals("url"))) {
          if ((attachmentURLs[i] != null)
              && (!attachmentURLs[i].equals(""))) {
            URL attachmnetTargetURL;
            try {
              attachmnetTargetURL = new URL(baseURL,
                  attachmentURLs[i]);
            } catch (MalformedURLException e) {
              throw new RuntimeException(e);
            }

            MimeType mimeType;
            if ((urlAttachmentContentTypes[i] != null)
                && (!urlAttachmentContentTypes[i].equals(""))) {
              try {
                mimeType = new MimeType(
                    urlAttachmentContentTypes[i]);
              } catch (MimeTypeParseException e) {
                throw new HandlerException("Invalid MimeType",
                    e);
              }
            } else {
              mimeType = null;
            }
            attachmentsSet.add(new Attachment(labels,
                attachmnetTargetURL, mimeType, width, height,
                attachmentMode[i].equals("inline"),
                attachmentLanguage, position, summmaryViews[i]
                    .equals("true")));
            /*
             * Resource attachmentTarget =
             * model.createResource(attachmnetTargetURL.toString());
             * ItemUtil.addAttachment(target, attachmentTarget,
             * urlAttachmentContentTypes[i], attachmentLabels[i],
             * width, height, attachmentMode[i].equals("inline"));
             */
          }
          // urlIter++;

        } else {
          if ((attachmentContent != null)
              && (attachmentContent[i] != null)
              && (attachmentContent[i].length > 0)) {
            String fileName = fileNames[i];
            MimeType mimeType;
            mimeType = fileContentTypes[i];
            try {
              attachmentsSet.add(new Attachment(model, hashStore,
                  new URL(target.getURI()), labels,
                  attachmentContent[i], fileName, mimeType,
                  width, height, attachmentMode[i]
                      .equals("inline"),
                  attachmentLanguage, position,
                  summmaryViews[i].equals("true"),
                  permissions));
              /*
               * ItemUtil.addAttachment(target,
               * attachmentContent[i], fileNames[i],
               * fileContentTypes[i], attachmentLabels[i], width,
               * height, attachmentMode[i].equals("inline"));
               */
            } catch (IOException e) {
              throw new HandlerException(e);
            }
          }
          // fileIter++;
        }
      }

      for (Iterator iter = attachmentsSet.iterator(); iter.hasNext();) {
        Attachment current = (Attachment) iter.next();
        addAttachment(target, current, permissions);

      }
      if (untouchedAttachments.size() > 0) {
        attachStmt = target.getProperty(ATTACH.attachments);
        Seq attachSeq;
        if (attachStmt != null) {
          attachSeq = attachStmt.getSeq();
        } else {
          attachSeq = model.createSeq();
          target.addProperty(ATTACH.attachments, attachSeq);
        }
        for (int i = 0; untouchedAttachments.size() > 0; i++) {
          Resource untouched = (Resource) untouchedAttachments
              .get(new Integer(i + 1));
          if (untouchedAttachments != null) {
            if (i <= attachSeq.size()) {
              try {
                attachSeq.add(i + 1, untouched);
              } catch (NullPointerException ex) {
                log.warn("Incosistent sequence of attachment");
                fixSeq(attachSeq);
                // i--;
                continue;
              }
            } else {
              attachSeq.add(untouched);
            }
          }
        }
      }
    }
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.rdf.model.Seq

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.