@Test
  public void testNormalOperations() throws Exception {
    FedoraObjectUIPProcessor processor = new FedoraObjectUIPProcessor();
    AccessControlService aclService = mock(AccessControlService.class);
    when(aclService.hasAccess(
            any(PID.class), any(AccessGroupSet.class), eq(Permission.editAccessControl)))
        .thenReturn(true);
    processor.setAclService(aclService);

    InputStream entryPart =
        new FileInputStream(new File("src/test/resources/atompub/metadataUnpublish.xml"));
    Abdera abdera = new Abdera();
    Parser parser = abdera.getParser();
    Document<Entry> entryDoc = parser.parse(entryPart);
    Entry entry = entryDoc.getRoot();
    Map<String, org.jdom2.Element> originalMap = new HashMap<String, org.jdom2.Element>();
    org.jdom2.Element rdfElement = new org.jdom2.Element("RDF", JDOMNamespaceUtil.RDF_NS);
    org.jdom2.Element descElement = new org.jdom2.Element("Description", JDOMNamespaceUtil.RDF_NS);
    rdfElement.addContent(descElement);
    org.jdom2.Element relElement =
        new org.jdom2.Element(
            ContentModelHelper.CDRProperty.isPublished.getPredicate(), JDOMNamespaceUtil.CDR_NS);
    relElement.setText("yes");
    descElement.addContent(relElement);
    relElement =
        new org.jdom2.Element(
            ContentModelHelper.CDRProperty.embargoUntil.getPredicate(),
            JDOMNamespaceUtil.CDR_ACL_NS);
    relElement.setText("2013-02-01");
    descElement.addContent(relElement);
    relElement =
        new org.jdom2.Element(
            ContentModelHelper.FedoraProperty.hasModel.name(), JDOMNamespaceUtil.FEDORA_MODEL_NS);
    relElement.setText(ContentModelHelper.Model.SIMPLE.name());
    descElement.addContent(relElement);

    originalMap.put(ContentModelHelper.Datastream.RELS_EXT.getName(), rdfElement);
    Map<String, org.jdom2.Element> datastreamMap =
        AtomPubMetadataParserUtil.extractDatastreams(entry);

    MetadataUIP uip = mock(MetadataUIP.class);
    when(uip.getPID()).thenReturn(new PID("uuid:test/ACL"));
    when(uip.getOperation()).thenReturn(UpdateOperation.REPLACE);
    when(uip.getOriginalData()).thenReturn(originalMap);
    when(uip.getModifiedData()).thenReturn(originalMap);
    when(uip.getIncomingData()).thenReturn(datastreamMap);
    when(uip.getModifiedFiles()).thenReturn(getModifiedFiles(originalMap));

    UIPUpdatePipeline pipeline = mock(UIPUpdatePipeline.class);
    when(pipeline.processUIP(any(UpdateInformationPackage.class))).thenReturn(uip);
    processor.setPipeline(pipeline);
    processor.setVirtualDatastreamMap(new HashMap<String, Datastream>());
    DigitalObjectManager digitalObjectManager = mock(DigitalObjectManager.class);
    processor.setDigitalObjectManager(digitalObjectManager);
    processor.setOperationsMessageSender(mock(OperationsMessageSender.class));

    processor.process(uip);
  }
