本文整理汇总了Java中com.liferay.portal.kernel.xml.Element.attributeValue方法的典型用法代码示例。如果您正苦于以下问题:Java Element.attributeValue方法的具体用法?Java Element.attributeValue怎么用?Java Element.attributeValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.liferay.portal.kernel.xml.Element
的用法示例。
在下文中一共展示了Element.attributeValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: importQuestions
import com.liferay.portal.kernel.xml.Element; //导入方法依赖的package包/类
private static void importQuestions(LearningActivity newLarn, long userId, PortletDataContext context, ServiceContext serviceContext, Element actElement) throws SystemException, PortalException {
for(Element qElement:actElement.elements("question")){
String pathq = qElement.attributeValue("path");
TestQuestion question=(TestQuestion)context.getZipEntryAsObject(pathq);
question.setActId(newLarn.getActId());
TestQuestion nuevaQuestion=TestQuestionLocalServiceUtil.addQuestion(question.getActId(), question.getText(), question.getQuestionType());
log.info(" Test Question: " + nuevaQuestion.getQuestionId() /*Jsoup.parse(nuevaQuestion.getText()).text()*/);
//Si tenemos ficheros en las descripciones de las preguntas.
for (Element actElementFile : qElement.elements("descriptionfile")) {
String description = importDescriptionFile(nuevaQuestion.getText(), actElementFile, userId, context, serviceContext);
//log.info(" description : " + description );
nuevaQuestion.setText(description);
TestQuestionLocalServiceUtil.updateTestQuestion(nuevaQuestion);
}
QuestionType qt =new QuestionTypeRegistry().getQuestionType(question.getQuestionType());
qt.importQuestionAnswers(context, qElement, nuevaQuestion.getQuestionId(), userId, serviceContext);
}
}
示例2: importQuestionAnswers
import com.liferay.portal.kernel.xml.Element; //导入方法依赖的package包/类
@Override
public void importQuestionAnswers(PortletDataContext context, Element entryElement, long questionId, long userId, ServiceContext serviceContext) throws SystemException, PortalException{
for(Element aElement:entryElement.elements("questionanswer")){
String patha = aElement.attributeValue("path");
TestAnswer oldanswer=(TestAnswer)context.getZipEntryAsObject(patha);
TestAnswer answer = TestAnswerLocalServiceUtil.addTestAnswer(questionId, oldanswer.getAnswer(), oldanswer.getFeedbackCorrect(), oldanswer.getFeedbacknocorrect(), oldanswer.isIsCorrect());
//Si tenemos ficheros en las descripciones de las respuestas.
for (Element actElementFile : aElement.elements("descriptionfile")) {
FileEntry oldFile = (FileEntry)context.getZipEntryAsObject(actElementFile.attributeValue("path"));
ModuleDataHandlerImpl m = new ModuleDataHandlerImpl();
FileEntry newFile;
long folderId=0;
String description = "";
try {
InputStream input = context.getZipEntryAsInputStream(actElementFile.attributeValue("file"));
long repositoryId = DLFolderConstants.getDataRepositoryId(context.getScopeGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
folderId = DLFolderUtil.createDLFoldersForLearningActivity(userId,repositoryId,serviceContext).getFolderId();
newFile = DLAppLocalServiceUtil.addFileEntry(userId, repositoryId , folderId , oldFile.getTitle(), "contentType", oldFile.getTitle(), StringPool.BLANK, StringPool.BLANK, IOUtils.toByteArray(input), serviceContext );
description = ImportUtil.descriptionFileParserLarToDescription(answer.getAnswer(), oldFile, newFile);
} catch(DuplicateFileException dfl){
FileEntry existingFile = DLAppLocalServiceUtil.getFileEntry(context.getScopeGroupId(), folderId, oldFile.getTitle());
description = ImportUtil.descriptionFileParserLarToDescription(answer.getAnswer(), oldFile, existingFile);
} catch (Exception e) {
e.printStackTrace();
}
answer.setAnswer(description);
TestAnswerLocalServiceUtil.updateTestAnswer(answer);
}
}
}
示例3: doImportData
import com.liferay.portal.kernel.xml.Element; //导入方法依赖的package包/类
@Override
protected PortletPreferences doImportData(PortletDataContext context, String portletId, PortletPreferences preferences, String data) throws Exception {
context.importPermissions("com.liferay.lms.model.module", context.getSourceGroupId(),context.getScopeGroupId());
log.info("\n-----------------------------\ndoImport1Data STARTS12");
Document document = SAXReaderUtil.read(data);
Element rootElement = document.getRootElement();
long entryOld=0;
long newModuleId = 0;
String path = null;
Module entry = null;
//Creamos un hashmap donde guardaremos la relación de los ids antiguos y los nuevos para poder cambiar las actividades precedentes
HashMap<Long,Long> relationModule = new HashMap<Long, Long>();
HashMap<Long,Long> relationActivities = new HashMap<Long, Long>();
//Tipos de actividades permitidas en la plataforma:
LearningActivityTypeRegistry learningActivityTypeRegistry = new LearningActivityTypeRegistry();
HashMap<Integer, LearningActivityType> hashLearningActivityType = learningActivityTypeRegistry.getLearningActivityTypesForCreatingHash();
for (Element entryElement : rootElement.elements("moduleentry")) {
path = entryElement.attributeValue("path");
if (context.isPathNotProcessed(path)) {
entry = (Module)context.getZipEntryAsObject(path);
if(entryOld != entry.getModuleId()){
entryOld=entry.getModuleId();
newModuleId = importEntry(context,entryElement, entry, relationActivities, hashLearningActivityType);
relationModule.put(entryOld, newModuleId);
} else{
log.info("repetidooooo el modulo "+entry.getModuleId());
}
}
}
ImportUtil.updateModuleIds(context.getScopeGroupId(), relationModule);
ImportUtil.updateActivityIds(context.getScopeGroupId(), relationActivities);
log.info("doImportData ENDS" + "\n-----------------------------\n" );
return null;
}
示例4: importEntry
import com.liferay.portal.kernel.xml.Element; //导入方法依赖的package包/类
/**
* Llamamos a esta función con el nodo moduleentry del archivo portlet-dat.xml dentro de \groups\xxxx\portlets\courseadmin_WAR_liferaylmsportlet
* @param context todo el war
* @param entryElement elemento moduleentry
* @param entry modulo cogido del war, de momento contiene los ids antiguos
* @param hashLearningActivityType
* @param relationActivities
* @return
* @throws SystemException
* @throws PortalException
* @throws DocumentException
*/
private long importEntry(PortletDataContext context, Element entryElement, Module entry, HashMap<Long, Long> relationActivities, HashMap<Integer, LearningActivityType> hashLearningActivityType ) throws SystemException, PortalException {
long userId = context.getUserId(entry.getUserUuid());
ServiceContext serviceContext=new ServiceContext();
serviceContext.setUserId(userId);
serviceContext.setCompanyId(context.getCompanyId());
serviceContext.setScopeGroupId(context.getScopeGroupId());
//Cargamos los datos del contexto del curso actual, sobre el que vamos a importar
entry.setGroupId(context.getScopeGroupId());
entry.setUserId(userId);
entry.setCompanyId(context.getCompanyId());
//Para convertir < correctamente.
entry.setDescription(entry.getDescription().replace("&lt;", "<"));
log.info("entry companyId: " + entry.getCompanyId());
log.info("entry groupId: " +entry.getGroupId() );
log.info("entry userId: " +entry.getUserId() );
log.info("entry moduleId: " +entry.getModuleId() );
log.info("ENTRY ELEMENT-->"+entryElement);
//Creamos el nuevo módulo en el curso
Module newModule = ModuleLocalServiceUtil.addmodule(entry);
//Importamos las imagenes de los módulos
ModuleImport.importImageModule(context, entryElement, serviceContext, userId, newModule);
//Importamos los archivos de la descripción
ModuleImport.importDescriptionFile(context, entryElement, serviceContext, userId, newModule);
//Importamos las actividades
long newActId = 0;
LearningActivity larn = null;
String path = null;
for (Element actElement : entryElement.elements("learningactivity")) {
path = actElement.attributeValue("path");
larn=(LearningActivity)context.getZipEntryAsObject(path);
log.info("tipo a comprobar: " + larn.getTypeId());
if(hashLearningActivityType.containsKey(larn.getTypeId())){
log.info("actividad correcta: " + larn.getTypeId());
newActId = LearningActivityImport.importLearningActivity(context, entryElement, serviceContext, userId, newModule, actElement, larn);
//Comprobamos que podamos crear una actividad de ese tipo
relationActivities.put(larn.getActId(), newActId);
}else{
log.info("actividad incorrecta: " + larn.getTypeId());
throw new NoLearningActivityTypeActiveException("No existe el tipo de actividad: " + larn.getTypeId());
}
}
log.info("Fin importación de módulo: " + newModule.getModuleId());
return newModule.getModuleId();
}
示例5: parseImage
import com.liferay.portal.kernel.xml.Element; //导入方法依赖的package包/类
private static void parseImage(Element imgElement, Element element, PortletDataContext context, Long moduleId){
String src = imgElement.attributeValue("src");
String []srcInfo = src.split("/");
String fileUuid = "", fileGroupId ="";
if(srcInfo.length >= 6 && srcInfo[1].compareTo("documents") == 0){
fileUuid = srcInfo[srcInfo.length-1];
fileGroupId = srcInfo[2];
String []uuidInfo = fileUuid.split("\\?");
String uuid="";
if(srcInfo.length > 0){
uuid=uuidInfo[0];
}
FileEntry file;
try {
file = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, Long.parseLong(fileGroupId));
String pathqu = getEntryPath(context, file);
String pathFile = getDescriptionModulePath(context, moduleId);
context.addZipEntry(pathqu, file);
context.addZipEntry(pathFile + file.getTitle(), file.getContentStream());
Element entryElementLoc= element.addElement("descriptionfile");
entryElementLoc.addAttribute("path", pathqu);
entryElementLoc.addAttribute("file", pathFile + file.getTitle());
log.info(" + Description file image : " + file.getTitle() +" ("+file.getMimeType()+")");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.info("* ERROR! Description file image : " + e.getMessage());
}
}
}
示例6: validateLayoutPrototypes
import com.liferay.portal.kernel.xml.Element; //导入方法依赖的package包/类
protected void validateLayoutPrototypes(
Element layoutsElement, List<Element> layoutElements)
throws Exception {
List<Tuple> missingLayoutPrototypes = new ArrayList<Tuple>();
String layoutSetPrototypeUuid = layoutsElement.attributeValue(
"layout-set-prototype-uuid");
if (Validator.isNotNull(layoutSetPrototypeUuid)) {
try {
LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototypeByUuid(
layoutSetPrototypeUuid);
}
catch (NoSuchLayoutSetPrototypeException nlspe) {
String layoutSetPrototypeName = layoutsElement.attributeValue(
"layout-set-prototype-name");
missingLayoutPrototypes.add(
new Tuple(
LayoutSetPrototype.class.getName(),
layoutSetPrototypeUuid, layoutSetPrototypeName));
}
}
for (Element layoutElement : layoutElements) {
String layoutPrototypeUuid = GetterUtil.getString(
layoutElement.attributeValue("layout-prototype-uuid"));
if (Validator.isNotNull(layoutPrototypeUuid)) {
try {
LayoutPrototypeLocalServiceUtil.getLayoutPrototypeByUuid(
layoutPrototypeUuid);
}
catch (NoSuchLayoutPrototypeException nslpe) {
String layoutPrototypeName = GetterUtil.getString(
layoutElement.attributeValue("layout-prototype-name"));
missingLayoutPrototypes.add(
new Tuple(
LayoutPrototype.class.getName(),
layoutPrototypeUuid, layoutPrototypeName));
}
}
}
if (!missingLayoutPrototypes.isEmpty()) {
throw new LayoutPrototypeException(missingLayoutPrototypes);
}
}
示例7: doImportStagedModel
import com.liferay.portal.kernel.xml.Element; //导入方法依赖的package包/类
@Override
protected void doImportStagedModel(
PortletDataContext portletDataContext, Artist artist)
throws Exception {
long userId = portletDataContext.getUserId(artist.getUserUuid());
ServiceContext serviceContext = portletDataContext.createServiceContext(
artist);
Artist importedArtist = null;
if (portletDataContext.isDataStrategyMirror()) {
Artist existingArtist =
ArtistLocalServiceUtil.fetchArtistByUuidAndGroupId(
artist.getUuid(), portletDataContext.getScopeGroupId());
if (existingArtist == null) {
serviceContext.setUuid(artist.getUuid());
importedArtist = ArtistLocalServiceUtil.addArtist(
userId, artist.getName(), artist.getBio(), null,
serviceContext);
}
else {
importedArtist = ArtistLocalServiceUtil.updateArtist(
userId, existingArtist.getArtistId(), artist.getName(),
artist.getBio(), null, serviceContext);
}
}
else {
importedArtist = ArtistLocalServiceUtil.addArtist(
userId, artist.getName(), artist.getBio(), null,
serviceContext);
}
Element artistElement =
portletDataContext.getImportDataStagedModelElement(artist);
List<Element> attachmentElements =
portletDataContext.getReferenceDataElements(
artistElement, FileEntry.class,
PortletDataContext.REFERENCE_TYPE_WEAK);
for (Element attachmentElement : attachmentElements) {
String path = attachmentElement.attributeValue("path");
FileEntry fileEntry =
(FileEntry)portletDataContext.getZipEntryAsObject(path);
importedArtist = ArtistLocalServiceUtil.updateArtist(
userId, importedArtist.getArtistId(), importedArtist.getName(),
importedArtist.getBio(), fileEntry.getContentStream(),
serviceContext);
}
portletDataContext.importClassedModel(artist, importedArtist);
}
示例8: doImportStagedModel
import com.liferay.portal.kernel.xml.Element; //导入方法依赖的package包/类
@Override
protected void doImportStagedModel(
PortletDataContext portletDataContext, Album album)
throws Exception {
long userId = portletDataContext.getUserId(album.getUserUuid());
ServiceContext serviceContext = portletDataContext.createServiceContext(
album);
String artistPath = ExportImportPathUtil.getModelPath(
portletDataContext, Artist.class.getName(), album.getArtistId());
Artist artist = (Artist)portletDataContext.getZipEntryAsObject(
artistPath);
if (artist != null) {
StagedModelDataHandlerUtil.importReferenceStagedModel(
portletDataContext, album, Artist.class, album.getArtistId());
}
Map<Long, Long> artistIds =
(Map<Long, Long>)portletDataContext.getNewPrimaryKeysMap(
Artist.class);
long artistId = MapUtil.getLong(
artistIds, album.getArtistId(), album.getArtistId());
Album importedAlbum = null;
if (portletDataContext.isDataStrategyMirror()) {
Album existingAlbum =
AlbumLocalServiceUtil.fetchAlbumByUuidAndGroupId(
album.getUuid(), portletDataContext.getScopeGroupId());
if (existingAlbum == null) {
serviceContext.setUuid(album.getUuid());
importedAlbum = AlbumLocalServiceUtil.addAlbum(
userId, artistId, album.getName(), album.getYear(), null,
serviceContext);
}
else {
importedAlbum = AlbumLocalServiceUtil.updateAlbum(
userId, existingAlbum.getAlbumId(), artistId,
album.getName(), album.getYear(), null, serviceContext);
}
}
else {
importedAlbum = AlbumLocalServiceUtil.addAlbum(
userId, artistId, album.getName(), album.getYear(), null,
serviceContext);
}
Element albumElement =
portletDataContext.getImportDataStagedModelElement(album);
List<Element> attachmentElements =
portletDataContext.getReferenceDataElements(
albumElement, FileEntry.class,
PortletDataContext.REFERENCE_TYPE_WEAK);
for (Element attachmentElement : attachmentElements) {
String path = attachmentElement.attributeValue("path");
FileEntry fileEntry =
(FileEntry)portletDataContext.getZipEntryAsObject(path);
importedAlbum = AlbumLocalServiceUtil.updateAlbum(
userId, importedAlbum.getAlbumId(), importedAlbum.getArtistId(),
importedAlbum.getName(), importedAlbum.getYear(),
fileEntry.getContentStream(), serviceContext);
}
portletDataContext.importClassedModel(album, importedAlbum);
}