예제 #2
0
  public Document serialize(Object object, Document doc) {
    Class c = object.getClass();
    Integer id = getID(object);
    map.put(object, id);
    String mapSize = Integer.toString(map.size());

    // creating serialization objects
    Element objectElement = new Element("object");
    objectElement.setAttribute(new Attribute("class", c.getName()));
    objectElement.setAttribute(new Attribute("id", mapSize));
    doc.getRootElement().addContent(objectElement);

    if (!c.isArray()) // class is not an array
    {
      Field[] fields = c.getDeclaredFields();
      ArrayList<Element> fieldXML = serializeFields(fields, object, doc);
      for (int i = 0; i < fieldXML.size(); i++) {
        objectElement.addContent(fieldXML.get(i));
      }
    } else // class is an array
    {
      Object array = object;
      objectElement.setAttribute(new Attribute("length", Integer.toString(Array.getLength(array))));
      if (c.getComponentType().isPrimitive()) // class is array of primitives
      {
        for (int i = 0; i < Array.getLength(array); i++) {
          Element value = new Element("value");
          value.setText(Array.get(c, i).toString());
          objectElement.addContent(value);
        }
      } else // class is array of references
      {
        for (int j = 0; j < Array.getLength(array); j++) {
          Element ref = new Element("reference");
          id = getID(Array.get(c, j));
          if (id != -1) {
            ref.setText(Integer.toString(id));
          }
        }
        for (int k = 0; k < Array.getLength(array); k++) {
          serialize(Array.get(array, k), doc);
        }
      }
    }
    if (currentElement == 0) {
      referenceID = 0;
    }

    return doc;
  }
  @Override
  public boolean applyChange(MavenProject project, Element root, String eol)
      throws ProjectRewriteException {
    boolean modified = false;

    if (project.hasParent()) {
      Namespace ns = getNamespaceOrNull(root);
      Element parentVersionElement = root.getChild("parent", ns).getChild("version", ns);
      MavenProject parent = project.getParent();
      String parentId = ArtifactUtils.versionlessKey(parent.getGroupId(), parent.getArtifactId());

      String parentVersion = releaseVersions.get(parentId);
      if (null == parentVersion && consistentProjectVersions && releaseVersions.size() > 0) {
        // Use any release version, as the project's versions are consistent/global
        parentVersion = releaseVersions.values().iterator().next();
      }

      if (null == parentVersion) {
        if (parent.getVersion().equals(originalVersions.get(parentId))) {
          throw new ProjectRewriteException(
              "Release version for parent " + parent.getName() + " was not found");
        }
      } else {
        workLog.add("setting parent version to '" + parentVersion + "'");
        parentVersionElement.setText(parentVersion);
        modified = true;
      }
    }

    return modified;
  }
예제 #4
0
파일: Pref.java 프로젝트: keensta/RwEditor
  private void setData() {
    try {
      Document doc = builder.build(prefFile);

      Element rootNode = doc.getRootElement();
      Element RWDir = new Element("RWDir");

      rootNode.getChild("firstLoad").setText("no");
      RWDir.setText(RWDIRECTORY.getAbsolutePath());

      rootNode.addContent(RWDir);

      XMLOutputter xmlOutput = new XMLOutputter();
      FileWriter fw = new FileWriter(prefFile);

      xmlOutput.setFormat(Format.getPrettyFormat());
      xmlOutput.output(doc, fw);

      fw.close();
    } catch (IOException io) {
      io.printStackTrace();
    } catch (JDOMException e) {
      e.printStackTrace();
    }
  }
예제 #5
0
  /**
   * This will convert a single property and its value to an XML element and textual value.
   *
   * @param root JDOM root <code>Element</code> to add children to.
   * @param propertyName name to base element creation on.
   * @param propertyValue value to use for property.
   */
  private void createXMLRepresentation(Element root, String propertyName, String propertyValue) {

    int split;
    String name = propertyName;
    Element current = root;
    Element test = null;

    while ((split = name.indexOf(".")) != -1) {
      String subName = name.substring(0, split);
      name = name.substring(split + 1);

      // Check for existing element
      if ((test = current.getChild(subName)) == null) {
        Element subElement = new Element(subName);
        current.addContent(subElement);
        current = subElement;
      } else {
        current = test;
      }
    }

    // When out of loop, what's left is the final element's name
    Element last = new Element(name);
    last.setText(propertyValue);
    // Attribute attribute = new Attribute("value", propertyValue);
    // last.setAttribute(attribute);
    current.addContent(last);
  }
  static void filterMarkerInElement(List<Element> eltList, Map<String, Object> parameterMap) {
    final Pattern patternMarker = Pattern.compile("\\$\\{([^}]+)\\}"); // matching pattern is ${..}

    for (Element elt : eltList) {
      String elementValue = elt.getText();

      if (elementValue == null) {
        continue;
      }

      Matcher matcher = patternMarker.matcher(elementValue);
      while (matcher.find()) {
        String marker = matcher.group(0); // full pattern matched ${..}
        String markerName = matcher.group(1); // get only text between curly braces
        String parameterValue = ServletUtil.getFirstParameter(parameterMap.get(markerName));

        if (parameterValue != null) {
          elementValue = elementValue.replace(marker, parameterValue);
          elt.setText(elementValue);

        } else {
          logger.warn(
              "Found marker \""
                  + marker
                  + "\" with NO matching parameter in Element <"
                  + elt.getName()
                  + ">");
        }
      }
    }
  }
 private static void addPara(final Element li, final String text) {
   if (text == null) {
     return;
   }
   final Element p = new Element("p");
   li.addContent(p);
   p.setText(text);
 }
 private static void addPara(
     final Element body, final String id, final String clazz, final String text) {
   final Element p = new Element("p");
   body.addContent(p);
   p.setAttribute("id", id);
   p.setAttribute("class", clazz);
   p.setText(text);
 }
 private static void addTableRow(final Element table, final String[] cells) {
   final Element tr = new Element("tr");
   table.addContent(tr);
   for (final String columnName : cells) {
     final Element td = new Element("td");
     tr.addContent(td);
     td.setText(columnName);
   }
 }
예제 #10
0
 @Override
 public Element toXml() {
   Element command = new Element("send");
   command.setText(this.command);
   if (this.divide != 0) {
     command.setAttribute("divide", this.divide + "");
   }
   return command;
 }
예제 #11
0
  public static Document toInputValidationExceptionXml(InputValidationException ex)
      throws IOException {

    Element exceptionElement = new Element("InputValidationException", XML_NS);

    Element messageElement = new Element("message", XML_NS);
    messageElement.setText(ex.getMessage());
    exceptionElement.addContent(messageElement);

    return new Document(exceptionElement);
  }
예제 #12
0
  public static Document toInstanceNotFoundException(InstanceNotFoundException ex)
      throws IOException {

    Element exceptionElement = new Element("InstanceNotFoundException", XML_NS);

    if (ex.getInstanceId() != null) {
      Element instanceIdElement = new Element("instanceId", XML_NS);
      instanceIdElement.setText(ex.getInstanceId().toString());

      exceptionElement.addContent(instanceIdElement);
    }

    if (ex.getInstanceType() != null) {
      Element instanceTypeElement = new Element("instanceType", XML_NS);
      instanceTypeElement.setText(ex.getInstanceType());

      exceptionElement.addContent(instanceTypeElement);
    }
    return new Document(exceptionElement);
  }
예제 #13
0
  public Element generateXMLElementForLexicon() {
    Element featureElement = new Element("feature");
    featureElement.setAttribute("name", featureName);

    for (String value : values) {
      Element valueElement = new Element("value");
      valueElement.setText(value);
      featureElement.addContent(valueElement);
    }
    return featureElement;
  }
예제 #14
0
  @Override
  protected Element generateHead(final Opml opml) {
    Element retValue;

    retValue = super.generateHead(opml);

    final Element docs = new Element("docs");
    docs.setText(opml.getDocs());
    retValue.addContent(docs);

    return retValue;
  }
예제 #15
0
파일: Foo.java 프로젝트: gburgett/XFlat
    @Override
    public Element convert(Foo source) {
      Element ret = new Element("foo");

      if (source.id != null) ret.setAttribute("id", source.id, FooIdNs);

      Element fooInt = new Element("fooInt");
      fooInt.setText(Integer.toString(source.fooInt));
      ret.addContent(fooInt);

      return ret;
    }
예제 #16
0
 public Element toXml() {
   final Element answerElement = new Element(ChaiResponseSet.XML_NODE_ANSWER_VALUE);
   answerElement.setText(version.toString() + VERSION_SEPARATOR + answerHash);
   if (salt != null && salt.length() > 0) {
     answerElement.setAttribute(ChaiResponseSet.XML_ATTRIBUTE_SALT, salt);
   }
   answerElement.setAttribute(ChaiResponseSet.XML_ATTRIBUTE_CONTENT_FORMAT, formatType.toString());
   if (hashCount > 1) {
     answerElement.setAttribute(
         ChaiResponseSet.XML_ATTRIBUTE_HASH_COUNT, String.valueOf(hashCount));
   }
   return answerElement;
 }
예제 #17
0
파일: RTerrain.java 프로젝트: kba/neon
 public Element toElement() {
   Element terrain = new Element("type");
   terrain.setAttribute("id", id);
   terrain.setAttribute("char", text);
   terrain.setAttribute("color", color);
   if (modifier != Modifier.NONE) {
     terrain.setAttribute("mod", modifier.toString());
   }
   if (description != null && !description.isEmpty()) {
     terrain.setText(description);
   }
   if (type != Subtype.NONE) {
     terrain.setAttribute("sub", type.toString());
   }
   return terrain;
 }
예제 #18
0
 private void replaceOperators(final Element element, final Map<String, String> replacements) {
   assert element != null && replacements != null;
   List<Element> operatorsToReplace = new ArrayList<Element>();
   for (Element operator : element.getDescendants(new ElementFilter(OPERATOR, MATHMLNS))) {
     if (replacements.containsKey(operator.getTextTrim())) {
       operatorsToReplace.add(operator);
     }
   }
   for (Element operator : operatorsToReplace) {
     final String oldOperator = operator.getTextTrim();
     final String newOperator = replacements.get(oldOperator);
     operator.setText(newOperator);
     LOGGER.log(
         Level.FINE,
         "Operator ''{0}'' was replaced by ''{1}''",
         new Object[] {oldOperator, newOperator});
   }
 }
예제 #19
0
  private Element writeTeamResultXml(final TeamResult result) {
    /*  example team result XML file content
    <result matchNumber="1" teamNumber="1" cat1="-1" cat2="-1" cat3="-1" ... >
        Specific notes about this team and this match
    </result>
    */

    Element rootElm = new Element("result");
    rootElm.setAttribute("matchNumber", Integer.toString(result.getMatch().getMatchNumber()));
    rootElm.setAttribute("teamNumber", Integer.toString(result.getTeam().getTeamNumber()));

    for (Category c : result.getScoringCategories()) {
      rootElm.setAttribute(c.getName(), result.getScore(c).toString());
    }

    rootElm.setText(result.getNotes());
    return rootElm;
  }
예제 #20
0
 private Element writeTeamXml(final TeamInfo team) {
   /*  example team XML file content
   <team teamNumber="1329" name="RoboRebels" city="St Louis" state="MO" country="US">
       General notes about this team
   </team>
   */
   Element e = new Element("team");
   e.setAttribute("teamNumber", Integer.toString(team.getTeamNumber()));
   e.setAttribute("name", team.getTeamName());
   if (team.getCity().length() > 0) {
     e.setAttribute("city", team.getCity());
   }
   if (team.getState().length() > 0) {
     e.setAttribute("state", team.getState());
   }
   if (team.getCountry().length() > 0) {
     e.setAttribute("country", team.getCountry());
   }
   e.setText(team.getNotes());
   return e;
 }
  public void buildXMLData() {
    if (size != null) {
      Element e = new Element("size");

      e.setAttribute(new Attribute("witdh", Integer.toString(size.width)));
      e.setAttribute(new Attribute("height", Integer.toString(size.height)));

      root.addContent(e);
    }

    for (int x = 0; x < size.width / 32; x++) {
      for (int y = 0; y < size.height / 32; y++) {
        if (cases[x][y].type != null) {
          Element e = new Element(cases[x][y].type);
          e.setAttribute(new Attribute("x", cases[x][y].getXString()));
          e.setAttribute(new Attribute("y", cases[x][y].getYString()));
          e.setText(Integer.toString(cases[x][y].id));

          root.addContent(e);
        }
      }
    }
  }
예제 #22
0
 public Content render(Reference reference) {
   Element a = new Element("a");
   a.setAttribute("href", reference.getTarget());
   a.setText(reference.getValue());
   return a;
 }
예제 #23
0
  /**
   * sauvegarde une course dans un fichier xml temporaire listcourses.xml
   *
   * @param pcourse est l'objet course recuperée depuis l'ihm
   */
  public static void saveCoursesinTempFile(EssaiOrCourse pcourse) {

    SAXBuilder sxb = new SAXBuilder();
    Document document;
    try {
      document = sxb.build(new File(xmlTempPathListCourses));

      Element racine = document.getRootElement();

      //			racine.removeChildren("course");

      Element newCourseElement = new Element("course");
      newCourseElement.setAttribute(
          "nomEssaiOrCourse",
          pcourse.getNomEssaiOrCourse_() != null ? pcourse.getNomEssaiOrCourse_() : "");
      newCourseElement.setAttribute(
          "typeEssaiOrCourse",
          pcourse.getTypeEssaiOrCourse_() != null
              ? pcourse.getTypeEssaiOrCourse_().toString()
              : "");

      Element departAutomatique = new Element("departAutomatique");
      Element typeDeFin = new Element("typeDeFin");
      Element heureDebut = new Element("heureDebut");
      Element heureFin = new Element("heureFin");

      Element nbToursMax = new Element("nbToursMax");
      Element dureeMaxPilotage = new Element("dureeMaxPilotage");

      Element dureeConsecutiveMaxPilotage = new Element("dureeConsecutiveMaxPilotage");
      Element commentaire = new Element("commentaire");

      departAutomatique.setText(pcourse.isDepartAutomatique_() ? "true" : "false");
      typeDeFin.setText(pcourse.getTypeDeFin_() != null ? pcourse.getTypeDeFin_().toString() : "");
      heureDebut.setText(
          pcourse.getHeureDebut_() != null ? pcourse.getHeureDebut_().toString() : "");
      heureFin.setText(pcourse.getHeureFin_() != null ? pcourse.getHeureFin_().toString() : "");
      nbToursMax.setText(
          pcourse.getNbToursMax_() >= 0 ? String.valueOf(pcourse.getNbToursMax_()) : "");
      dureeMaxPilotage.setText(
          pcourse.getDureeMaxPilotage_() >= 0
              ? String.valueOf(pcourse.getDureeMaxPilotage_())
              : "");
      dureeConsecutiveMaxPilotage.setText(
          pcourse.getDureeConsecutiveMaxPilotage_() >= 0
              ? String.valueOf(pcourse.getDureeConsecutiveMaxPilotage_())
              : "");
      commentaire.setText(pcourse.getCommentaire_() != null ? pcourse.getCommentaire_() : "");

      newCourseElement.addContent(departAutomatique);
      newCourseElement.addContent(typeDeFin);
      newCourseElement.addContent(heureDebut);
      newCourseElement.addContent(heureFin);
      newCourseElement.addContent(nbToursMax);
      newCourseElement.addContent(dureeMaxPilotage);
      newCourseElement.addContent(dureeConsecutiveMaxPilotage);
      newCourseElement.addContent(commentaire);

      racine.addContent(newCourseElement);

      enregistre(document, xmlTempPathListCourses);

    } catch (Exception e) {
      e.getMessage();
    }
  }
예제 #24
0
파일: Source.java 프로젝트: sudduth/Aardin
 /** {@inheritDoc} */
 @Override
 public Element xml() {
   Element source = new Element("source");
   source.setText(getSource());
   return source;
 }
예제 #25
0
  protected void write(Bill bill, OutputStream out) throws IOException {
    Element billElement = new Element("bill");
    billElement.setAttribute("year", bill.getSession() + "");
    billElement.setAttribute("senateId", bill.getBillId());
    billElement.setAttribute("billId", bill.getBillId());
    billElement.setAttribute("title", bill.getTitle());
    billElement.setAttribute("law", bill.getLaw());
    billElement.setAttribute("lawSection", bill.getLawSection());
    billElement.setAttribute("assemblySameAs", bill.getSameAs());
    billElement.setAttribute("sameAs", bill.getSameAs());
    billElement.setAttribute(
        "sponsor", bill.getSponsor() != null ? bill.getSponsor().getFullname() : "n/a");

    Element elemCos = new Element("cosponsors");
    if (bill.getCoSponsors() != null) {
      Iterator<Person> itCos = bill.getCoSponsors().iterator();
      Person coSponsor = null;

      while (itCos.hasNext()) {
        Element elemCosChild = new Element("cosponsor");
        coSponsor = itCos.next();

        if (coSponsor.getFullname() != null) {
          elemCosChild.setText(coSponsor.getFullname());
          elemCos.addContent(elemCosChild);
        }
      }
    }
    billElement.addContent(elemCos);

    billElement.addContent(makeElement("summary", bill.getSummary()));
    billElement.addContent(makeElement("committee", bill.getCurrentCommittee()));

    Element votesElement = new Element("votes");
    for (Vote vote : bill.getVotes()) {
      Element voteElement = new Element("vote");
      voteElement.setAttribute("timestamp", vote.getVoteDate().getTime() + "");
      voteElement.setAttribute("ayes", vote.getAyes().size() + "");
      voteElement.setAttribute("nays", vote.getNays().size() + "");
      voteElement.setAttribute("abstains", vote.getAbstains().size() + "");
      voteElement.setAttribute("excused", vote.getExcused().size() + "");

      Iterator<String> it = vote.getAyes().iterator();

      while (it.hasNext()) {
        Element elemVoter = new Element("voter");
        elemVoter.setAttribute("name", it.next());
        elemVoter.setAttribute("vote", "aye");
        voteElement.addContent(elemVoter);
      }

      it = vote.getNays().iterator();

      while (it.hasNext()) {
        Element elemVoter = new Element("voter");
        elemVoter.setAttribute("name", it.next());
        elemVoter.setAttribute("vote", "nay");
        voteElement.addContent(elemVoter);
      }

      it = vote.getAbstains().iterator();

      while (it.hasNext()) {
        Element elemVoter = new Element("voter");
        elemVoter.setAttribute("name", it.next());
        elemVoter.setAttribute("vote", "abstain");
        voteElement.addContent(elemVoter);
      }

      it = vote.getExcused().iterator();

      while (it.hasNext()) {
        Element elemVoter = new Element("voter");
        elemVoter.setAttribute("name", it.next());
        elemVoter.setAttribute("vote", "excused");
        voteElement.addContent(elemVoter);
      }

      votesElement.addContent(voteElement);
    }
    billElement.addContent(votesElement);

    if (bill.getFulltext() != null) {
      billElement.addContent(makeElement("text", new CDATA(bill.getFulltext())));
    }

    if (bill.getMemo() != null) {
      billElement.addContent(makeElement("memo", new CDATA(bill.getMemo())));
    }

    write(makeElement("docket", billElement), out);
  }